alias.c
+charset.c
+charset.li
# include <langinfo.h>
#endif
-#include "mutt.h"
#include "charset.h"
#ifndef EILSEQ
# define EILSEQ EINVAL
#endif
+@import "lib-lua/base.cpkg"
+
+@package MCharset {
+ /*
+ ** .pp
+ ** This variable is a colon-separated list of character encoding
+ ** schemes for messages without character encoding indication.
+ ** Header field values and message body content without character encoding
+ ** indication would be assumed that they are written in one of this list.
+ ** By default, all the header fields and message body without any charset
+ ** indication are assumed to be in \fTus-ascii\fP.
+ ** .pp
+ ** For example, Japanese users might prefer this:
+ ** .pp
+ ** \fTset assumed_charset="iso-2022-jp:euc-jp:shift_jis:utf-8"\fP
+ ** .pp
+ ** However, only the first content is valid for the message body.
+ ** This variable is valid only if $$strict_mime is unset.
+ */
+ string_t assumed_charset = m_strdup("us-ascii");
+
+ /*
+ ** .pp
+ ** Character set your terminal uses to display and enter textual data.
+ */
+ string_t charset = NULL;
+
+ /*
+ ** .pp
+ ** This variable is a colon-separated list of character encoding
+ ** schemes for text file attatchments.
+ ** If \fIunset\fP, $$charset value will be used instead.
+ ** For example, the following configuration would work for Japanese
+ ** text handling:
+ ** .pp
+ ** \fTset file_charset="iso-2022-jp:euc-jp:shift_jis:utf-8"\fP
+ ** .pp
+ ** Note: ``\fTiso-2022-*\fP'' must be put at the head of the value as shown above
+ ** if included.
+ */
+ string_t file_charset = NULL;
+
+ /*
+ ** .pp
+ ** A list of character sets for outgoing messages. Madmutt will use the
+ ** first character set into which the text can be converted exactly.
+ ** If your ``$$charset'' is not \fTiso-8859-1\fP and recipients may not
+ ** understand \fTUTF-8\fP, it is advisable to include in the list an
+ ** appropriate widely used standard character set (such as
+ ** \fTiso-8859-2\fP, \fTkoi8-r\fP or \fTiso-2022-jp\fP) either
+ ** instead of or after \fTiso-8859-1\fP.
+ */
+ string_t send_charset = m_strdup("us-ascii:iso-8859-1:utf-8");
+};
-char *Charset;
int Charset_is_utf8 = 0;
wchar_t CharsetReplacement = '?';
/* finally, set $charset */
if (!m_strisempty(buff2)) {
- m_strreplace(&Charset, buff2);
+ m_strreplace(&MCharset.charset, buff2);
} else
#endif
{
- m_strreplace(&Charset, "iso-8859-1");
+ m_strreplace(&MCharset.charset, "iso-8859-1");
}
- Charset_is_utf8 = !m_strcmp(Charset, "utf-8");
+ Charset_is_utf8 = !m_strcmp(MCharset.charset, "utf-8");
CharsetReplacement = Charset_is_utf8 ? 0xfffd : '?';
#ifdef HAVE_BIND_TEXTDOMAIN_CODESET
- bind_textdomain_codeset(PACKAGE, Charset);
+ bind_textdomain_codeset(PACKAGE, MCharset.charset);
#endif
}
int mutt_convert_nonmime_string(char **ps)
{
- const char *p = AssumedCharset;
+ const char *p = MCharset.assumed_charset;
ssize_t ulen = m_strlen(*ps);
char *u = *ps;
m_strncpy(fromcode, sizeof(fromcode), p, q - p);
p = q;
- if (convert_string(u, ulen, fromcode, Charset, &s, &slen) >= 0) {
+ if (convert_string(u, ulen, fromcode, MCharset.charset, &s, &slen) >= 0) {
p_delete(ps);
*ps = s;
return 0;
/****************************************************************************/
/* fgetconv_t stuff for converting a file while reading it
- Used in sendlib.c for converting from mutt's Charset */
+ Used in sendlib.c for converting from mutt's charset */
struct fgetconv_t {
FILE *file;
return pos ? buf : NULL;
}
+
+/* vim:set ft=c: */
# include "config.h"
#endif
+#include <lib-lua/lib-lua.h>
+#include "charset.li"
+
/****************************************************************************/
/* charset functions */
/****************************************************************************/
-extern char *Charset;
extern int Charset_is_utf8;
extern wchar_t CharsetReplacement;
fputs ("MIME-Version: 1.0\n", out);
fputs ("Content-Transfer-Encoding: 8bit\n", out);
fputs ("Content-Type: text/plain; charset=", out);
- charset_canonicalize(chsbuf, sizeof (chsbuf), Charset);
+ charset_canonicalize(chsbuf, sizeof (chsbuf), MCharset.charset);
rfc822_strcpy(buffer, sizeof(buffer), chsbuf, MimeSpecials);
fputs (buffer, out);
fputc ('\n', out);
WHERE address_t *From;
-WHERE char *AssumedCharset;
WHERE char *AttachSep;
WHERE char *Attribution;
WHERE char *AttachFormat;
WHERE char *PrintCmd;
WHERE char *QueryCmd;
WHERE char *Realname;
-WHERE char *SendCharset;
WHERE char *SidebarDelim;
WHERE char *SidebarNumberFormat;
WHERE char *SidebarBoundary;
const char *charset = parameter_getval(b->parameter, "charset");
if (!charset)
- charset = charset_getfirst(AssumedCharset);
- if (charset && Charset)
- cd = mutt_iconv_open (Charset, charset, M_ICONV_HOOK_FROM);
+ charset = charset_getfirst(MCharset.assumed_charset);
+ if (charset && MCharset.charset)
+ cd = mutt_iconv_open (MCharset.charset, charset, M_ICONV_HOOK_FROM);
} else {
if (b->file_charset)
- cd = mutt_iconv_open (Charset, b->file_charset, M_ICONV_HOOK_FROM);
+ cd = mutt_iconv_open (MCharset.charset, b->file_charset, M_ICONV_HOOK_FROM);
}
}
void imap_utf7_encode (char **s)
{
- if (Charset) {
+ if (MCharset.charset) {
char *t = m_strdup(*s);
- if (!mutt_convert_string (&t, Charset, "utf-8", 0)) {
+ if (!mutt_convert_string (&t, MCharset.charset, "utf-8", 0)) {
char *u7 = utf8_to_utf7 (t, strlen (t), NULL, 0);
p_delete(s);
*s = u7;
void imap_utf7_decode (char **s)
{
- if (Charset) {
+ if (MCharset.charset) {
char *t = utf7_to_utf8 (*s, m_strlen(*s), 0, 0);
- if (t && !mutt_convert_string (&t, "utf-8", Charset, 0)) {
+ if (t && !mutt_convert_string (&t, "utf-8", MCharset.charset, 0)) {
p_delete(s);
*s = t;
}
p_clear(&token, 1);
while ((linebuf = mutt_read_line(linebuf, &buflen, f, &line)) != NULL) {
- conv = ConfigCharset && (*ConfigCharset) && Charset;
+ conv = ConfigCharset && (*ConfigCharset) && MCharset.charset;
if (conv) {
currentline = m_strdup(linebuf);
if (!currentline)
continue;
- mutt_convert_string (¤tline, ConfigCharset, Charset, 0);
+ mutt_convert_string (¤tline, ConfigCharset, MCharset.charset, 0);
}
else
currentline = linebuf;
** If \fIset\fP, Madmutt will prompt you for carbon-copy (Cc) recipients before
** editing the body of an outgoing message.
*/
- {"assumed_charset", DT_STR, R_NONE, UL &AssumedCharset, "us-ascii"},
- /*
- ** .pp
- ** This variable is a colon-separated list of character encoding
- ** schemes for messages without character encoding indication.
- ** Header field values and message body content without character encoding
- ** indication would be assumed that they are written in one of this list.
- ** By default, all the header fields and message body without any charset
- ** indication are assumed to be in \fTus-ascii\fP.
- ** .pp
- ** For example, Japanese users might prefer this:
- ** .pp
- ** \fTset assumed_charset="iso-2022-jp:euc-jp:shift_jis:utf-8"\fP
- ** .pp
- ** However, only the first content is valid for the message body.
- ** This variable is valid only if $$strict_mime is unset.
- */
#ifdef USE_NNTP
{"nntp_ask_followup_to", DT_BOOL, R_NONE, OPTASKFOLLOWUP, "no" },
/*
** as read when you leaving it.
*/
#endif
- {"charset", DT_STR, R_NONE, UL &Charset, "" },
- /*
- ** .pp
- ** Character set your terminal uses to display and enter textual data.
- */
{"check_new", DT_BOOL, R_NONE, OPTCHECKNEW, "yes" },
/*
** .pp
** signed.
** (PGP only)
*/
- {"file_charset", DT_STR, R_NONE, UL &FileCharset, "" },
- /*
- ** .pp
- ** This variable is a colon-separated list of character encoding
- ** schemes for text file attatchments.
- ** If \fIunset\fP, $$charset value will be used instead.
- ** For example, the following configuration would work for Japanese
- ** text handling:
- ** .pp
- ** \fTset file_charset="iso-2022-jp:euc-jp:shift_jis:utf-8"\fP
- ** .pp
- ** Note: ``\fTiso-2022-*\fP'' must be put at the head of the value as shown above
- ** if included.
- */
{"folder", DT_PATH, R_NONE, UL &Maildir, "~/Mail"},
/*
** .pp
** Madmutt scores are always greater than or equal to zero, the default setting
** of this variable will never mark a message read.
*/
- {"send_charset", DT_STR, R_NONE, UL &SendCharset, "us-ascii:iso-8859-1:utf-8"},
- /*
- ** .pp
- ** A list of character sets for outgoing messages. Madmutt will use the
- ** first character set into which the text can be converted exactly.
- ** If your ``$$charset'' is not \fTiso-8859-1\fP and recipients may not
- ** understand \fTUTF-8\fP, it is advisable to include in the list an
- ** appropriate widely used standard character set (such as
- ** \fTiso-8859-2\fP, \fTkoi8-r\fP or \fTiso-2022-jp\fP) either
- ** instead of or after \fTiso-8859-1\fP.
- */
#ifdef USE_NNTP
{"nntp_save_unsubscribed", DT_BOOL, R_NONE, OPTSAVEUNSUB, "no" },
/*
char *tstr;
tstr = p_dupstr(buf, len);
- mutt_convert_string (&tstr, "utf-8", Charset, M_ICONV_HOOK_FROM);
+ mutt_convert_string (&tstr, "utf-8", MCharset.charset, M_ICONV_HOOK_FROM);
fputs (tstr, fp);
p_delete(&tstr);
}
unlink (fname);
p_delete(&fname);
- fc = fgetconv_open (fp, charset, Charset, M_ICONV_HOOK_FROM);
+ fc = fgetconv_open (fp, charset, MCharset.charset, M_ICONV_HOOK_FROM);
for (complete = 1, armor_header = 1;
fgetconvs (buf, sizeof (buf), fc) != NULL;
int c;
rewind (pgpout);
- fc = fgetconv_open (pgpout, "utf-8", Charset, 0);
+ fc = fgetconv_open (pgpout, "utf-8", MCharset.charset, 0);
while ((c = fgetconv (fc)) != EOF) {
state_putc (c, s);
if (c == '\n' && s->prefix)
if ((devnull = open ("/dev/null", O_RDWR)) == -1)
return NULL;
- m_strreplace(&_chs, Charset);
+ m_strreplace(&_chs, MCharset.charset);
thepid = pgp_invoke_list_keys (NULL, &fp, NULL, -1, -1, devnull,
keyring, hints);
rewind (fpin);
- fc = fgetconv_open (fpin, charset, Charset, M_ICONV_HOOK_FROM);
+ fc = fgetconv_open (fpin, charset, MCharset.charset, M_ICONV_HOOK_FROM);
for (complete = 1, armor_header = 1;
fgetconvs (buf, sizeof (buf), fc) != NULL;
rewind (pgpout);
state_set_prefix (s);
- fc = fgetconv_open (pgpout, "utf-8", Charset, 0);
+ fc = fgetconv_open (pgpout, "utf-8", MCharset.charset, 0);
while ((c = fgetconv (fc)) != EOF)
state_prefix_putc (c, s);
fgetconv_close (&fc);
if (a->noconv)
from_charset = body_charset;
else
- from_charset = Charset;
+ from_charset = MCharset.charset;
if (!charset_is_us_ascii (body_charset)) {
int c;
## alias_format
## ask-no
## ask-yes
+## assumed_charset
## beep
## beep_new
## bindir
+## charset
## docdir
## dotlock
## dsn_notify
## dsn_return
## editor
## envelope_from_address
+## file_charset
## gecos_mask
## hcache_backend
## homedir
## no
## quit
+## send_charset
## sendmail
## sendmail_wait
## shell
#include "../alias.h"
#include "../mutt.h"
+#include "../charset.h"
static lua_State *L;
{"MCore", luaopen_MCore},
{"MTransport", luaopen_MTransport},
{"MAlias", luaopen_MAlias},
+ {"MCharset", luaopen_MCharset},
};
int i;
}
}
-#include "mutt.h"
-
-int url_parse_mailto(ENVELOPE *e, char **body, const char *src)
-{
- char *t;
- char *tmp;
- char *headers;
- char *tag, *value;
- char scratch[HUGE_STRING];
-
- int taglen;
-
- string_list_t **last = &e->userhdrs;
-
- if (!(t = strchr (src, ':')))
- return -1;
-
- if ((tmp = m_strdup(t + 1)) == NULL)
- return -1;
-
- if ((headers = strchr (tmp, '?')))
- *headers++ = '\0';
-
- url_decode(tmp);
- e->to = rfc822_parse_adrlist(e->to, tmp);
-
- tag = headers ? strtok (headers, "&") : NULL;
-
- for (; tag; tag = strtok(NULL, "&")) {
- if ((value = strchr (tag, '=')))
- *value++ = '\0';
- if (!value || !*value)
- continue;
-
- url_decode (tag);
- url_decode (value);
-
- if (mime_which_token(tag, -1) == MIME_BODY) {
- if (body)
- m_strreplace(body, value);
- } else {
-#define SAFEPFX (option(OPTSTRICTMAILTO) ? "" : "X-Mailto-")
- taglen = m_strlen(tag) + strlen(SAFEPFX);
- /* mutt_parse_rfc822_line makes some assumptions */
- snprintf(scratch, sizeof(scratch), "%s%s: %s", SAFEPFX, tag, value);
-#undef SAVEPFX
- scratch[taglen] = '\0';
- value = vskipspaces(&scratch[taglen + 1]);
- last = mutt_parse_rfc822_line (e, NULL, scratch, value, 0, 0, last);
- /* if $strict_mailto is set, force editing headers to let
- * users have a look at what we got */
- if (!option (OPTSTRICTMAILTO)) {
- set_option (OPTXMAILTO);
- set_option (OPTEDITHDRS);
- }
- }
- }
-
- p_delete(&tmp);
- return 0;
-}
#define TYPE(X) ((X->type == TYPEOTHER) && (X->xtype != NULL) ? X->xtype : BodyTypes[(X->type)])
#define ENCODING(X) BodyEncodings[(X)]
-int url_parse_mailto(ENVELOPE *e, char **body, const char *src);
-
/****************************************************************************/
/* RFC 1524 */
/* A User Agent Configuration Mechanism */
ssize_t elen;
const char *charsets;
- if (!Charset || !*pd)
+ if (!MCharset.charset || !*pd)
return;
- charsets = m_strisempty(SendCharset) ? "UTF-8" : SendCharset;
+ charsets = m_strisempty(MCharset.send_charset) ? "utf-8" : MCharset.send_charset;
rfc2047_encode(*pd, m_strlen(*pd), col,
- Charset, charsets, &e, &elen,
+ MCharset.charset, charsets, &e, &elen,
encode_specials ? RFC822Specials : NULL);
p_delete(pd);
*q = '\0';
if (*charset)
- mutt_convert_string(&d0, charset, Charset, M_ICONV_HOOK_FROM);
+ mutt_convert_string(&d0, charset, MCharset.charset, M_ICONV_HOOK_FROM);
m_strcpy(d, len, d0);
p_delete(&d0);
return 0;
n -= m, s += m;
}
- if (mime_which_token(AssumedCharset, -1) == MIME_US_ASCII) {
+ if (mime_which_token(MCharset.assumed_charset, -1) == MIME_US_ASCII) {
char *t;
t = p_dupstr(s, n);
if (value) {
if (encoded)
- mutt_convert_string (&value, charset, Charset, M_ICONV_HOOK_FROM);
+ mutt_convert_string (&value, charset, MCharset.charset, M_ICONV_HOOK_FROM);
*head = parameter_new();
(*head)->attribute = m_strdup(attribute);
(*head)->value = value;
if (p->value && strstr(p->value, "=?")) {
rfc2047_decode(&p->value);
} else {
- if (mime_which_token(AssumedCharset, -1) == MIME_US_ASCII)
+ if (mime_which_token(MCharset.assumed_charset, -1) == MIME_US_ASCII)
mutt_convert_nonmime_string(&p->value);
}
s = rfc2231_get_charset (p->value, charset, sizeof (charset));
rfc2231_decode_one (p->value, s);
- mutt_convert_string (&p->value, charset, Charset, M_ICONV_HOOK_FROM);
+ mutt_convert_string (&p->value, charset, MCharset.charset, M_ICONV_HOOK_FROM);
*last = p;
last = &p->next;
return 0;
}
- if (Charset && SendCharset) {
- charset = mutt_choose_charset(Charset, SendCharset,
+ if (MCharset.charset && MCharset.send_charset) {
+ charset = mutt_choose_charset(MCharset.charset, MCharset.send_charset,
*s, m_strlen(*s), &d, &dlen);
}
if (!charset) {
- charset = m_strdup(Charset ? Charset : "unknown-8bit");
+ charset = m_strdup(MCharset.charset ?: "unknown-8bit");
d = *s;
dlen = m_strlen(d);
}
pc = parameter_getval(ct->parameter, "charset");
if (!pc) {
parameter_setval(&ct->parameter, "charset",
- charset_getfirst(AssumedCharset));
+ charset_getfirst(MCharset.assumed_charset));
}
}
}
(MUTTNG_HCACHE_ID "sithglan@stud.uni-erlangen.de[sithglan]|hcache.c|20041108231548|29613"));
#ifdef HAVE_LANGINFO_CODESET
- crc = crc32(crc, (unsigned char const *) Charset, m_strlen(Charset));
+ crc = crc32(crc, (unsigned char const *) MCharset.charset, m_strlen(MCharset.charset));
crc = crc32(crc, (unsigned char const *) "HAVE_LANGINFO_CODESET",
m_strlen("HAVE_LANGINFO_CODESET"));
#endif
/* Is this the right function? Interesting effects with some bad identifiers! */
if (idna_to_unicode_8z8z (in, out, 1) != IDNA_SUCCESS)
goto notrans;
- if (mutt_convert_string (out, "utf-8", Charset, M_ICONV_HOOK_TO) == -1)
+ if (mutt_convert_string (out, "utf-8", MCharset.charset, M_ICONV_HOOK_TO) == -1)
goto notrans;
/*
char *t2 = NULL;
char *tmp = m_strdup(*out);
- if (mutt_convert_string (&tmp, Charset, "utf-8", M_ICONV_HOOK_FROM) == -1)
+ if (mutt_convert_string (&tmp, MCharset.charset, "utf-8", M_ICONV_HOOK_FROM) == -1)
irrev = 1;
if (!irrev && idna_to_ascii_8z (tmp, &t2, 1) != IDNA_SUCCESS)
irrev = 1;
return -1;
}
- if (mutt_convert_string (&tmp, Charset, "utf-8", M_ICONV_HOOK_FROM) == -1)
+ if (mutt_convert_string (&tmp, MCharset.charset, "utf-8", M_ICONV_HOOK_FROM) == -1)
rv = -1;
if (!rv && idna_to_ascii_8z (tmp, out, 1) != IDNA_SUCCESS)
rv = -2;
int quadoption (int);
int mutt_option_value (const char* val, char* dst, ssize_t dstlen);
+int url_parse_mailto(ENVELOPE *e, char **body, const char *src);
address_t *mutt_default_from (void);
#include "remailer.h"
+int url_parse_mailto(ENVELOPE *e, char **body, const char *src)
+{
+ char *t;
+ char *tmp;
+ char *headers;
+ char *tag, *value;
+ char scratch[HUGE_STRING];
+
+ int taglen;
+
+ string_list_t **last = &e->userhdrs;
+
+ if (!(t = strchr (src, ':')))
+ return -1;
+
+ if ((tmp = m_strdup(t + 1)) == NULL)
+ return -1;
+
+ if ((headers = strchr (tmp, '?')))
+ *headers++ = '\0';
+
+ url_decode(tmp);
+ e->to = rfc822_parse_adrlist(e->to, tmp);
+
+ tag = headers ? strtok (headers, "&") : NULL;
+
+ for (; tag; tag = strtok(NULL, "&")) {
+ if ((value = strchr (tag, '=')))
+ *value++ = '\0';
+ if (!value || !*value)
+ continue;
+
+ url_decode (tag);
+ url_decode (value);
+
+ if (mime_which_token(tag, -1) == MIME_BODY) {
+ if (body)
+ m_strreplace(body, value);
+ } else {
+#define SAFEPFX (option(OPTSTRICTMAILTO) ? "" : "X-Mailto-")
+ taglen = m_strlen(tag) + strlen(SAFEPFX);
+ /* mutt_parse_rfc822_line makes some assumptions */
+ snprintf(scratch, sizeof(scratch), "%s%s: %s", SAFEPFX, tag, value);
+#undef SAVEPFX
+ scratch[taglen] = '\0';
+ value = vskipspaces(&scratch[taglen + 1]);
+ last = mutt_parse_rfc822_line (e, NULL, scratch, value, 0, 0, last);
+ /* if $strict_mailto is set, force editing headers to let
+ * users have a look at what we got */
+ if (!option (OPTSTRICTMAILTO)) {
+ set_option (OPTXMAILTO);
+ set_option (OPTEDITHDRS);
+ }
+ }
+ }
+
+ p_delete(&tmp);
+ return 0;
+}
static void append_signature (FILE * f)
{
FILE *tmpfp;
if (b != NULL && b->type == TYPETEXT && (!b->noconv && !b->force_charset)) {
const char *chs = parameter_getval(b->parameter, "charset");
- char *fchs = b->use_disp ? ((FileCharset && *FileCharset) ?
- FileCharset : Charset) : Charset;
- if (Charset && (chs || SendCharset) &&
- convert_file_from_to (fp, fchs, chs ? chs : SendCharset,
+ char *fchs = b->use_disp && !m_strisempty(MCharset.file_charset)
+ ? FileCharset : MCharset.charset;
+ if (MCharset.charset && (chs || MCharset.send_charset) &&
+ convert_file_from_to (fp, fchs, chs ? chs : MCharset.send_charset,
&fromcode, &tocode, info) != -1) {
if (!chs) {
charset_canonicalize (chsbuf, sizeof (chsbuf), tocode);
if (b != NULL && b->type == TYPETEXT && (!b->noconv && !b->force_charset))
parameter_setval(&b->parameter, "charset",
(!info->hibin ? "us-ascii"
- : Charset && !charset_is_us_ascii(Charset) ? Charset : "unknown-8bit"));
+ : MCharset.charset && !charset_is_us_ascii(MCharset.charset)
+ ? MCharset.charset : "unknown-8bit"));
return info;
}
# automake sucks, badly
all: ../lib-mime/mime-token.h \
- ../lib-lua/lua-token.h \
- ../lib-lua/madmutt.li
+ ../lib-lua/lua-token.h \
+ ../lib-lua/madmutt.li \
+ ../charset.li
../%: ; $(MAKE) -C $(@D) $(@F)