aboutsummaryrefslogtreecommitdiffstats
path: root/camel/camel-mime-part.c
diff options
context:
space:
mode:
authorEttore Perazzoli <ettore@src.gnome.org>1999-11-17 22:39:25 +0800
committerEttore Perazzoli <ettore@src.gnome.org>1999-11-17 22:39:25 +0800
commitca7044930f42a698fd88f914c2512a20e2eeaae9 (patch)
tree522962a77005d741097713e87de1d50353b17768 /camel/camel-mime-part.c
parent16de3313b700cb56ab9e829d1e9b7e7d2c81241b (diff)
downloadgsoc2013-evolution-ca7044930f42a698fd88f914c2512a20e2eeaae9.tar
gsoc2013-evolution-ca7044930f42a698fd88f914c2512a20e2eeaae9.tar.gz
gsoc2013-evolution-ca7044930f42a698fd88f914c2512a20e2eeaae9.tar.bz2
gsoc2013-evolution-ca7044930f42a698fd88f914c2512a20e2eeaae9.tar.lz
gsoc2013-evolution-ca7044930f42a698fd88f914c2512a20e2eeaae9.tar.xz
gsoc2013-evolution-ca7044930f42a698fd88f914c2512a20e2eeaae9.tar.zst
gsoc2013-evolution-ca7044930f42a698fd88f914c2512a20e2eeaae9.zip
Added streaming capability to CamelDataWrapper. This makes it possible, for
example, to build multipart messages out of files that are on disk without loading them in memory. svn path=/trunk/; revision=1394
Diffstat (limited to 'camel/camel-mime-part.c')
-rw-r--r--camel/camel-mime-part.c102
1 files changed, 72 insertions, 30 deletions
diff --git a/camel/camel-mime-part.c b/camel/camel-mime-part.c
index 180a843c02..fbf7c89591 100644
--- a/camel/camel-mime-part.c
+++ b/camel/camel-mime-part.c
@@ -60,7 +60,7 @@ static void _finalize (GtkObject *object);
/* from CamelDataWrapper */
static void _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
-void _construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
+static void _construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
/* from CamelMedia */
static void _add_header (CamelMedium *medium, gchar *header_name, gchar *header_value);
@@ -79,8 +79,8 @@ static void _set_content_id (CamelMimePart *mime_part, gchar *content_id);
static const gchar *_get_content_id (CamelMimePart *mime_part);
static void _set_content_MD5 (CamelMimePart *mime_part, gchar *content_MD5);
static const gchar *_get_content_MD5 (CamelMimePart *mime_part);
-static void _set_encoding (CamelMimePart *mime_part, gchar *encoding);
-static const gchar *_get_encoding (CamelMimePart *mime_part);
+static void _set_encoding (CamelMimePart *mime_part, CamelMimePartEncodingType encoding);
+static CamelMimePartEncodingType _get_encoding (CamelMimePart *mime_part);
static void _set_content_languages (CamelMimePart *mime_part, GList *content_languages);
static const GList *_get_content_languages (CamelMimePart *mime_part);
static void _set_header_lines (CamelMimePart *mime_part, GList *header_lines);
@@ -162,7 +162,7 @@ camel_mime_part_init (gpointer object, gpointer klass)
camel_mime_part->content_id = NULL;
camel_mime_part->content_MD5 = NULL;
camel_mime_part->content_languages = NULL;
- camel_mime_part->encoding = NULL;
+ camel_mime_part->encoding = CAMEL_MIME_PART_ENCODING_DEFAULT;
camel_mime_part->filename = NULL;
camel_mime_part->header_lines = NULL;
@@ -214,7 +214,6 @@ _finalize (GtkObject *object)
g_free (mime_part->content_id);
g_free (mime_part->content_MD5);
string_list_free (mime_part->content_languages);
- g_free (mime_part->encoding);
g_free (mime_part->filename);
if (mime_part->header_lines) string_list_free (mime_part->header_lines);
@@ -416,14 +415,14 @@ camel_mime_part_get_content_MD5 (CamelMimePart *mime_part)
static void
-_set_encoding (CamelMimePart *mime_part, gchar *encoding)
+_set_encoding (CamelMimePart *mime_part, CamelMimePartEncodingType encoding)
{
- g_free(mime_part->encoding);
mime_part->encoding = encoding;
}
void
-camel_mime_part_set_encoding (CamelMimePart *mime_part, gchar *encoding)
+camel_mime_part_set_encoding (CamelMimePart *mime_part,
+ CamelMimePartEncodingType encoding)
{
CMP_CLASS(mime_part)->set_encoding (mime_part, encoding);
}
@@ -433,13 +432,13 @@ camel_mime_part_set_encoding (CamelMimePart *mime_part, gchar *encoding)
-static const gchar *
+static CamelMimePartEncodingType
_get_encoding (CamelMimePart *mime_part)
{
return mime_part->encoding;
}
-const gchar *
+const CamelMimePartEncodingType
camel_mime_part_get_encoding (CamelMimePart *mime_part)
{
return CMP_CLASS(mime_part)->get_encoding (mime_part);
@@ -620,6 +619,7 @@ static void
_write_content_to_stream (CamelMimePart *mime_part, CamelStream *stream)
{
CamelMedium *medium = CAMEL_MEDIUM (mime_part);
+ CamelStream *wrapper_stream;
guint buffer_size;
gchar *buffer;
gchar *encoded_buffer;
@@ -629,23 +629,27 @@ _write_content_to_stream (CamelMimePart *mime_part, CamelStream *stream)
CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::_write_content_to_stream, content=%p\n", content);
if (!content) return;
- /* buffer_size = camel_data_wrapper_size (content); */
- /* buffer = g_malloc (buffer_size); */
-
- camel_data_wrapper_write_to_stream (content, stream);
-
-#if 0
- //if (mime_part->encoding) {
- // encoded_buffer_size = gmime_encoded_size(buffer, buffer_size, encoding);
- // encoded_buffer = g_malloc (encoded_buffer_size);
- // gmime_encode_buffer (buffer, encoded_buffer, encoding);
- // camel_stream_write (stream, encoded_buffer, encoded_buffer_size);
- // g_free (encoded_buffer);
- //} else
- //fwrite (buffer, buffer_size, 1, file);
- //camel_stream_write (stream, buffer, buffer_size);
- //g_free (buffer);
-#endif
+ switch (mime_part->encoding) {
+ case CAMEL_MIME_PART_ENCODING_DEFAULT:
+ case CAMEL_MIME_PART_ENCODING_7BIT:
+ case CAMEL_MIME_PART_ENCODING_8BIT:
+ camel_data_wrapper_write_to_stream (content, stream);
+ break;
+ case CAMEL_MIME_PART_ENCODING_BASE64:
+ wrapper_stream = camel_data_wrapper_get_stream (content);
+ if (wrapper_stream == NULL) {
+ /* FIXME in this case, we should probably copy stuff
+ in-memory and make sure things work anyway. */
+ g_warning ("Class `%s' does not implement `get_stream'",
+ gtk_type_name (GTK_OBJECT (content)->klass->type));
+ }
+ gmime_encode_base64 (wrapper_stream, stream);
+ break;
+ default:
+ g_warning ("Encoding type `%s' not supported.",
+ camel_mime_part_encoding_to_string
+ (mime_part->encoding));
+ }
CAMEL_LOG_FULL_DEBUG ( "Leaving CamelMimePart::_write_content_to_stream\n");
}
@@ -665,7 +669,8 @@ _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::write_to_stream writing content-disposition\n");
gmime_content_field_write_to_stream(mp->disposition, stream);
CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::write_to_stream writing content-transfer-encoding\n");
- WHPT (stream, "Content-Transfer-Encoding", mp->encoding);
+ WHPT (stream, "Content-Transfer-Encoding",
+ camel_mime_part_encoding_to_string (mp->encoding));
CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::write_to_stream writing content-description\n");
WHPT (stream, "Content-Description", mp->description);
CAMEL_LOG_FULL_DEBUG ( "CamelMimePart::write_to_stream writing content-MD5\n");
@@ -733,7 +738,9 @@ _parse_header_pair (CamelMimePart *mime_part, gchar *header_name, gchar *header_
"CamelMimePart::parse_header_pair found HEADER_ENCODING: %s\n",
header_value);
- camel_mime_part_set_encoding (mime_part, header_value);
+ camel_mime_part_set_encoding
+ (mime_part,
+ camel_mime_part_encoding_from_string (header_value));
header_handled = TRUE;
break;
@@ -767,7 +774,7 @@ _parse_header_pair (CamelMimePart *mime_part, gchar *header_name, gchar *header_
}
-void
+static void
_construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
{
@@ -782,6 +789,41 @@ _construct_from_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
}
+const gchar *
+camel_mime_part_encoding_to_string (CamelMimePartEncodingType encoding)
+{
+ switch (encoding) {
+ case CAMEL_MIME_PART_ENCODING_DEFAULT:
+ case CAMEL_MIME_PART_ENCODING_7BIT:
+ return "7bit";
+ case CAMEL_MIME_PART_ENCODING_8BIT:
+ return "8bit";
+ case CAMEL_MIME_PART_ENCODING_BASE64:
+ return "base64";
+ case CAMEL_MIME_PART_ENCODING_QUOTEDPRINTABLE:
+ return "quoted-printable";
+ }
+}
+
+
+/* FIXME I am not sure this is the correct way to do this. */
+CamelMimePartEncodingType
+camel_mime_part_encoding_from_string (const gchar *string)
+{
+ if (strncmp (string, "7bit") == 0)
+ return CAMEL_MIME_PART_ENCODING_7BIT;
+ else if (strncmp (string, "8bit") == 0)
+ return CAMEL_MIME_PART_ENCODING_8BIT;
+ else if (strncmp (string, "base64") == 0)
+ return CAMEL_MIME_PART_ENCODING_BASE64;
+ else if (strncmp (string, "quoted-printable") == 0)
+ return CAMEL_MIME_PART_ENCODING_QUOTEDPRINTABLE;
+ else
+ /* FIXME? Spit a warning? */
+ return CAMEL_MIME_PART_ENCODING_DEFAULT;
+}
+
+
/******************************/
/** Misc utility functions **/