aboutsummaryrefslogtreecommitdiffstats
path: root/camel/camel-mime-part.c
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2003-07-17 04:45:26 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2003-07-17 04:45:26 +0800
commitb83ddf044ce11b4c52996f7827d843465ad5659b (patch)
tree906e25e3703bfa9c2f048c1511cc37baa0189e18 /camel/camel-mime-part.c
parent0b562324921620bf50b946efe05895ac930fbb6e (diff)
downloadgsoc2013-evolution-b83ddf044ce11b4c52996f7827d843465ad5659b.tar
gsoc2013-evolution-b83ddf044ce11b4c52996f7827d843465ad5659b.tar.gz
gsoc2013-evolution-b83ddf044ce11b4c52996f7827d843465ad5659b.tar.bz2
gsoc2013-evolution-b83ddf044ce11b4c52996f7827d843465ad5659b.tar.lz
gsoc2013-evolution-b83ddf044ce11b4c52996f7827d843465ad5659b.tar.xz
gsoc2013-evolution-b83ddf044ce11b4c52996f7827d843465ad5659b.tar.zst
gsoc2013-evolution-b83ddf044ce11b4c52996f7827d843465ad5659b.zip
Add the CamelMimePartEncodingType definition here.
2003-07-14 Jeffrey Stedfast <fejj@ximian.com> * camel-mime-utils.h: Add the CamelMimePartEncodingType definition here. * camel-mime-part.h: Remove the CamelMimePartEncodingType definition. * camel-mime-part-utils.c (simple_data_wrapper_construct_from_parser): Don't do any of the auto-detection we used to do here anymore. Just read the content into a memory buffer and record the encoding type. (camel_mime_part_construct_content_from_parser): Don't mangle the Content-Type struct here anymore. * camel-data-wrapper.c (camel_data_wrapper_init): Init encoding to DEFAULT. (write_to_stream): If the stream needs to be decoded, decode it. svn path=/trunk/; revision=21842
Diffstat (limited to 'camel/camel-mime-part.c')
-rw-r--r--camel/camel-mime-part.c127
1 files changed, 56 insertions, 71 deletions
diff --git a/camel/camel-mime-part.c b/camel/camel-mime-part.c
index 343248715b..e6ab427f49 100644
--- a/camel/camel-mime-part.c
+++ b/camel/camel-mime-part.c
@@ -75,7 +75,7 @@ static CamelMediumClass *parent_class=NULL;
static int write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
static int construct_from_stream (CamelDataWrapper *dw, CamelStream *s);
-/* from CamelMedia */
+/* from CamelMedium */
static void add_header (CamelMedium *medium, const char *header_name, const void *header_value);
static void set_header (CamelMedium *medium, const char *header_name, const void *header_value);
static void remove_header (CamelMedium *medium, const char *header_name);
@@ -626,7 +626,6 @@ write_to_stream(CamelDataWrapper *data_wrapper, CamelStream *stream)
{
CamelMimePart *mp = CAMEL_MIME_PART(data_wrapper);
CamelMedium *medium = CAMEL_MEDIUM(data_wrapper);
- CamelStream *ostream = stream;
CamelDataWrapper *content;
int total = 0;
int count;
@@ -667,89 +666,75 @@ write_to_stream(CamelDataWrapper *data_wrapper, CamelStream *stream)
return -1;
total += count;
- content = camel_medium_get_content_object(medium);
+ content = camel_medium_get_content_object (medium);
if (content) {
- /* I dont really like this here, but i dont know where else it might go ... */
-#define CAN_THIS_GO_ELSEWHERE
-#ifdef CAN_THIS_GO_ELSEWHERE
- CamelMimeFilter *filter = NULL;
- CamelStreamFilter *filter_stream = NULL;
- CamelMimeFilter *charenc = NULL;
- const char *filename;
- const char *charset;
-
- switch (mp->encoding) {
- case CAMEL_MIME_PART_ENCODING_BASE64:
- filter = (CamelMimeFilter *)camel_mime_filter_basic_new_type(CAMEL_MIME_FILTER_BASIC_BASE64_ENC);
- break;
- case CAMEL_MIME_PART_ENCODING_QUOTEDPRINTABLE:
- filter = (CamelMimeFilter *)camel_mime_filter_basic_new_type(CAMEL_MIME_FILTER_BASIC_QP_ENC);
- break;
- case CAMEL_MIME_PART_ENCODING_UUENCODE:
- filename = camel_mime_part_get_filename (mp);
- count = camel_stream_printf (ostream, "begin 644 %s\n", filename ? filename : "untitled");
+ if (mp->encoding != content->encoding) {
+ /* we need to (re)encode the content stream */
+ CamelStream *filter_stream = NULL;
+ CamelMimeFilter *filter = NULL;
+ const char *filename;
+
+ filter_stream = (CamelStream *) camel_stream_filter_new_with_stream (stream);
+ switch (mp->encoding) {
+ case CAMEL_MIME_PART_ENCODING_BASE64:
+ filter = (CamelMimeFilter *) camel_mime_filter_basic_new_type (CAMEL_MIME_FILTER_BASIC_BASE64_ENC);
+ camel_stream_filter_add (CAMEL_STREAM_FILTER (filter_stream), filter);
+ camel_object_unref (filter);
+ break;
+ case CAMEL_MIME_PART_ENCODING_QUOTEDPRINTABLE:
+ filter = (CamelMimeFilter *) camel_mime_filter_basic_new_type (CAMEL_MIME_FILTER_BASIC_QP_ENC);
+ camel_stream_filter_add (CAMEL_STREAM_FILTER (filter_stream), filter);
+ camel_object_unref (filter);
+ break;
+ case CAMEL_MIME_PART_ENCODING_UUENCODE:
+ filename = camel_mime_part_get_filename (mp);
+ count = camel_stream_printf (stream, "begin 0644 %s\n", filename ? filename : "unknown");
+ if (count == -1) {
+ camel_object_unref (filter_stream);
+ return -1;
+ }
+
+ total += count;
+
+ filter = (CamelMimeFilter *) camel_mime_filter_basic_new_type (CAMEL_MIME_FILTER_BASIC_UU_ENC);
+ camel_stream_filter_add (CAMEL_STREAM_FILTER (filter_stream), filter);
+ camel_object_unref (filter);
+ break;
+ default:
+ break;
+ }
+
+ count = camel_data_wrapper_write_to_stream (content, filter_stream);
+ camel_stream_flush (filter_stream);
+ camel_object_unref (filter_stream);
+
if (count == -1)
return -1;
- total += count;
- filter = (CamelMimeFilter *)camel_mime_filter_basic_new_type(CAMEL_MIME_FILTER_BASIC_UU_ENC);
- break;
- default:
- break;
- }
-
- if (!content->rawtext && header_content_type_is(mp->content_type, "text", "*")) {
- charset = header_content_type_param(mp->content_type, "charset");
- if (charset && !(!strcasecmp(charset, "us-ascii") || !strcasecmp(charset, "utf-8"))) {
- charenc = (CamelMimeFilter *)camel_mime_filter_charset_new_convert("UTF-8", charset);
- }
- }
-
- if (filter || charenc) {
- filter_stream = camel_stream_filter_new_with_stream(stream);
- /* if we have a character encoder, add that always */
- if (charenc) {
- camel_stream_filter_add(filter_stream, charenc);
- camel_object_unref((CamelObject *)charenc);
- }
+ total += count;
- /* we only re-do crlf on encoded blocks */
- if (filter && header_content_type_is(mp->content_type, "text", "*")) {
- CamelMimeFilter *crlf = camel_mime_filter_crlf_new(CAMEL_MIME_FILTER_CRLF_ENCODE,
- CAMEL_MIME_FILTER_CRLF_MODE_CRLF_ONLY);
+ if (mp->encoding == CAMEL_MIME_PART_ENCODING_UUENCODE) {
+ /* FIXME: get rid of this special-case x-uuencode crap */
+ count = camel_stream_write (stream, "end\n", 4);
+ if (count == -1)
+ return -1;
- camel_stream_filter_add(filter_stream, crlf);
- camel_object_unref((CamelObject *)crlf);
+ total += count;
}
+ } else {
+ /* write the content out raw... */
+ if (camel_stream_reset (content->stream) == -1)
+ return -1;
- if (filter) {
- camel_stream_filter_add(filter_stream, filter);
- camel_object_unref((CamelObject *)filter);
- }
+ count = camel_stream_write_to_stream (content->stream, stream);
- stream = (CamelStream *)filter_stream;
- }
-
-#endif
-
- count = camel_data_wrapper_write_to_stream(content, stream);
-
- if (filter_stream) {
- camel_stream_flush((CamelStream *)filter_stream);
- camel_object_unref((CamelObject *)filter_stream);
- }
- if (count == -1)
- return -1;
- total += count;
-
- if (mp->encoding == CAMEL_MIME_PART_ENCODING_UUENCODE) {
- count = camel_stream_write (ostream, "end\n", 4);
if (count == -1)
return -1;
+
total += count;
}
} else {
- g_warning("No content for medium, nothing to write");
+ g_warning ("No content for medium, nothing to write");
}
return total;