aboutsummaryrefslogtreecommitdiffstats
path: root/camel/camel-mime-filter-bestenc.c
diff options
context:
space:
mode:
authorNot Zed <NotZed@HelixCode.com>2000-11-08 17:13:52 +0800
committerMichael Zucci <zucchi@src.gnome.org>2000-11-08 17:13:52 +0800
commit2b97bd935b8d4becffb4df667a2ee6162c706465 (patch)
treedd75b0c2f60651e8910fda93a5910d6699f94ef7 /camel/camel-mime-filter-bestenc.c
parent18c2d259b26f9a6d3d86e1b0a183750d4f482d72 (diff)
downloadgsoc2013-evolution-2b97bd935b8d4becffb4df667a2ee6162c706465.tar
gsoc2013-evolution-2b97bd935b8d4becffb4df667a2ee6162c706465.tar.gz
gsoc2013-evolution-2b97bd935b8d4becffb4df667a2ee6162c706465.tar.bz2
gsoc2013-evolution-2b97bd935b8d4becffb4df667a2ee6162c706465.tar.lz
gsoc2013-evolution-2b97bd935b8d4becffb4df667a2ee6162c706465.tar.xz
gsoc2013-evolution-2b97bd935b8d4becffb4df667a2ee6162c706465.tar.zst
gsoc2013-evolution-2b97bd935b8d4becffb4df667a2ee6162c706465.zip
Keep track of the caller bestenc flags that make sense.
2000-11-08 Not Zed <NotZed@HelixCode.com> * camel-mime-message.c (find_best_encoding): Keep track of the caller bestenc flags that make sense. * camel-mime-filter-bestenc.c (filter): Added code to detect when we have "^From " lines in the sequence of text. (camel_mime_filter_bestenc_get_best_encoding): Added a new flag CAMEL_BESTENC_NO_FROM: if set, it will not allow any lines matching "^From " to appear in the output - currently forcing base64 encoding to achieve this. * camel-mime-parser.c (folder_scan_step): Call camel_mime-filter_complete() once we're done, rather than filter_filter(). (folder_scan_content): Some fixes for state changing; so that when we do find another boundary it is properly flagged. Since we strip the last \n off all data, we must take that into account too. Sigh. Fixes a rather nasty set of bugs where multipart messages could start including following messages as parts, etc. (struct _header_scan_stack): Added new parameter, boundarylenfinal, which holds the length of the final boundary, if it is different (e.g. for From lines, whihc aren't) (folder_scan_step): Setup teh boundarylenfinal value when creating a new boundary. (folder_scan_content): Hmm, if we hit the end-of-buffer sentinal, reset the scanner back to leave 'atleast' chars in the buffer still, dump that content, and retry again. Stops us losing a check for a boundary on some data we haven't really looked at yet! (folder_scan_content): Use boundarylenfinal to calculate 'atleast'. (folder_scan_header): And here too. (folder_boundary_check): Use the atleast value directly, dont truncate it. Use the boundarylen/boundarylenfinal values directly too. (struct _header_scan_stack): Add an atleast parameter to cache the atleast info. (folder_push_part): Determine/set 'atleast', every time we add a new part. (folder_scan_header): Get the cached atleast info from the current part. (folder_scan_content): And here too. (folder_scan_header): Fix a problem where a part starting with " text" would be interpreted as a followon header wrongly. * camel-mime-filter-charset.c (complete): Add some assertions to find a bug. svn path=/trunk/; revision=6500
Diffstat (limited to 'camel/camel-mime-filter-bestenc.c')
-rw-r--r--camel/camel-mime-filter-bestenc.c45
1 files changed, 44 insertions, 1 deletions
diff --git a/camel/camel-mime-filter-bestenc.c b/camel/camel-mime-filter-bestenc.c
index d3db9a2a3f..18ee7039f0 100644
--- a/camel/camel-mime-filter-bestenc.c
+++ b/camel/camel-mime-filter-bestenc.c
@@ -20,6 +20,8 @@
#include "camel-mime-filter-bestenc.h"
+#include <string.h>
+
static void camel_mime_filter_bestenc_class_init (CamelMimeFilterBestencClass *klass);
static void camel_mime_filter_bestenc_init (CamelMimeFilter *obj);
@@ -54,6 +56,10 @@ reset(CamelMimeFilter *mf)
f->total = 0;
f->lastc = ~0;
f->crlfnoorder = FALSE;
+ f->fromcount = 0;
+ f->hadfrom = FALSE;
+ f->startofline = TRUE;
+
camel_charset_init(&f->charset);
}
@@ -63,7 +69,8 @@ filter(CamelMimeFilter *mf, char *in, size_t len, size_t prespace, char **out, s
CamelMimeFilterBestenc *f = (CamelMimeFilterBestenc *)mf;
register unsigned char *p, *pend;
- f->total += len;
+ if (len == 0)
+ goto donothing;
if (f->flags & CAMEL_BESTENC_GET_ENCODING) {
register unsigned int /* hopefully reg's are assinged in the order they appear? */
@@ -73,6 +80,21 @@ filter(CamelMimeFilter *mf, char *in, size_t len, size_t prespace, char **out, s
count0=f->count0,
count8 = f->count8;
+ /* Check ^From lines first call, or have the start of a new line waiting? */
+ if ((f->flags & CAMEL_BESTENC_NO_FROM) && !f->hadfrom
+ && (f->fromcount > 0 || f->startofline)) {
+ if (f->fromcount + len >=5) {
+ memcpy(&f->fromsave[f->fromcount], in, 5-f->fromcount);
+ f->hadfrom = strncmp(f->fromsave, "From ", 5) == 0;
+ f->fromcount = 0;
+ } else {
+ memcpy(&f->fromsave[f->fromcount], in, len);
+ f->fromcount += len;
+ }
+ }
+
+ f->startofline = FALSE;
+
/* See rfc2045 section 2 for definitions of 7bit/8bit/binary */
p = in;
pend = p + len;
@@ -98,6 +120,18 @@ filter(CamelMimeFilter *mf, char *in, size_t len, size_t prespace, char **out, s
if (countline > f->maxline)
f->maxline = countline;
countline = 0;
+
+ /* Check for "^From " lines */
+ if ((f->flags & CAMEL_BESTENC_NO_FROM) && !f->hadfrom) {
+ if (pend-p >= 5) {
+ f->hadfrom = strncmp(p, "From ", 5) == 0;
+ } else if (pend-p == 0) {
+ f->startofline = TRUE;
+ } else {
+ f->fromcount = pend-p;
+ memcpy(f->fromsave, p, pend-p);
+ }
+ }
} else {
f->crlfnoorder = TRUE;
}
@@ -112,9 +146,12 @@ filter(CamelMimeFilter *mf, char *in, size_t len, size_t prespace, char **out, s
f->lastc = lastc;
}
+ f->total += len;
+
if (f->flags & CAMEL_BESTENC_GET_CHARSET)
camel_charset_step(&f->charset, in, len);
+donothing:
*out = in;
*outlen = len;
*outprespace = prespace;
@@ -187,6 +224,12 @@ camel_mime_filter_bestenc_get_best_encoding(CamelMimeFilterBestenc *f, CamelBest
printf(" %d%% require encoding?\n", (f->count0+f->count8)*100 / f->total);
#endif
+ /* if we're not allowed to have From lines and we had one, use an encoding
+ that will never let it show. Unfortunately only base64 can at present,
+ although qp could be modified to allow it too */
+ if ((f->flags & CAMEL_BESTENC_NO_FROM) && f->hadfrom)
+ return CAMEL_MIME_PART_ENCODING_BASE64;
+
/* if we need to encode, see how we do it */
if (required == CAMEL_BESTENC_BINARY)
bestenc = CAMEL_MIME_PART_ENCODING_BINARY;