From: Thomas Roessler Date: Tue, 16 May 2000 19:00:15 +0000 (+0000) Subject: Some fixes to the size calculation code. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ecfc412faa4f3f3c2042eedaa6c9a1b492e62f76;p=neomutt Some fixes to the size calculation code. --- diff --git a/compose.c b/compose.c index bb9661788..034424f27 100644 --- a/compose.c +++ b/compose.c @@ -417,9 +417,10 @@ static int change_attachment_charset (BODY *b) /* * cum_attachs_size: Cumulative Attachments Size * - * * Returns the total number of bytes used by the attachments in the - * attachment list. + * attachment list _after_ content-transfer-encodings have been + * applied. + * */ static unsigned long cum_attachs_size (MUTTMENU *menu) @@ -428,21 +429,27 @@ static unsigned long cum_attachs_size (MUTTMENU *menu) unsigned short i; ATTACHPTR **idx = menu->data; CONTENT *info; + BODY *b; for (i = 0, s = 0; i < menu->max; i++) { - if ((info = idx[i]->content->content)) + b = idx[i]->content; + + if (!b->content) + b->content = mutt_get_content_info (b->filename, b); + + if ((info = b->content)) { - switch (idx[i]->content->encoding) + switch (b->encoding) { case ENCQUOTEDPRINTABLE: - s += 3 * (info->lobin + info->hibin) + info->ascii; + s += 3 * (info->lobin + info->hibin) + info->ascii + info->crlf; break; case ENCBASE64: - s += (4 * (info->lobin + info->hibin + info->ascii)) / 3; + s += (4 * (info->lobin + info->hibin + info->ascii + info->crlf)) / 3; break; default: - s += info->lobin + info->hibin + info->ascii; + s += info->lobin + info->hibin + info->ascii + info->crlf; break; } } diff --git a/mutt.h b/mutt.h index f8656118c..37ed6a9af 100644 --- a/mutt.h +++ b/mutt.h @@ -483,6 +483,7 @@ typedef struct content { long hibin; /* 8-bit characters */ long lobin; /* unprintable 7-bit chars (eg., control chars) */ + long crlf; /* '\r' and '\n' characters */ long ascii; /* number of ascii chars */ long linemax; /* length of the longest line in the file */ unsigned int space : 1; /* whitespace at the end of lines? */ diff --git a/protos.h b/protos.h index d67e43abb..5ccdf4d5b 100644 --- a/protos.h +++ b/protos.h @@ -89,6 +89,8 @@ BODY *mutt_parse_multipart (FILE *, const char *, long, int); BODY *mutt_parse_messageRFC822 (FILE *, BODY *); BODY *mutt_read_mime_header (FILE *, int); +CONTENT *mutt_get_content_info (const char *fname, BODY *b); + LIST *mutt_make_references(ENVELOPE *e); ENVELOPE *mutt_read_rfc822_header (FILE *, HEADER *, short, short); diff --git a/sendlib.c b/sendlib.c index 5d24ca933..840565bd3 100644 --- a/sendlib.c +++ b/sendlib.c @@ -512,7 +512,7 @@ void mutt_generate_boundary (PARAMETER **parm) } /* analyze the contents of a file to determine which MIME encoding to use */ -static CONTENT *mutt_get_content_info (const char *fname, BODY *b) +CONTENT *mutt_get_content_info (const char *fname, BODY *b) { CONTENT *info; FILE *fp; @@ -533,6 +533,7 @@ static CONTENT *mutt_get_content_info (const char *fname, BODY *b) linelen++; if (ch == '\n') { + info->crlf++; if (whitespace) info->space = 1; if (dot) info->dot = 1; if (linelen > info->linemax) info->linemax = linelen; @@ -542,6 +543,7 @@ static CONTENT *mutt_get_content_info (const char *fname, BODY *b) } else if (ch == '\r') { + info->crlf++; info->cr = 1; if ((ch = fgetc (fp)) == EOF) { @@ -952,9 +954,7 @@ void mutt_update_encoding (BODY *a) safe_free ((void **) &a->content); a->content = info; - info = NULL; - safe_free ((void **) &info); } BODY *mutt_make_message_attach (CONTEXT *ctx, HEADER *hdr, int attach_msg) @@ -1087,18 +1087,8 @@ BODY *mutt_make_file_attach (const char *path) if (att->type == TYPETEXT) mutt_set_body_charset(att, get_text_charset(att, info)); - -#ifdef HAVE_PGP - /* - * save the info in case this message is signed. we will want to do Q-P - * encoding if any lines begin with "From " so the signature won't be munged, - * for example. - */ - att->content = info; - info = NULL; -#endif - safe_free ((void **) &info); + att->content = info; return (att); }