From 96496c1392cea9179b9bfbf2b6895e69a6dd13af Mon Sep 17 00:00:00 2001 From: Not Zed Date: Wed, 11 Jul 2001 07:28:40 +0000 Subject: Create the messageinfo itself, so we can properly set the size. 2001-07-11 Not Zed * camel-filter-driver.c (camel_filter_driver_filter_mbox): Create the messageinfo itself, so we can properly set the size. * camel-movemail.c (camel_movemail_solaris): Write out the from line between each message. 2001-07-10 Not Zed * providers/local/camel-local-summary.c (local_summary_add): Copy the size across from the source message info if supplied. * camel-stream-null.c: Added a 'written' member which keeps track of how much has been written to the stream. * camel-movemail.c (camel_movemail): If we have BROKEN_SPOOL defined, then use the solaris movemail to quote from lines that sendmail didn't. (camel_movemail_solaris): Compile this in if BROKEN_SPOOL defined. svn path=/trunk/; revision=10989 --- camel/ChangeLog | 21 +++++ camel/camel-filter-driver.c | 9 +- camel/camel-folder-summary.c | 7 +- camel/camel-movemail.c | 141 ++++++++++++++++++---------- camel/camel-stream-null.c | 4 +- camel/camel-stream-null.h | 2 + camel/providers/local/camel-local-summary.c | 1 + 7 files changed, 129 insertions(+), 56 deletions(-) (limited to 'camel') diff --git a/camel/ChangeLog b/camel/ChangeLog index e2bacc58f2..650030e65e 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,3 +1,24 @@ +2001-07-11 Not Zed + + * camel-filter-driver.c (camel_filter_driver_filter_mbox): Create + the messageinfo itself, so we can properly set the size. + + * camel-movemail.c (camel_movemail_solaris): Write out the from + line between each message. + +2001-07-10 Not Zed + + * providers/local/camel-local-summary.c (local_summary_add): Copy + the size across from the source message info if supplied. + + * camel-stream-null.c: Added a 'written' member which keeps track + of how much has been written to the stream. + + * camel-movemail.c (camel_movemail): If we have BROKEN_SPOOL + defined, then use the solaris movemail to quote from lines that + sendmail didn't. + (camel_movemail_solaris): Compile this in if BROKEN_SPOOL defined. + 2001-07-10 Jeffrey Stedfast * camel-mime-utils.c (html_meta_param_list_decode): New function diff --git a/camel/camel-filter-driver.c b/camel/camel-filter-driver.c index 71c1091b07..92cce8bab8 100644 --- a/camel/camel-filter-driver.c +++ b/camel/camel-filter-driver.c @@ -629,7 +629,9 @@ camel_filter_driver_filter_mbox (CamelFilterDriver *driver, const char *mbox, co int i = 0; struct stat st; int status; - + CamelMessageInfo *info; + off_t last = 0; + fd = open (mbox, O_RDONLY); if (fd == -1) { camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM, _("Unable to open spool folder")); @@ -665,7 +667,10 @@ camel_filter_driver_filter_mbox (CamelFilterDriver *driver, const char *mbox, co goto fail; } - status = camel_filter_driver_filter_message (driver, msg, NULL, NULL, NULL, source_url, + info = camel_message_info_new_from_header(((CamelMimePart *)msg)->headers); + info->size = camel_mime_parser_tell(mp) - last; + last = camel_mime_parser_tell(mp); + status = camel_filter_driver_filter_message (driver, msg, info, NULL, NULL, source_url, original_source_url ? original_source_url : source_url, ex); camel_object_unref (CAMEL_OBJECT (msg)); if (camel_exception_is_set (ex) || status == -1) { diff --git a/camel/camel-folder-summary.c b/camel/camel-folder-summary.c index 2b8fa3734f..2e2d66d062 100644 --- a/camel/camel-folder-summary.c +++ b/camel/camel-folder-summary.c @@ -870,6 +870,7 @@ CamelMessageInfo *camel_folder_summary_info_new_from_message(CamelFolderSummary { CamelMessageInfo *info; struct _CamelFolderSummaryPrivate *p = _PRIVATE(s); + CamelStreamNull *sn; info = ((CamelFolderSummaryClass *)(CAMEL_OBJECT_GET_CLASS(s)))->message_info_new_from_message(s, msg); @@ -883,8 +884,10 @@ CamelMessageInfo *camel_folder_summary_info_new_from_message(CamelFolderSummary } info->content = summary_build_content_info_message(s, info, (CamelMimePart *)msg); - /* FIXME: calculate the size as part of build_content_info_message */ - /* info->size = ... */ +#if 0 + sn = camel_stream_null_new(); + camel_data_wrapper_write_to_stream((CamelDataWrapper *)msg, sn); +#endif return info; } diff --git a/camel/camel-movemail.c b/camel/camel-movemail.c index bd00075485..fec8e5fc10 100644 --- a/camel/camel-movemail.c +++ b/camel/camel-movemail.c @@ -59,9 +59,15 @@ static void movemail_external (const char *source, const char *dest, CamelException *ex); #endif +#ifdef HAVE_BROKEN_SPOOL +static int camel_movemail_copy_filter(int fromfd, int tofd, off_t start, size_t bytes, CamelMimeFilter *filter); +static int camel_movemail_solaris (int oldsfd, int dfd, CamelException *ex); +#else /* these could probably be exposed as a utility? (but only mbox needs it) */ +static int camel_movemail_copy_file(int sfd, int dfd, CamelException *ex); +#endif + #if 0 -static int camel_movemail_copy_filter(int fromfd, int tofd, off_t start, size_t bytes, CamelMimeFilter *filter); static int camel_movemail_copy(int fromfd, int tofd, off_t start, size_t bytes); #endif @@ -86,8 +92,6 @@ camel_movemail(const char *source, const char *dest, CamelException *ex) int res = -1; int sfd, dfd; struct stat st; - int nread, nwrote; - char buf[BUFSIZ]; camel_exception_clear(ex); @@ -103,7 +107,7 @@ camel_movemail(const char *source, const char *dest, CamelException *ex) camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, _("Could not check mail file " "%s: %s"), source, - g_strerror (errno)); + strerror (errno)); } return -1; } @@ -116,7 +120,7 @@ camel_movemail(const char *source, const char *dest, CamelException *ex) if (sfd == -1) { camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, _("Could not open mail file %s: %s"), - source, g_strerror (errno)); + source, strerror (errno)); return -1; } @@ -125,7 +129,7 @@ camel_movemail(const char *source, const char *dest, CamelException *ex) camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, _("Could not open temporary mail " "file %s: %s"), dest, - g_strerror (errno)); + strerror (errno)); close (sfd); return -1; } @@ -138,49 +142,23 @@ camel_movemail(const char *source, const char *dest, CamelException *ex) return -1; } - while (1) { - int written = 0; - - nread = read (sfd, buf, sizeof (buf)); - if (nread == 0) - break; - else if (nread == -1) { - if (errno == EINTR) - continue; - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - _("Error reading mail file: %s"), - g_strerror (errno)); - break; - } - - while (nread) { - nwrote = write (dfd, buf + written, nread); - if (nwrote == -1) { - if (errno == EINTR) - continue; /* continues inner loop */ - camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - _("Error writing " - "mail temp file: %s"), - g_strerror (errno)); - break; - } - written += nwrote; - nread -= nwrote; - } - } +#ifdef HAVE_BROKEN_SPOOL + res = camel_movemail_solaris(sfd, dfd, ex); +#else + res = camel_movemail_copy_file(sfd, dfd, ex); +#endif /* If no errors occurred copying the data, and we successfully * close the destination file, then truncate the source file. */ - if (!camel_exception_is_set (ex)) { + if (res != -1) { if (close (dfd) == 0) { ftruncate (sfd, 0); - res = 0; } else { camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - _("Failed to store mail in " - "temp file %s: %s"), dest, - g_strerror (errno)); + _("Failed to store mail in temp file %s: %s"), dest, + strerror(errno)); + res = -1; } } else close (dfd); @@ -209,7 +187,7 @@ movemail_external (const char *source, const char *dest, CamelException *ex) sigprocmask (SIG_SETMASK, &omask, NULL); camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, _("Could not create pipe: %s"), - g_strerror (errno)); + strerror (errno)); return; } @@ -221,7 +199,7 @@ movemail_external (const char *source, const char *dest, CamelException *ex) sigprocmask (SIG_SETMASK, &omask, NULL); camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, _("Could not fork: %s"), - g_strerror (errno)); + strerror (errno)); return; case 0: @@ -265,6 +243,46 @@ movemail_external (const char *source, const char *dest, CamelException *ex) } #endif +#ifndef HAVE_BROKEN_SPOOL +static int +camel_movemail_copy_file(int sfd, int dfd, CamelException *ex) +{ + int nread, nwrote; + char buf[4096]; + + while (1) { + int written = 0; + + nread = read (sfd, buf, sizeof (buf)); + if (nread == 0) + break; + else if (nread == -1) { + if (errno == EINTR) + continue; + camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, + _("Error reading mail file: %s"), + strerror (errno)); + return -1; + } + + while (nread) { + nwrote = write (dfd, buf + written, nread); + if (nwrote == -1) { + if (errno == EINTR) + continue; /* continues inner loop */ + camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, + _("Error writing mail temp file: %s"), + strerror (errno)); + return -1; + } + written += nwrote; + nread -= nwrote; + } + } + + return 0; +} +#endif #if 0 static int @@ -318,7 +336,7 @@ camel_movemail_copy(int fromfd, int tofd, off_t start, size_t bytes) #define PRE_SIZE (32) -#if 0 +#ifdef HAVE_BROKEN_SPOOL static int camel_movemail_copy_filter(int fromfd, int tofd, off_t start, size_t bytes, CamelMimeFilter *filter) { @@ -349,6 +367,8 @@ camel_movemail_copy_filter(int fromfd, int tofd, off_t start, size_t bytes, Came if (towrite == -1) return -1; + printf("read %d unfiltered bytes\n", towrite); + /* check for 'end of file' */ if (towrite == 0) { d(printf("end of file?\n")); @@ -363,6 +383,8 @@ camel_movemail_copy_filter(int fromfd, int tofd, off_t start, size_t bytes, Came towrite = filterlen; } + printf("writing %d filtered bytes\n", towrite); + do { toread = write(tofd, filterbuffer, towrite); } while (toread == -1 && errno == EINTR); @@ -428,13 +450,24 @@ solaris_header_write(int fd, struct _header_raw *header) we must convert it to a real mbox format. Thankfully this is mostly pretty easy */ static int -camel_movemail_solaris (int sfd, int dfd, CamelException *ex) +camel_movemail_solaris (int oldsfd, int dfd, CamelException *ex) { CamelMimeParser *mp; char *buffer; int len; + int sfd; CamelMimeFilterFrom *ffrom; int ret = 1; + char *from = NULL; + + /* need to dup as the mime parser will close on finish */ + sfd = dup(oldsfd); + if (sfd == -1) { + camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, + _("Error copying mail temp file: %s"), + strerror (errno)); + return -1; + } mp = camel_mime_parser_new(); camel_mime_parser_scan_from(mp, TRUE); @@ -443,6 +476,8 @@ camel_movemail_solaris (int sfd, int dfd, CamelException *ex) ffrom = camel_mime_filter_from_new(); while (camel_mime_parser_step(mp, &buffer, &len) == HSCAN_FROM) { + g_assert(camel_mime_parser_from_line(mp)); + from = g_strdup(camel_mime_parser_from_line(mp)); if (camel_mime_parser_step(mp, &buffer, &len) != HSCAN_FROM_END) { const char *cl; int length; @@ -454,8 +489,12 @@ camel_movemail_solaris (int sfd, int dfd, CamelException *ex) start = camel_mime_parser_tell_start_from(mp); body = camel_mime_parser_tell(mp); + if (write(dfd, from, strlen(from)) != strlen(from)) + goto fail; + /* write out headers, but NOT content-length header */ - solaris_header_write(dfd, camel_mime_parser_headers_raw(mp)); + if (solaris_header_write(dfd, camel_mime_parser_headers_raw(mp)) == -1) + goto fail; cl = camel_mime_parser_header(mp, "content-length", NULL); if (cl == NULL) { @@ -480,6 +519,7 @@ camel_movemail_solaris (int sfd, int dfd, CamelException *ex) } else { g_error("Inalid parser state: %d", camel_mime_parser_state(mp)); } + g_free(from); } camel_object_unref((CamelObject *)mp); @@ -488,10 +528,11 @@ camel_movemail_solaris (int sfd, int dfd, CamelException *ex) return ret; fail: + g_free(from); + camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - _("Error copying " - "mail temp file: %s"), - g_strerror (errno)); + _("Error copying mail temp file: %s"), + strerror (errno)); camel_object_unref((CamelObject *)mp); @@ -499,5 +540,5 @@ fail: return -1; } -#endif +#endif /* HAVE_BROKEN_SPOOL */ diff --git a/camel/camel-stream-null.c b/camel/camel-stream-null.c index 8e9e107f0f..7e99a9c38d 100644 --- a/camel/camel-stream-null.c +++ b/camel/camel-stream-null.c @@ -36,11 +36,11 @@ static CamelObjectClass *parent_class = NULL; /* dummy implementations, for a NULL stream */ static ssize_t stream_read (CamelStream *stream, char *buffer, size_t n) { return 0; } -static ssize_t stream_write (CamelStream *stream, const char *buffer, size_t n) { return n; } +static ssize_t stream_write (CamelStream *stream, const char *buffer, size_t n) { ((CamelStreamNull *)stream)->written += n; return n; } static int stream_close (CamelStream *stream) { return 0; } static int stream_flush (CamelStream *stream) { return 0; } static gboolean stream_eos (CamelStream *stream) { return TRUE; } -static int stream_reset (CamelStream *stream) { return 0; } +static int stream_reset (CamelStream *stream) { ((CamelStreamNull *)stream)->written = 0; return 0; } static void camel_stream_null_class_init (CamelStreamClass *camel_stream_null_class) diff --git a/camel/camel-stream-null.h b/camel/camel-stream-null.h index db702b9ae2..20214e23a5 100644 --- a/camel/camel-stream-null.h +++ b/camel/camel-stream-null.h @@ -31,6 +31,8 @@ typedef struct _CamelStreamNullClass CamelStreamNullClass; struct _CamelStreamNull { CamelStream parent; + + size_t written; }; struct _CamelStreamNullClass { diff --git a/camel/providers/local/camel-local-summary.c b/camel/providers/local/camel-local-summary.c index 25cdf0d045..a1f1c1334b 100644 --- a/camel/providers/local/camel-local-summary.c +++ b/camel/providers/local/camel-local-summary.c @@ -393,6 +393,7 @@ local_summary_add(CamelLocalSummary *cls, CamelMimeMessage *msg, const CamelMess } mi->flags = mi->flags | (info->flags & 0xffff); + mi->size = info->size; } mi->flags &= ~(CAMEL_MESSAGE_FOLDER_NOXEV|CAMEL_MESSAGE_FOLDER_FLAGGED); xev = camel_local_summary_encode_x_evolution(cls, mi); -- cgit v1.2.3