aboutsummaryrefslogtreecommitdiffstats
path: root/camel
diff options
context:
space:
mode:
authorBertrand Guiheneuf <bertrand@src.gnome.org>1999-06-19 04:32:18 +0800
committerBertrand Guiheneuf <bertrand@src.gnome.org>1999-06-19 04:32:18 +0800
commit19a118096fe6f3d7b79a0fe3cb6e5bfe50ef8767 (patch)
tree04f063fc3c18e43eea5251943be93fa89cfd5549 /camel
parent499ae51b86891889ffb5fd9954b1f60efcadfed2 (diff)
downloadgsoc2013-evolution-19a118096fe6f3d7b79a0fe3cb6e5bfe50ef8767.tar.gz
gsoc2013-evolution-19a118096fe6f3d7b79a0fe3cb6e5bfe50ef8767.tar.zst
gsoc2013-evolution-19a118096fe6f3d7b79a0fe3cb6e5bfe50ef8767.zip
Commit of all Netherlands changes.
All mime stuff uses streams now, and it still works. Bertrand svn path=/trunk/; revision=981
Diffstat (limited to 'camel')
-rw-r--r--camel/camel-data-wrapper.h1
-rw-r--r--camel/camel-log.h4
-rw-r--r--camel/camel-mime-message.c41
-rw-r--r--camel/camel-mime-part.c52
-rw-r--r--camel/camel-mime-part.h1
-rw-r--r--camel/camel-stream-fs.c30
-rw-r--r--camel/camel-stream.c22
-rw-r--r--camel/camel-stream.h5
-rw-r--r--camel/gmime-content-field.c28
-rw-r--r--camel/gmime-content-field.h3
-rw-r--r--camel/gmime-utils.c9
11 files changed, 135 insertions, 61 deletions
diff --git a/camel/camel-data-wrapper.h b/camel/camel-data-wrapper.h
index 3c7fb65be4..a7b9dbbff1 100644
--- a/camel/camel-data-wrapper.h
+++ b/camel/camel-data-wrapper.h
@@ -34,6 +34,7 @@ extern "C" {
#include <gtk/gtk.h>
#include <stdio.h>
#include "gmime-content-field.h"
+#include "camel-stream.h"
diff --git a/camel/camel-log.h b/camel/camel-log.h
index b2c9cbe305..dfe023cc3c 100644
--- a/camel/camel-log.h
+++ b/camel/camel-log.h
@@ -38,7 +38,9 @@ typedef enum {
FULL_DEBUG = 10
} CamelLogLevel;
-/* the goal here is to be able to have a hard maximum log
+#define HARD_LOG_LEVEL FULL_DEBUG
+
+/* the idea here is to be able to have a hard maximum log
level, given at compilation time, and a soft one, given at
runtime (with camel_debug_level). For the moment, only
soft level is implmented, but one day, when performance
diff --git a/camel/camel-mime-message.c b/camel/camel-mime-message.c
index b0768d1aa7..dd984fbeac 100644
--- a/camel/camel-mime-message.c
+++ b/camel/camel-mime-message.c
@@ -70,7 +70,7 @@ static gboolean _get_flag (CamelMimeMessage *mime_message, GString *flag);
static void _set_message_number (CamelMimeMessage *mime_message, guint number);
static guint _get_message_number (CamelMimeMessage *mime_message);
-static void _write_to_file(CamelDataWrapper *data_wrapper, FILE *file);
+static void _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
static gboolean _parse_header_pair (CamelMimePart *mime_part, GString *header_name, GString *header_value);
/* Returns the class for a CamelMimeMessage */
@@ -125,7 +125,7 @@ camel_mime_message_class_init (CamelMimeMessageClass *camel_mime_message_class)
camel_mime_message_class->get_message_number = _get_message_number;
/* virtual method overload */
- camel_data_wrapper_class->write_to_file = _write_to_file;
+ camel_data_wrapper_class->write_to_stream = _write_to_stream;
camel_mime_part_class->parse_header_pair = _parse_header_pair;
}
@@ -514,39 +514,44 @@ camel_mime_message_get_message_number (CamelMimeMessage *mime_message)
-#ifdef WHPTF
-#warning : WHPTF is already defined !!!!!!
+#ifdef WHPT
+#warning : WHPT is already defined !!!!!!
#endif
-#define WHPTF gmime_write_header_pair_to_file
+#define WHPT gmime_write_header_pair_to_stream
static void
-_write_one_recipient_to_file (gpointer key, gpointer value, gpointer user_data)
+_write_one_recipient_to_stream (gpointer key, gpointer value, gpointer user_data)
{
GString *recipient_type = (GString *)key;
GList *recipients = (GList *)value;
// GString *current;
- FILE *file = (FILE *)user_data;
+ CamelStream *stream = (CamelStream *)user_data;
if ( (recipient_type) && (recipient_type->str) )
- write_header_with_glist_to_file (file, recipient_type->str, recipients);
+ write_header_with_glist_to_stream (stream, recipient_type->str, recipients);
}
static void
-_write_recipients_to_file (CamelMimeMessage *mime_message, FILE *file)
+_write_recipients_to_stream (CamelMimeMessage *mime_message, CamelStream *stream)
{
- g_hash_table_foreach (mime_message->recipients, _write_one_recipient_to_file, (gpointer)file);
+ g_hash_table_foreach (mime_message->recipients, _write_one_recipient_to_stream, (gpointer)stream);
}
static void
-_write_to_file (CamelDataWrapper *data_wrapper, FILE *file)
+_write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
{
CamelMimeMessage *mm = CAMEL_MIME_MESSAGE (data_wrapper);
-
- WHPTF (file, "From", mm->from);
- WHPTF (file, "Reply-To", mm->reply_to);
- _write_recipients_to_file (mm, file);
- WHPTF (file, "Date", mm->received_date);
- WHPTF (file, "Subject", mm->subject);
- CAMEL_DATA_WRAPPER_CLASS (parent_class)->write_to_file (data_wrapper, file);
+ CAMEL_LOG (FULL_DEBUG, "CamelMimeMessage::write_to_stream\n");
+ CAMEL_LOG (FULL_DEBUG, "Writing \"From\"\n");
+ WHPT (stream, "From", mm->from);
+ CAMEL_LOG (FULL_DEBUG, "Writing \"Reply-To\"\n");
+ WHPT (stream, "Reply-To", mm->reply_to);
+ CAMEL_LOG (FULL_DEBUG, "Writing recipients\n");
+ _write_recipients_to_stream (mm, stream);
+ CAMEL_LOG (FULL_DEBUG, "Writing \"Date\"\n");
+ WHPT (stream, "Date", mm->received_date);
+ CAMEL_LOG (FULL_DEBUG, "Writing \"Subject\"\n");
+ WHPT (stream, "Subject", mm->subject);
+ CAMEL_DATA_WRAPPER_CLASS (parent_class)->write_to_stream (data_wrapper, stream);
}
diff --git a/camel/camel-mime-part.c b/camel/camel-mime-part.c
index f4c02b7d7f..503e303c06 100644
--- a/camel/camel-mime-part.c
+++ b/camel/camel-mime-part.c
@@ -67,7 +67,7 @@ static void _set_header_lines (CamelMimePart *mime_part, GList *header_lines);
static GList *_get_header_lines (CamelMimePart *mime_part);
static CamelDataWrapper *_get_content_object(CamelMimePart *mime_part);
-static void _write_to_file(CamelDataWrapper *data_wrapper, FILE *file);
+static void _write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream);
static gboolean _parse_header_pair (CamelMimePart *mime_part, GString *header_name, GString *header_value);
@@ -117,7 +117,7 @@ camel_mime_part_class_init (CamelMimePartClass *camel_mime_part_class)
/* virtual method overload */
- camel_data_wrapper_class->write_to_file = _write_to_file;
+ camel_data_wrapper_class->write_to_stream = _write_to_stream;
}
static void
@@ -481,15 +481,15 @@ camel_mime_part_get_content_object(CamelMimePart *mime_part)
return CMP_CLASS(mime_part)->get_content_object (mime_part);
}
-#ifdef WHPTF
-#warning : WHPTF is already defined !!!!!!
+#ifdef WHPT
+#warning : WHPT is already defined !!!!!!
#endif
-#define WHPTF gmime_write_header_pair_to_file
+#define WHPT gmime_write_header_pair_to_stream
/* This is not used for the moment */
static void
-_write_content_to_file (CamelMimePart *mime_part, FILE *file)
+_write_content_to_stream (CamelMimePart *mime_part, CamelStream *stream)
{
guint buffer_size;
gchar *buffer;
@@ -498,16 +498,17 @@ _write_content_to_file (CamelMimePart *mime_part, FILE *file)
CamelDataWrapper *content = mime_part->content;
// buffer_size = camel_data_wrapper_size (content);
buffer = g_malloc (buffer_size);
- camel_data_wrapper_write_to_buffer (content, buffer);
+ camel_data_wrapper_write_to_stream (content, stream);
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);
- // fwrite (encoded_buffer, encoded_buffer_size, 1, file);
+ // camel_stream_write (stream, encoded_buffer, encoded_buffer_size);
// g_free (encoded_buffer);
} else
- fwrite (buffer, buffer_size, 1, file);
+ //fwrite (buffer, buffer_size, 1, file);
+ camel_stream_write (stream, buffer, buffer_size);
g_free (buffer);
}
@@ -516,19 +517,30 @@ _write_content_to_file (CamelMimePart *mime_part, FILE *file)
static void
-_write_to_file(CamelDataWrapper *data_wrapper, FILE *file)
+_write_to_stream (CamelDataWrapper *data_wrapper, CamelStream *stream)
{
CamelMimePart *mp = CAMEL_MIME_PART (data_wrapper);
- gmime_content_field_write_to_file(data_wrapper->content_type, file);
- gmime_content_field_write_to_file(mp->disposition, file);
- WHPTF (file, "Content-Transfer-Encoding", mp->encoding);
- WHPTF (file, "Content-Description", mp->description);
- WHPTF (file, "Content-MD5", mp->content_MD5);
- WHPTF (file, "Content-id", mp->content_id);
- write_header_with_glist_to_file (file, "Content-Language", mp->content_languages);
- write_header_table_to_file (file, mp->headers);
- fprintf(file,"\n");
- if (mp->content) camel_data_wrapper_write_to_file (mp->content, file);
+
+ CAMEL_LOG (FULL_DEBUG, "Entering CamelMimePart::write_to_stream\n");
+
+ CAMEL_LOG (FULL_DEBUG, "CamelMimePart::write_to_stream writing content-type\n");
+ gmime_content_field_write_to_stream(data_wrapper->content_type, 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);
+ 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");
+ WHPT (stream, "Content-MD5", mp->content_MD5);
+ CAMEL_LOG (FULL_DEBUG, "CamelMimePart::write_to_stream writing content-id\n");
+ WHPT (stream, "Content-id", mp->content_id);
+ CAMEL_LOG (FULL_DEBUG, "CamelMimePart::write_to_stream writing content-languages\n");
+ write_header_with_glist_to_stream (stream, "Content-Language", mp->content_languages);
+ CAMEL_LOG (FULL_DEBUG, "CamelMimePart::write_to_stream writing other headers\n");
+ write_header_table_to_stream (stream, mp->headers);
+ camel_stream_write_string(stream,"\n");
+ if (mp->content) camel_data_wrapper_write_to_stream (mp->content, stream);
}
diff --git a/camel/camel-mime-part.h b/camel/camel-mime-part.h
index 7cd724e44f..87ed6e7a4f 100644
--- a/camel/camel-mime-part.h
+++ b/camel/camel-mime-part.h
@@ -33,6 +33,7 @@ extern "C" {
#include <gtk/gtk.h>
#include "camel-data-wrapper.h"
+#include "camel-stream.h"
diff --git a/camel/camel-stream-fs.c b/camel/camel-stream-fs.c
index 0a42e5062f..c7335f9821 100644
--- a/camel/camel-stream-fs.c
+++ b/camel/camel-stream-fs.c
@@ -27,6 +27,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
+#include "camel-log.h"
static CamelStreamClass *parent_class=NULL;
@@ -95,21 +96,27 @@ camel_stream_fs_new_with_name (GString *name, CamelStreamFsMode mode)
int flags;
CamelStreamFs *stream_fs;
- if (!name) return NULL;
-
+ g_assert (name);
+ g_assert (name->str);
+ CAMEL_LOG (FULL_DEBUG, "Entering CamelStream::new_with_name, name=\"%s\", mode=%d\n", name->str, mode);
v = stat (name->str, &s);
-
+
if (mode & CAMEL_STREAM_FS_READ)
- if (mode & CAMEL_STREAM_FS_WRITE) flags = O_RDWR;
+ if (mode & CAMEL_STREAM_FS_WRITE) flags = O_RDWR | O_CREAT;
else flags = O_RDONLY;
else
- if (mode & CAMEL_STREAM_FS_WRITE) flags = O_WRONLY;
+ if (mode & CAMEL_STREAM_FS_WRITE) flags = O_WRONLY | O_CREAT;
else return NULL;
- if (mode & CAMEL_STREAM_FS_READ)
+ if ( (mode & CAMEL_STREAM_FS_READ) && !(mode & CAMEL_STREAM_FS_WRITE) )
if (v == -1) return NULL;
fd = open (name->str, flags);
+ if (fd==-1) {
+ CAMEL_LOG (FULL_DEBUG, "CamelStreamFs::new_with_name can not obtain fd for file \"%s\"\n", name->str);
+ CAMEL_LOG (FULL_DEBUG, " Full error text is : %s\n", strerror(errno));
+ return NULL;
+ }
stream_fs = CAMEL_STREAM_FS (camel_stream_fs_new_with_fd (fd));
stream_fs->name = name;
@@ -123,6 +130,7 @@ camel_stream_fs_new_with_fd (int fd)
{
CamelStreamFs *stream_fs;
+ CAMEL_LOG (FULL_DEBUG, "Entering CamelStream::new_with_fd fd=%d\n",fd);
stream_fs = gtk_type_new (camel_stream_fs_get_type ());
stream_fs->fd = fd;
return CAMEL_STREAM (stream_fs);
@@ -166,11 +174,19 @@ static gint
_write (CamelStream *stream, gchar *buffer, gint n)
{
int v;
-
+ g_assert (stream);
+ g_assert ((CAMEL_STREAM_FS (stream))->fd);
+ CAMEL_LOG (FULL_DEBUG, "CamelStreamFs:: entering write. n=%d\n", n);
do {
v = write ( (CAMEL_STREAM_FS (stream))->fd, buffer, n);
} while (v == -1 && errno == EINTR);
+#if HARD_LOG_LEVEL >= FULL_DEBUG
+ if (v==-1) {
+ perror("");
+ CAMEL_LOG (FULL_DEBUG, "CamelStreamFs::write could not write bytes in stream\n");
+ }
+#endif
return v;
}
diff --git a/camel/camel-stream.c b/camel/camel-stream.c
index c993556fa0..9f9e912bd8 100644
--- a/camel/camel-stream.c
+++ b/camel/camel-stream.c
@@ -192,3 +192,25 @@ camel_stream_close (CamelStream *stream)
{
CS_CLASS (stream)->close (stream);
}
+
+
+
+
+
+/***************** Utility functions ********************/
+
+void
+camel_stream_write_strings (CamelStream *stream, ... )
+{
+ va_list args;
+ char *string;
+
+ va_start(args, stream);
+ string = va_arg (args, char *);
+
+ while (string) {
+ camel_stream_write_string(stream, string);
+ string = va_arg (args, char *);
+ }
+ va_end (args);
+}
diff --git a/camel/camel-stream.h b/camel/camel-stream.h
index 925d5583a0..5fff22a24a 100644
--- a/camel/camel-stream.h
+++ b/camel/camel-stream.h
@@ -72,6 +72,11 @@ gint camel_stream_read (CamelStream *stream, gchar *buffer, gint n);
gint camel_stream_write (CamelStream *stream, gchar *buffer, gint n);
void camel_stream_close (CamelStream *stream);
+/* utility macros and funcs */
+#define camel_stream_write_string(stream, string) camel_stream_write ((stream), (string), strlen (string))
+
+void camel_stream_write_strings (CamelStream *stream, ... );
+
#ifdef __cplusplus
}
#endif /* __cplusplus */
diff --git a/camel/gmime-content-field.c b/camel/gmime-content-field.c
index 29c5fb61ec..87ceaf39f0 100644
--- a/camel/gmime-content-field.c
+++ b/camel/gmime-content-field.c
@@ -63,29 +63,39 @@ gmime_content_field_set_parameter(GMimeContentField *content_field, GString *att
static void
_print_parameter (gpointer name, gpointer value, gpointer user_data)
{
- FILE *file = (FILE *)user_data;
+ CamelStream *stream = (CamelStream *)user_data;
+
+ camel_stream_write_strings (stream,
+ "; \n ",
+ ((GString *)name)->str,
+ "=",
+ ((GString *)value)->str,
+ NULL);
- fprintf (file, "; \n %s=%s", ((GString *)name)->str, ((GString *)value)->str);
}
/**
- * gmime_content_field_write_to_file: write a mime content type to a file
+ * gmime_content_field_write_to: write a mime content type to a stream
* @content_field: content type object
- * @file: file to write the content type field
+ * @stream: the stream
*
*
**/
void
-gmime_content_field_write_to_file(GMimeContentField *content_field, FILE *file)
+gmime_content_field_write_to_stream (GMimeContentField *content_field, CamelStream *stream)
{
if (!content_field) return;
if ((content_field->type) && ((content_field->type)->str)) {
- fprintf (file, "Content-Type: %s", content_field->type->str);
+ //fprintf (file, "Content-Type: %s", content_field->type->str);
+ camel_stream_write_strings (stream, "Content-Type: ", content_field->type->str, NULL);
if ((content_field->subtype) && ((content_field->subtype)->str)) {
- fprintf (file, "/%s", content_field->subtype->str);
+ //fprintf (file, "/%s", content_field->subtype->str);
+ camel_stream_write_strings (stream, "/", content_field->type->str, NULL);
}
/* print all parameters */
- g_hash_table_foreach (content_field->parameters, _print_parameter, file);
- fprintf (file, "\n");
+ g_hash_table_foreach (content_field->parameters, _print_parameter, stream);
+ //fprintf (file, "\n");
+ camel_stream_write_string (stream, "\n");
}
}
+
diff --git a/camel/gmime-content-field.h b/camel/gmime-content-field.h
index 92328dcb2a..2711deabb9 100644
--- a/camel/gmime-content-field.h
+++ b/camel/gmime-content-field.h
@@ -33,6 +33,7 @@ extern "C" {
#include <glib.h>
#include <stdio.h>
+#include "camel-stream.h"
typedef struct {
@@ -44,7 +45,7 @@ typedef struct {
GMimeContentField *gmime_content_field_new (GString *type, GString *subtype);
void gmime_content_field_set_parameter(GMimeContentField *content_field, GString *attribute, GString *value);
-void gmime_content_field_write_to_file(GMimeContentField *content_field, FILE *file);
+void gmime_content_field_write_to_stream (GMimeContentField *content_field, CamelStream *stream);
#ifdef __cplusplus
diff --git a/camel/gmime-utils.c b/camel/gmime-utils.c
index ce605ade05..e2390b1499 100644
--- a/camel/gmime-utils.c
+++ b/camel/gmime-utils.c
@@ -31,20 +31,20 @@
void
gmime_write_header_pair_to_stream (CamelStream *stream, gchar* name, GString *value)
{
- g_assert(name);
- g_assert(value);
- g_assert(value->str);
GString *strtmp;
guint len;
+ g_assert(name);
+
+ if (!value || !(value->str)) return;
len = strlen (name) + strlen (value->str) +3;
/* 3 is for ": " and "\n" */
strtmp = g_string_sized_new (len);
sprintf(strtmp->str, "%s: %s\n", name, value->str);
camel_stream_write (stream, strtmp->str, len);
-
+ CAMEL_LOG (FULL_DEBUG, "gmime_write_header_pair_to_stream:\n writing %s\n", strtmp->str);
g_string_free (strtmp, FALSE);
}
@@ -80,7 +80,6 @@ write_header_with_glist_to_stream (CamelStream *stream, gchar *header_name, GLis
{
gboolean first;
- fprintf(file, "%s: ", header_name);
camel_stream_write (stream, header_name, strlen (header_name) );
camel_stream_write (stream, ": ", 2);
first = TRUE;