diff options
author | NotZed <NotZed@HelixCode.com> | 2000-04-23 18:10:44 +0800 |
---|---|---|
committer | Michael Zucci <zucchi@src.gnome.org> | 2000-04-23 18:10:44 +0800 |
commit | 5fcb83b5fb1294a781e3f7139200aa3486650db4 (patch) | |
tree | a890998dfce162ec25eb55b238e537f506abb6c1 /camel/camel-mime-utils.c | |
parent | f229f08168b0666469e0fc35d065860f2da58303 (diff) | |
download | gsoc2013-evolution-5fcb83b5fb1294a781e3f7139200aa3486650db4.tar.gz gsoc2013-evolution-5fcb83b5fb1294a781e3f7139200aa3486650db4.tar.zst gsoc2013-evolution-5fcb83b5fb1294a781e3f7139200aa3486650db4.zip |
Whole swag of changes. Still lots of cleanup remaining ...
2000-04-23 NotZed <NotZed@HelixCode.com>
* camel-data-wrapper.c (set_mime_type_field): Ref the
content_field when we get it?
* camel-mime-parser.c (camel_mime_parser_unstep): New function.
Cause a subsequent call to mime_parser_step() to return the same
state over again.
* providers/mbox/camel-mbox-folder.c (_get_message_by_uid):
Initial test code using the mime parser to construct the message.
* camel-mime-part.c (construct_from_parser): part constructor.
(camel_mime_part_construct_content): Basically a simpler
replacement for the datawrapper repository.
(camel_mime_part_init): Set the default type to text/plain.
* camel-simple-data-wrapper.c (construct_from_parser): Initial
implementation of a content constructor.
* camel-multipart.c (construct_from_parser): Multipart
construction routine.
(camel_multipart_init): Set the default multipart type to
multipart/mixed. Duh, no subtype is not allowed anyway.
2000-04-22 NotZed <NotZed@HelixCode.com>
* camel-mime-message.h (struct _CamelMimeMessage): Removed
send_date, and received_date, and replaced it with a time_t
'date' (this is what the header is called), and date_offset to
store the GMT offset of the date.
* camel-mime-message.c (camel_mime_message_set_from): Update raw
header as we go.
(_set_from): Removed.
(_get_from): Removed.
(camel_mime_message_get_from): Moved implementation here.
(camel_mime_message_get_subject): Move implementation here.
(_get_subject): Nuked.
(camel_mime_message_set_subject): Handle utf-8 input, and also
update raw header when changed.
(_set_subject): Removed.
(_set_received_date): Removed.
(camel_mime_message_set_received_date): Removed.
(_get_received_date): Removed.
(camel_mime_message_get_received_date): Removed.
(_get_sent_date): Removed.
(camel_mime_message_get_sent_date): Removed.
(camel_mime_message_get_date): New function to get the date as a
time_t/offset.
(camel_mime_message_set_date): Set the date as a time_t/offset.
(camel_mime_message_get_date_string): Get the date as a string.
(camel_mime_message_init): Initialise the current date as
'CMAEL_MESSAGE_DATE_CURRENT'.
(_set_reply_to): Removed.
(camel_mime_message_set_reply_to): Moved implementation here.
This is still broken, reply-to can have multiple addresses.
(_get_reply_to): Removed.
(_set_field): Removed, no longer used anywhere.
(_get_field): Also removed.
(_init_header_name_table): Add the Date header.
(process_header): Also handle snooping of Date header here.
* camel-stream-filter.c (finalise): Unref the source stream on
finalise, and also call the parent class (oops).
* camel-mime-parser.c (camel_mime_parser_state): New function to
get the current parser state.
(camel_mime_parser_stream): Allow you to get the stream back from
the mime_parser.
(camel_mime_parser_fd): Alternative to allow you to get the fd
back from the mime_parser.
(folder_scan_init_with_stream): Properly ref/unref the stream.
(folder_scan_close): Properly unref the stream/close the fd on
exit.
(folder_scan_init_with_fd): Close the old fd if there is one.
* camel-data-wrapper.c (camel_data_wrapper_construct_from_parser):
New method, construct a data wrapper from an initialised parser.
(construct_from_parser): Empty implementation.
* providers/mbox/camel-mbox-summary.c (message_struct_new):
Convert subject line to unicode, before storing in the summary.
(strdup_trim): Removed, no longer needed.
* providers/mbox/camel-mbox-folder.c (_get_message_by_uid): Ref
the folder after setting it in the new message.
* camel-mime-part.c (my_set_content_object): Have the headers
follow the content-type change here too.
(my_write_to_stream): Dont write content-type here, automatically
stored in the headers ...
(my_write_to_stream): Use header_disposition_format() to format
the content-disposition header.
(my_write_to_stream): Removed old code, all headers are now stored
in the camel-medium level, always. Need to do the same with
camel-mime-message i suppose ...
(my_write_to_stream): Write the content using the parent class,
not some weird function.
(camel_mime_part_class_init): Dont override get_output_stream.
(camel_mime_part_encoding_from_string): Bleh, make it
case-insensitive.
* camel-mime-utils.c (header_content_type_is): Handle empty types.
(header_encode_string): Start of an implementation of the rfc2047
encoder. It does iso-8859-1, and us-ascii, and utf-8 (others get
tricky *sigh*)
(rfc2047_encode_word): Convert a single word/string into rfc2047
encoding.
(quoted_encode): Different quoted-printable encoding for rfc2047
encoding of headers.
* gmime-content-field.c (gmime_content_field_write_to_stream): Use
header_content_type_format() to format it.
svn path=/trunk/; revision=2560
Diffstat (limited to 'camel/camel-mime-utils.c')
-rw-r--r-- | camel/camel-mime-utils.c | 152 |
1 files changed, 150 insertions, 2 deletions
diff --git a/camel/camel-mime-utils.c b/camel/camel-mime-utils.c index 7b1ad93cd0..25970e58a0 100644 --- a/camel/camel-mime-utils.c +++ b/camel/camel-mime-utils.c @@ -34,6 +34,7 @@ #include <time.h> #include <ctype.h> +#include <errno.h> #include "camel-mime-utils.h" @@ -586,6 +587,35 @@ quoted_decode(const unsigned char *in, int len, unsigned char *out) return -1; } +/* rfc2047 version of quoted-printable */ +static int +quoted_encode(const unsigned char *in, int len, unsigned char *out) +{ + register const unsigned char *inptr, *inend; + unsigned char *outptr; + unsigned char c; + + inptr = in; + inend = in+len; + outptr = out; + while (inptr<inend) { + c = *inptr++; + if (is_qpsafe(c) && !(c=='_' || c=='?')) { + if (c==' ') + c='_'; + *outptr++=c; + } else { + *outptr++ = '='; + *outptr++ = tohex[(c>>4) & 0xf]; + *outptr++ = tohex[c & 0xf]; + } + } + + printf("encoding '%.*s' = '%.*s'\n", len, in, outptr-out, out); + + return outptr-out; +} + static void header_decode_lwsp(const char **in) @@ -736,6 +766,7 @@ header_decode_text(const char *in, int inlen) encstart = out->str; g_string_free(out, FALSE); + return encstart; } @@ -747,6 +778,125 @@ header_decode_string(const char *in) return header_decode_text(in, strlen(in)); } +static char *encoding_map[] = { + "US-ASCII", + "ISO-8859-1", + "UTF-8" +}; + +/* FIXME: needs a way to cache iconv opens for different charsets? */ +static +char *rfc2047_encode_word(const char *in, int len, char *type) +{ + unicode_iconv_t ic; + char *buffer, *out, *ascii; + size_t inlen, outlen, enclen; + + printf("Converting '%.*s' to %s\n", len, in, type); + + /* convert utf8->encoding */ + outlen = len*6; + buffer = alloca(outlen); + inlen = len; + out = buffer; + + /* if we can't convert from utf-8, just encode as utf-8 */ + if (!strcasecmp(type, "UTF-8") + || (ic = unicode_iconv_open(type, "UTF-8")) == (unicode_iconv_t)-1) { + memcpy(buffer, in, len); + out = buffer+len; + type = "UTF-8"; + } else { + if (unicode_iconv(ic, &in, &inlen, &out, &outlen) == -1) { + g_warning("Conversion problem: conversion truncated: %s", strerror(errno)); + } + unicode_iconv_close(ic); + } + enclen = out-buffer; + + /* now create qp version */ + ascii = alloca(enclen*3 + strlen(type) + 8); + out = ascii; + /* should determine which encoding is smaller, and use that? */ + out += sprintf(out, "=?%s?Q?", type); + out += quoted_encode(buffer, enclen, out); + sprintf(out, "?="); + + printf("converted = %s\n", ascii); + return g_strdup(ascii); +} + + +/* TODO: Should this worry about quotes?? */ +char * +header_encode_string(const unsigned char *in) +{ + GString *out; + const unsigned char *inptr = in, *start; + int encoding; + char *outstr; + + if (in == NULL) + return NULL; + + /* do a quick us-ascii check (the common case?) */ + while (*inptr) { + if (*inptr > 127) + break; + inptr++; + } + if (*inptr == 0) + return g_strdup(in); + + /* This gets each word out of the input, and checks to see what charset + can be used to encode it. */ + /* TODO: Work out when to merge subsequent words, or across word-parts */ + /* FIXME: Make sure a converted word is less than the encoding size */ + out = g_string_new(""); + inptr = in; + encoding = 0; + start = inptr; + while (inptr && *inptr) { + unicode_char_t c; + const char *newinptr; + newinptr = unicode_get_utf8(inptr, &c); + if (newinptr == NULL) { + g_warning("Invalid UTF-8 sequence encountered (pos %d, char '%c'): %s", (inptr-in), inptr[0], in); + inptr++; + continue; + } + inptr = newinptr; + if (unicode_isspace(c)) { + if (encoding == 0) { + g_string_append_len(out, start, inptr-start); + } else { + char *text = rfc2047_encode_word(start, inptr-start-1, encoding_map[encoding]); + g_string_append(out, text); + g_string_append_c(out, c); + g_free(text); + } + start = inptr; + encoding = 0; + } else if (c>127 && c < 256) { + encoding = MAX(encoding, 1); + } else if (c >=256) { + encoding = MAX(encoding, 2); + } + } + if (inptr-start) { + if (encoding == 0) { + g_string_append_len(out, start, inptr-start); + } else { + char *text = rfc2047_encode_word(start, inptr-start, encoding_map[encoding]); + g_string_append(out, text); + g_free(text); + } + } + outstr = out->str; + g_string_free(out, FALSE); + return outstr; +} + /* these are all internal parser functions */ @@ -976,8 +1126,6 @@ void header_content_type_set_param(struct _header_content_type *t, const char *n int header_content_type_is(struct _header_content_type *ct, const char *type, const char *subtype) { - printf("type = %s / %s\n", type, subtype); - /* no type == text/plain or text/"*" */ if (ct==NULL) { return (!strcasecmp(type, "text") |