X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=sendlib.c;h=9ebab5e33309ba6870e4c06ddaed291d3312bce4;hp=a77b6d05d7dc08b243b71cf49317e305daf08d8f;hb=709596677d75e57812cc6bcaa85b844b4b32ca36;hpb=3d937534e7b1ee723f86594b5e4c64c95158a933 diff --git a/sendlib.c b/sendlib.c index a77b6d0..9ebab5e 100644 --- a/sendlib.c +++ b/sendlib.c @@ -18,6 +18,10 @@ #define _SENDLIB_C 1 +#if HAVE_CONFIG_H +# include "config.h" +#endif + #include "mutt.h" #include "mutt_curses.h" #include "rfc2047.h" @@ -505,7 +509,7 @@ int mutt_write_mime_body (BODY *a, FILE *f) } if (a->type == TYPETEXT && (!a->noconv)) - fc = fgetconv_open (fpin, Charset, + fc = fgetconv_open (fpin, a->file_charset, mutt_get_body_charset (send_charset, sizeof (send_charset), a), 0); else @@ -905,6 +909,7 @@ CONTENT *mutt_get_content_info (const char *fname, BODY *b) CONTENT *info; CONTENT_STATE state; FILE *fp = NULL; + char *fromcode; char *tocode; char buffer[100]; char chsbuf[STRING]; @@ -939,15 +944,18 @@ CONTENT *mutt_get_content_info (const char *fname, BODY *b) if (b != NULL && b->type == TYPETEXT && (!b->noconv && !b->force_charset)) { char *chs = mutt_get_parameter ("charset", b->parameter); + char *fchs = b->use_disp ? ((FileCharset && *FileCharset) ? + FileCharset : Charset) : Charset; if (Charset && (chs || SendCharset) && - convert_file_from_to (fp, Charset, chs ? chs : SendCharset, - 0, &tocode, info) != (size_t)(-1)) + convert_file_from_to (fp, fchs, chs ? chs : SendCharset, + &fromcode, &tocode, info) != (size_t)(-1)) { if (!chs) { mutt_canonical_charset (chsbuf, sizeof (chsbuf), tocode); mutt_set_parameter ("charset", chsbuf, &b->parameter); } + b->file_charset = fromcode; FREE (&tocode); safe_fclose (&fp); return info; @@ -1173,6 +1181,9 @@ static void transform_to_7bit (BODY *a, FILE *fpin) } else { + a->noconv = 1; + a->force_charset = 1; + mutt_mktemp (buff); if ((s.fpout = safe_fopen (buff, "w")) == NULL) { @@ -1327,6 +1338,7 @@ BODY *mutt_make_message_attach (CONTEXT *ctx, HEADER *hdr, int attach_msg) body->unlink = 1; body->use_disp = 0; body->disposition = DISPINLINE; + body->noconv = 1; mutt_parse_mime_message (ctx, hdr); @@ -1810,9 +1822,102 @@ const char *mutt_fqdn(short may_hide_host) return p; } +static char mutt_normalized_char(char c) { + if (isalnum(c)) + return c; + if (strchr(".!#$%&'*+-/=?^_`{|}~",c)) + return c; + return '.'; /* normalized character (we're stricter than RFC2822, 3.6.4) */ +} + +static void mutt_gen_localpart(char * buf, unsigned int len, char * fmt) { + time_t now; + struct tm *tm; + char tmp[SHORT_STRING]; + + *buf = '\0'; + + now = time (NULL); + tm = gmtime (&now); + + for (;*fmt;++fmt) { + if (*fmt == '%') { + switch (fmt[1]) { + case 0: + return; + case 'd': + snprintf(tmp,sizeof(tmp),"%02d",tm->tm_mday); + safe_strncat(buf,len,tmp,2); + break; + case 'h': + snprintf(tmp,sizeof(tmp),"%02d",tm->tm_hour); + safe_strncat(buf,len,tmp,2); + break; + case 'm': + snprintf(tmp,sizeof(tmp),"%02d",tm->tm_mon+1); + safe_strncat(buf,len,tmp,2); + break; + case 'M': + snprintf(tmp,sizeof(tmp),"%02d",tm->tm_min); + safe_strncat(buf,len,tmp,2); + break; + case 'O': + snprintf(tmp,sizeof(tmp),"%lo",(unsigned long)now); + safe_strncat(buf,len,tmp,strlen(tmp)); + break; + case 'p': + snprintf(tmp,sizeof(tmp),"%u",(unsigned int)getpid()); + safe_strncat(buf,len,tmp,strlen(tmp)); + break; + case 'P': + snprintf(tmp,sizeof(tmp),"%c",MsgIdPfx); + MsgIdPfx = (MsgIdPfx == 'Z') ? 'A' : MsgIdPfx + 1; + safe_strncat(buf,len,tmp,1); + break; + case 'r': + snprintf(tmp,sizeof(tmp),"%u",(unsigned int)rand()); + safe_strncat(buf,len,tmp,strlen(tmp)); + break; + case 'R': + snprintf(tmp,sizeof(tmp),"%x",(unsigned int)rand()); + safe_strncat(buf,len,tmp,strlen(tmp)); + break; + case 's': + snprintf(tmp,sizeof(tmp),"%02d",tm->tm_sec); + safe_strncat(buf,len,tmp,2); + break; + case 'T': + snprintf(tmp,sizeof(tmp),"%u",(unsigned int)now); + safe_strncat(buf,len,tmp,strlen(tmp)); + break; + case 'X': + snprintf(tmp,sizeof(tmp),"%x",(unsigned int)now); + safe_strncat(buf,len,tmp,strlen(tmp)); + break; + case 'Y': + snprintf(tmp,sizeof(tmp),"%04d",tm->tm_year+1900); /* this will break in the year 10000 ;-) */ + safe_strncat(buf,len,tmp,4); + break; + case '%': + safe_strncat(buf,len,"%",1); + break; + default: + safe_strncat(buf,len,".",1); /* invalid formats are replaced by '.' */ + } /* switch */ + ++fmt; + } else { + char c; + c = mutt_normalized_char(*fmt); /* @todo: filter out invalid characters */ + safe_strncat(buf,len,&c,1); + } + } +} + char *mutt_gen_msgid (void) { char buf[SHORT_STRING]; + char localpart[SHORT_STRING]; + unsigned int localpart_length; time_t now; struct tm *tm; const char *fqdn; @@ -1822,10 +1927,11 @@ char *mutt_gen_msgid (void) if(!(fqdn = mutt_fqdn(0))) fqdn = NONULL(Hostname); - snprintf (buf, sizeof (buf), "<%d%02d%02d%02d%02d%02d.G%c%u@%s>", - tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, - tm->tm_min, tm->tm_sec, MsgIdPfx, (unsigned int)getpid (), fqdn); - MsgIdPfx = (MsgIdPfx == 'Z') ? 'A' : MsgIdPfx + 1; + localpart_length = sizeof(buf) - strlen(fqdn) - 4; /* the 4 characters are '<', '@', '>' and '\0' */ + + mutt_gen_localpart(localpart,localpart_length,MsgIdFormat); + + snprintf(buf,sizeof(buf),"<%s@%s>",localpart,fqdn); return (safe_strdup (buf)); } @@ -2255,6 +2361,7 @@ void mutt_prepare_envelope (ENVELOPE *env, int final) /* Take care of 8-bit => 7-bit conversion. */ rfc2047_encode_adrlist (env->to, "To"); rfc2047_encode_adrlist (env->cc, "Cc"); + rfc2047_encode_adrlist (env->bcc, "Bcc"); rfc2047_encode_adrlist (env->from, "From"); rfc2047_encode_adrlist (env->mail_followup_to, "Mail-Followup-To"); rfc2047_encode_adrlist (env->reply_to, "Reply-To"); @@ -2281,6 +2388,7 @@ void mutt_unprepare_envelope (ENVELOPE *env) /* back conversions */ rfc2047_decode_adrlist (env->to); rfc2047_decode_adrlist (env->cc); + rfc2047_decode_adrlist (env->bcc); rfc2047_decode_adrlist (env->from); rfc2047_decode_adrlist (env->reply_to); rfc2047_decode (&env->subject);