diff options
author | Peter Williams <peterw@ximian.com> | 2001-06-29 04:35:43 +0800 |
---|---|---|
committer | Peter Williams <peterw@src.gnome.org> | 2001-06-29 04:35:43 +0800 |
commit | 6ffa930086b903dbd8fed3543f5e4ed762b6e8d1 (patch) | |
tree | 805bc825e07162f42996776921d770efe44b4b69 /camel/tests/mime-filter/test-stripheader.c | |
parent | dacae0532fb39cee00b4f8ccfa8157d3a31b3a80 (diff) | |
download | gsoc2013-evolution-6ffa930086b903dbd8fed3543f5e4ed762b6e8d1.tar gsoc2013-evolution-6ffa930086b903dbd8fed3543f5e4ed762b6e8d1.tar.gz gsoc2013-evolution-6ffa930086b903dbd8fed3543f5e4ed762b6e8d1.tar.bz2 gsoc2013-evolution-6ffa930086b903dbd8fed3543f5e4ed762b6e8d1.tar.lz gsoc2013-evolution-6ffa930086b903dbd8fed3543f5e4ed762b6e8d1.tar.xz gsoc2013-evolution-6ffa930086b903dbd8fed3543f5e4ed762b6e8d1.tar.zst gsoc2013-evolution-6ffa930086b903dbd8fed3543f5e4ed762b6e8d1.zip |
Add a CamelMimeFilterStripHeader that removes a header from mime output. Used
by sendmail to strip the BCC from the email while still sending to the BCC
recipients.
camel:
2001-06-28 Peter Williams <peterw@ximian.com>
* camel-mime-filter-stripheader.c: New file. Filter that strips a
header from mime output.
* camel-mime-filter-stripheader.h: New file. Header for the above.
* providers/smtp/camel-smtp-transport.c (smtp_data): Use the stripheader
filter to remove the "Bcc" header.
* Makefile.am: Add the stripheader files.
* tests/lib/Makefile.am (INCLUDES): Get this to compile again.
* tests/mime-filter/test-stripheader.c: New file. Test suite for
the CamelMimeFilterStripHeader.
* tests/mime-filter/Makefile.am: New test section: mime filters.
mail:
2001-06-28 Peter Williams <peterw@ximian.com>
* mail-ops.c (mail_send_message): Revert fejj's Bcc header removal;
this unsets the BCC recipients and so doesn't send to the Bcc'd
people at all.
svn path=/trunk/; revision=10576
Diffstat (limited to 'camel/tests/mime-filter/test-stripheader.c')
-rw-r--r-- | camel/tests/mime-filter/test-stripheader.c | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/camel/tests/mime-filter/test-stripheader.c b/camel/tests/mime-filter/test-stripheader.c new file mode 100644 index 0000000000..ff5446635b --- /dev/null +++ b/camel/tests/mime-filter/test-stripheader.c @@ -0,0 +1,131 @@ +/* + test-stripheader.c + + Test the CamelMimeFilterStripHeader class +*/ + +#include <stdio.h> +#include <string.h> + +#include "camel-test.h" + +#include <camel/camel-stream-fs.h> +#include <camel/camel-stream-mem.h> +#include <camel/camel-stream-filter.h> +#include <camel/camel-mime-filter-stripheader.h> + +#define d(x) x + +#define NUM_CASES 6 +#define CHUNK_SIZE 32 + +int +main(int argc, char **argv) +{ + CamelStream *source; + CamelStream *correct; + CamelStreamFilter *filter; + CamelMimeFilter *sh; + gchar *work; + int i; + ssize_t comp_progress, comp_correct_chunk, comp_filter_chunk; + int comp_i; + char comp_correct[CHUNK_SIZE], comp_filter[CHUNK_SIZE]; + + camel_test_init(argc, argv); + + for (i = 0; i < NUM_CASES; i++) { + work = g_strdup_printf ("Header stripping filter, test case %d", i); + camel_test_start (work); + g_free (work); + + camel_test_push ("Initializing objects"); + work = g_strdup_printf ("%s/stripheader-%d.in", SOURCEDIR, i + 1); + source = camel_stream_fs_new_with_name (work, 0, O_RDONLY); + if (!source) { + camel_test_fail ("Failed to open input case in \"%s\"", work); + g_free (work); + continue; + } + g_free (work); + + work = g_strdup_printf ("%s/stripheader-%d.out", SOURCEDIR, i + 1); + correct = camel_stream_fs_new_with_name (work, 0, O_RDONLY); + if (!correct) { + camel_test_fail ("Failed to open correct output in \"%s\"", work); + g_free (work); + continue; + } + g_free (work); + + filter = camel_stream_filter_new_with_stream (CAMEL_STREAM (source)); + if (!filter) { + camel_test_fail ("Couldn't create CamelStreamFilter??"); + continue; + } + + sh = camel_mime_filter_stripheader_new ("Stripped"); + if (!sh) { + camel_test_fail ("Couldn't create CamelMimeFilterStripHeader??"); + continue; + } + + camel_stream_filter_add (filter, sh); + camel_test_pull (); + + camel_test_push ("Running filter and comparing to correct result"); + + comp_progress = 0; + + while (1) { + comp_correct_chunk = camel_stream_read (correct, comp_correct, CHUNK_SIZE); + comp_filter_chunk = 0; + + if (comp_correct_chunk == 0) + break; + + while (comp_filter_chunk < comp_correct_chunk) { + ssize_t delta; + + delta = camel_stream_read (CAMEL_STREAM (filter), + comp_filter + comp_filter_chunk, + CHUNK_SIZE - comp_filter_chunk); + + if (delta == 0) { + camel_test_fail ("Chunks are different sizes: correct is %d, filter is %d, %d bytes into stream", + comp_correct_chunk, comp_filter_chunk, comp_progress); + } + + comp_filter_chunk += delta; + } + + d(printf ("\n\nCORRECT: >>%.*s<<", comp_correct_chunk, comp_correct);) + d(printf ("\nFILTER : >>%.*s<<\n", comp_filter_chunk, comp_filter);) + + for (comp_i = 0; comp_i < comp_filter_chunk; comp_i++) { + if (comp_correct[comp_i] != comp_filter[comp_i]) { + camel_test_fail ("Difference: correct is %c, filter is %c, %d bytes into stream", + comp_correct[comp_i], + comp_filter[comp_i], + comp_progress + comp_i); + } + } + + comp_progress += comp_filter_chunk; + } + + camel_test_pull (); + + /* inefficient */ + camel_test_push ("Cleaning up"); + camel_object_unref (CAMEL_OBJECT (filter)); + camel_object_unref (CAMEL_OBJECT (correct)); + camel_object_unref (CAMEL_OBJECT (source)); + camel_object_unref (CAMEL_OBJECT (sh)); + camel_test_pull (); + + camel_test_end(); + } + + return 0; +} |