From 16534e98723674fa391e3fc29d2a07ce419c13dd Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Wed, 28 Mar 2007 00:48:03 +0200 Subject: [PATCH] turn charset into a lua package as well. Signed-off-by: Pierre Habouzit --- .gitignore | 2 ++ charset.c => charset.cpkg | 72 ++++++++++++++++++++++++++++++++++----- charset.h | 4 ++- copy.c | 2 +- globals.h | 2 -- handler.c | 8 ++--- imap/utf7.c | 8 ++--- init.c | 4 +-- init.h | 47 ------------------------- lib-crypt/crypt-gpgme.c | 6 ++-- lib-crypt/gnupgparse.c | 2 +- lib-crypt/pgp.c | 6 ++-- lib-lua/lua-token.sh | 4 +++ lib-lua/runtime.c | 2 ++ lib-mime/mime.c | 61 --------------------------------- lib-mime/mime.h | 2 -- lib-mime/rfc2047.c | 10 +++--- lib-mime/rfc2231.c | 12 +++---- lib-mime/rfc822parse.c | 2 +- lib-mx/hcache.c | 2 +- mutt_idna.c | 6 ++-- protos.h | 1 + send.c | 59 ++++++++++++++++++++++++++++++++ sendlib.c | 11 +++--- tools/Makefile | 5 +-- 25 files changed, 177 insertions(+), 163 deletions(-) rename charset.c => charset.cpkg (82%) diff --git a/.gitignore b/.gitignore index e0984dc..ebe6b83 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ alias.c +charset.c +charset.li diff --git a/charset.c b/charset.cpkg similarity index 82% rename from charset.c rename to charset.cpkg index 11441e4..3db2745 100644 --- a/charset.c +++ b/charset.cpkg @@ -31,14 +31,66 @@ # include #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 = '?'; @@ -58,18 +110,18 @@ void charset_initialize(void) /* 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 } @@ -316,7 +368,7 @@ static ssize_t convert_string(const char *f, ssize_t flen, 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; @@ -335,7 +387,7 @@ int mutt_convert_nonmime_string(char **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; @@ -350,7 +402,7 @@ int mutt_convert_nonmime_string(char **ps) /****************************************************************************/ /* 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; @@ -468,3 +520,5 @@ char *fgetconvs(char *buf, ssize_t len, fgetconv_t *fc) return pos ? buf : NULL; } + +/* vim:set ft=c: */ diff --git a/charset.h b/charset.h index 2f03c24..67eb482 100644 --- a/charset.h +++ b/charset.h @@ -32,11 +32,13 @@ # include "config.h" #endif +#include +#include "charset.li" + /****************************************************************************/ /* charset functions */ /****************************************************************************/ -extern char *Charset; extern int Charset_is_utf8; extern wchar_t CharsetReplacement; diff --git a/copy.c b/copy.c index 45eba0a..8e8f96f 100644 --- a/copy.c +++ b/copy.c @@ -361,7 +361,7 @@ mutt_copy_header (FILE * in, HEADER * h, FILE * out, int flags, 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); diff --git a/globals.h b/globals.h index 81e2952..ade60c8 100644 --- a/globals.h +++ b/globals.h @@ -23,7 +23,6 @@ WHERE char Quotebuf[STRING]; WHERE address_t *From; -WHERE char *AssumedCharset; WHERE char *AttachSep; WHERE char *Attribution; WHERE char *AttachFormat; @@ -110,7 +109,6 @@ WHERE char *Prefix; WHERE char *PrintCmd; WHERE char *QueryCmd; WHERE char *Realname; -WHERE char *SendCharset; WHERE char *SidebarDelim; WHERE char *SidebarNumberFormat; WHERE char *SidebarBoundary; diff --git a/handler.c b/handler.c index 0153bc3..abe7f65 100644 --- a/handler.c +++ b/handler.c @@ -1252,12 +1252,12 @@ void mutt_decode_attachment (BODY * b, STATE * s) 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); } } diff --git a/imap/utf7.c b/imap/utf7.c index b21149b..ae194e6 100644 --- a/imap/utf7.c +++ b/imap/utf7.c @@ -208,10 +208,10 @@ bail: 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; @@ -222,10 +222,10 @@ void imap_utf7_encode (char **s) 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; } diff --git a/init.c b/init.c index 522557f..3d17e76 100644 --- a/init.c +++ b/init.c @@ -1682,12 +1682,12 @@ static int source_rc (const char *rcfile, BUFFER * err) 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; diff --git a/init.h b/init.h index 15ca874..624e72e 100644 --- a/init.h +++ b/init.h @@ -182,23 +182,6 @@ struct option_t MuttVars[] = { ** 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" }, /* @@ -331,11 +314,6 @@ struct option_t MuttVars[] = { ** 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 @@ -582,20 +560,6 @@ struct option_t MuttVars[] = { ** 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 @@ -2827,17 +2791,6 @@ struct option_t MuttVars[] = { ** 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" }, /* diff --git a/lib-crypt/crypt-gpgme.c b/lib-crypt/crypt-gpgme.c index c0d4b7f..949d1eb 100644 --- a/lib-crypt/crypt-gpgme.c +++ b/lib-crypt/crypt-gpgme.c @@ -116,7 +116,7 @@ static void print_utf8 (FILE * fp, const char *buf, ssize_t len) 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); } @@ -1707,7 +1707,7 @@ static void copy_clearsigned (gpgme_data_t data, STATE * s, char *charset) 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; @@ -1925,7 +1925,7 @@ int pgp_gpgme_application_handler (BODY * m, STATE * s) 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) diff --git a/lib-crypt/gnupgparse.c b/lib-crypt/gnupgparse.c index a2d8549..6be9f16 100644 --- a/lib-crypt/gnupgparse.c +++ b/lib-crypt/gnupgparse.c @@ -273,7 +273,7 @@ pgp_key_t pgp_get_candidates (pgp_ring_t keyring, string_list_t * hints) 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); diff --git a/lib-crypt/pgp.c b/lib-crypt/pgp.c index 6b78ce4..abab102 100644 --- a/lib-crypt/pgp.c +++ b/lib-crypt/pgp.c @@ -167,7 +167,7 @@ static void pgp_copy_clearsigned (FILE * fpin, STATE * s, char *charset) 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; @@ -394,7 +394,7 @@ int pgp_application_pgp_handler (BODY * m, STATE * s) 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); @@ -1268,7 +1268,7 @@ BODY *pgp_traditional_encryptsign (BODY * a, int flags, char *keylist) if (a->noconv) from_charset = body_charset; else - from_charset = Charset; + from_charset = MCharset.charset; if (!charset_is_us_ascii (body_charset)) { int c; diff --git a/lib-lua/lua-token.sh b/lib-lua/lua-token.sh index 6adcef3..bec6a1a 100644 --- a/lib-lua/lua-token.sh +++ b/lib-lua/lua-token.sh @@ -114,20 +114,24 @@ exit 0 ## 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 diff --git a/lib-lua/runtime.c b/lib-lua/runtime.c index b96db43..1b976c9 100644 --- a/lib-lua/runtime.c +++ b/lib-lua/runtime.c @@ -22,6 +22,7 @@ #include "../alias.h" #include "../mutt.h" +#include "../charset.h" static lua_State *L; @@ -39,6 +40,7 @@ void luaM_initialize(void) {"MCore", luaopen_MCore}, {"MTransport", luaopen_MTransport}, {"MAlias", luaopen_MAlias}, + {"MCharset", luaopen_MCharset}, }; int i; diff --git a/lib-mime/mime.c b/lib-mime/mime.c index 43ccfd3..8f10d56 100644 --- a/lib-mime/mime.c +++ b/lib-mime/mime.c @@ -243,64 +243,3 @@ int mutt_is_text_part(BODY * b) } } -#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; -} diff --git a/lib-mime/mime.h b/lib-mime/mime.h index e5ab93d..0ff5bce 100644 --- a/lib-mime/mime.h +++ b/lib-mime/mime.h @@ -47,8 +47,6 @@ extern const char *BodyEncodings[]; #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 */ diff --git a/lib-mime/rfc2047.c b/lib-mime/rfc2047.c index 7e45ce6..4aa6ee4 100644 --- a/lib-mime/rfc2047.c +++ b/lib-mime/rfc2047.c @@ -561,13 +561,13 @@ static void _rfc2047_encode_string(char **pd, int encode_specials, int col) 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); @@ -667,7 +667,7 @@ rfc2047_decode_word(char *d, size_t len, const char *p, const char *end) *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; @@ -786,7 +786,7 @@ void rfc2047_decode(char **pd) 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); diff --git a/lib-mime/rfc2231.c b/lib-mime/rfc2231.c index 287c1d6..da50510 100644 --- a/lib-mime/rfc2231.c +++ b/lib-mime/rfc2231.c @@ -186,7 +186,7 @@ rfc2231_join_continuations(parameter_t **head, rfc2231_param *par) 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; @@ -236,7 +236,7 @@ void rfc2231_decode_parameters (parameter_t ** headp) 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); } @@ -249,7 +249,7 @@ void rfc2231_decode_parameters (parameter_t ** headp) 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; @@ -313,13 +313,13 @@ int rfc2231_encode_string(char **s) 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); } diff --git a/lib-mime/rfc822parse.c b/lib-mime/rfc822parse.c index 0b67479..3e77c57 100644 --- a/lib-mime/rfc822parse.c +++ b/lib-mime/rfc822parse.c @@ -331,7 +331,7 @@ void mutt_parse_content_type(char *s, BODY *ct) pc = parameter_getval(ct->parameter, "charset"); if (!pc) { parameter_setval(&ct->parameter, "charset", - charset_getfirst(AssumedCharset)); + charset_getfirst(MCharset.assumed_charset)); } } } diff --git a/lib-mx/hcache.c b/lib-mx/hcache.c index a6aa68d..bdbeeb9 100644 --- a/lib-mx/hcache.c +++ b/lib-mx/hcache.c @@ -361,7 +361,7 @@ static int generate_crc32 () (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 diff --git a/mutt_idna.c b/mutt_idna.c index 1a9bd8b..686e849 100644 --- a/mutt_idna.c +++ b/mutt_idna.c @@ -48,7 +48,7 @@ int mutt_idna_to_local (const char *in, char **out, int flags) /* 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; /* @@ -61,7 +61,7 @@ int mutt_idna_to_local (const char *in, char **out, int flags) 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; @@ -96,7 +96,7 @@ int mutt_local_to_idna (const char *in, char **out) 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; diff --git a/protos.h b/protos.h index 068cc4a..ce7e380 100644 --- a/protos.h +++ b/protos.h @@ -20,6 +20,7 @@ int query_quadoption2(int, const char *); 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); diff --git a/send.c b/send.c index 2c06429..269d98d 100644 --- a/send.c +++ b/send.c @@ -29,6 +29,65 @@ #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; diff --git a/sendlib.c b/sendlib.c index 838b850..669140d 100644 --- a/sendlib.c +++ b/sendlib.c @@ -767,10 +767,10 @@ CONTENT *mutt_get_content_info (const char *fname, BODY * b) 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); @@ -793,7 +793,8 @@ CONTENT *mutt_get_content_info (const char *fname, BODY * b) 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; } diff --git a/tools/Makefile b/tools/Makefile index ec3e895..39394f5 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -1,7 +1,8 @@ # 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) -- 2.20.1