balsa r7970 - in trunk: . libbalsa src



Author: PeterB
Date: Sun Sep 14 16:46:11 2008
New Revision: 7970
URL: http://svn.gnome.org/viewvc/balsa?rev=7970&view=rev

Log:
mbox fixes

Modified:
   trunk/ChangeLog
   trunk/libbalsa/body.c
   trunk/libbalsa/mailbox_mbox.c
   trunk/src/balsa-mime-widget-text.c
   trunk/src/balsa-print-object-text.c
   trunk/src/sendmsg-window.c

Modified: trunk/libbalsa/body.c
==============================================================================
--- trunk/libbalsa/body.c	(original)
+++ trunk/libbalsa/body.c	Sun Sep 14 16:46:11 2008
@@ -476,19 +476,6 @@
         default:
             break;
         }
-    } else if (body->mime_part) {
-        /* Not a GMimePart... */
-        GMimeObject *object = body->mime_part;
-        if (GMIME_IS_MESSAGE_PART(object))
-            object = GMIME_OBJECT(g_mime_message_part_get_message
-                                  ((GMimeMessagePart *) object));
-        else
-            g_object_ref(object);
-        stream = g_mime_stream_mem_new();
-        libbalsa_mailbox_lock_store(body->message->mailbox);
-        g_mime_object_write_to_stream(object, stream);
-        libbalsa_mailbox_unlock_store(body->message->mailbox);
-        g_object_unref(object);
     } else {
         g_set_error(err, LIBBALSA_MAILBOX_ERROR, LIBBALSA_MAILBOX_ACCESS_ERROR,
                     "Internal error in get_stream");

Modified: trunk/libbalsa/mailbox_mbox.c
==============================================================================
--- trunk/libbalsa/mailbox_mbox.c	(original)
+++ trunk/libbalsa/mailbox_mbox.c	Sun Sep 14 16:46:11 2008
@@ -46,6 +46,8 @@
 #include "mime-stream-shared.h"
 #include <glib/gi18n.h>
 
+#define DEBUG_SEEK TRUE
+
 struct message_info {
     LibBalsaMailboxLocalMessageInfo local_info;
     LibBalsaMessageFlag orig_flags;     /* Has only real flags */
@@ -252,6 +254,13 @@
     retval = g_mime_stream_seek(stream, offset, GMIME_STREAM_SEEK_SET) >= 0
         && g_mime_stream_read(stream, buffer, sizeof buffer) == sizeof buffer
         && strncmp("From ", buffer, 5) == 0;
+#if DEBUG_SEEK
+    if (!retval) {
+        buffer[4] = 0;
+        g_print("%s at %ld failed: saw \"%s\"\n", __func__, offset,
+                buffer);
+    }
+#endif
 
     g_mime_stream_seek(stream, offset, GMIME_STREAM_SEEK_SET);
 
@@ -548,6 +557,7 @@
                                      (gpointer) & msg_info->local_info.message);
 	msg_info->local_info.message = NULL;
     }
+    g_free(msg_info);
 }
 
 static void
@@ -559,7 +569,6 @@
         struct message_info *msg_info =
             g_ptr_array_index(msgno_2_msg_info, i);
         free_message_info(msg_info);
-        g_free(msg_info);
     }
     g_ptr_array_free(msgno_2_msg_info, TRUE);
 }
@@ -705,6 +714,10 @@
     }
 
     mbox->size = st.st_size;
+#if DEBUG_SEEK
+    g_print("%s %s set size from stat %d\n", __func__, mailbox->name,
+            mbox->size);
+#endif
     libbalsa_mailbox_set_mtime(mailbox, st.st_mtime);
     mbox->gmime_stream = gmime_stream;
 
@@ -975,6 +988,10 @@
 	/* First check--just cache the mtime and size. */
         libbalsa_mailbox_set_mtime(mailbox, st.st_mtime);
 	mbox->size = st.st_size;
+#if DEBUG_SEEK
+        g_print("%s %s set size from stat %d\n", __func__, mailbox->name,
+                mbox->size);
+#endif
 	return;
     }
     if (st.st_mtime == mtime && st.st_size == mbox->size)
@@ -988,6 +1005,10 @@
 								 path));
 	/* Cache the file size, so we don't check the next time. */
 	mbox->size = st.st_size;
+#if DEBUG_SEEK
+        g_print("%s %s set size from stat %d\n", __func__, mailbox->name,
+                mbox->size);
+#endif
 	return;
     }
 
@@ -1015,6 +1036,23 @@
     /* If Balsa appended a message, it was prefixed with "\nFrom ", so
      * we first check one byte beyond the end of the last message: */
     start = mbox->size + 1;
+#if DEBUG_SEEK
+    g_print("%s %s looking where to start parsing.\n",
+              __func__, mailbox->name);
+    if (!lbm_mbox_stream_seek_to_message(mbox_stream, start)) {
+        g_print(" did not find a message at offset %ld\n", start);
+        --start;
+        if (lbm_mbox_stream_seek_to_message(mbox_stream, start))
+            g_print(" found a message at offset %ld\n", start);
+        else
+            g_print(" did not find a message at offset %ld\n", start);
+    } else
+        g_print(" found a message at offset %ld\n", start);
+#else
+    if (!lbm_mbox_stream_seek_to_message(mbox_stream, start))
+        /* Sometimes we seem to be off by 1: */
+        --start;
+#endif
 
     while ((msgno = mbox->msgno_2_msg_info->len) > 0) {
 	off_t offset;
@@ -1025,6 +1063,9 @@
 	     * the first new message--start parsing here. */
             break;
 
+#if DEBUG_SEEK
+        g_print(" backing up over message %d\n", msgno);
+#endif
 	/* Back up over this message and try again. */
         msg_info = message_info_from_msgno(mbox, msgno);
         start = msg_info->start;
@@ -1056,6 +1097,10 @@
 #endif
     parse_mailbox(mbox);
     mbox->size = g_mime_stream_tell(mbox_stream);
+#if DEBUG_SEEK
+    g_print("%s %s set size from tell %d\n", __func__, mailbox->name,
+            mbox->size);
+#endif
     libbalsa_mime_stream_shared_unlock(mbox_stream);
     mbox_unlock(mailbox, mbox_stream);
     libbalsa_mailbox_local_load_messages(mailbox, msgno);
@@ -1549,6 +1594,10 @@
         g_warning("mbox_sync: message not in expected position.\n");
     else if (g_mime_stream_write_to_stream(temp_stream, mbox_stream) != -1) {
         mbox->size = g_mime_stream_tell(mbox_stream);
+#if DEBUG_SEEK
+        g_print("%s %s set size from tell %d\n", __func__, mailbox->name,
+                mbox->size);
+#endif
         if (ftruncate(GMIME_STREAM_FS(mbox_stream)->fd, mbox->size) == 0)
             save_failed = FALSE;
     }

Modified: trunk/src/balsa-mime-widget-text.c
==============================================================================
--- trunk/src/balsa-mime-widget-text.c	(original)
+++ trunk/src/balsa-mime-widget-text.c	Sun Sep 14 16:46:11 2008
@@ -124,7 +124,7 @@
 {
     LibBalsaHTMLType html_type;
     gchar *ptr = NULL;
-    size_t alloced;
+    ssize_t alloced;
     BalsaMimeWidget *mw;
     GtkTextBuffer *buffer;
 #if USE_GREGEX
@@ -143,7 +143,7 @@
 
     is_text_plain = !g_ascii_strcasecmp(content_type, "text/plain");
     alloced = libbalsa_message_body_get_content(mime_body, &ptr, &err);
-    if (!ptr) {
+    if (alloced < 0) {
         balsa_information(LIBBALSA_INFORMATION_ERROR,
                           _("Could not save a text part: %s"),
                           err ? err->message : "Unknown error");

Modified: trunk/src/balsa-print-object-text.c
==============================================================================
--- trunk/src/balsa-print-object-text.c	(original)
+++ trunk/src/balsa-print-object-text.c	Sun Sep 14 16:46:11 2008
@@ -452,7 +452,7 @@
     PangoTabArray *tabs;
     GString *desc_buf;
     gdouble c_max_height;
-    LibBalsaAddress * addr;
+    LibBalsaAddress * addr = NULL;
     gchar *textbuf;
 
     /* check if we can create an address from the body and fall back to default if 
@@ -461,7 +461,8 @@
 	textbuf = g_strdup(body->buffer);
     else
 	libbalsa_message_body_get_content(body, &textbuf, NULL);
-    addr = libbalsa_address_new_from_vcard(textbuf, body->charset);
+    if (textbuf)
+        addr = libbalsa_address_new_from_vcard(textbuf, body->charset);
     if (!addr) {
 	g_free(textbuf);
 	return balsa_print_object_text(list, context, body, psetup);

Modified: trunk/src/sendmsg-window.c
==============================================================================
--- trunk/src/sendmsg-window.c	(original)
+++ trunk/src/sendmsg-window.c	Sun Sep 14 16:46:11 2008
@@ -3873,6 +3873,9 @@
 
     body = quote_body(bsmsg, headers, message_id, references,
                       root, qtype);
+
+    g_return_if_fail(body != NULL);
+
     if(body->len && body->str[body->len] != '\n')
         g_string_append_c(body, '\n');
     libbalsa_insert_with_url(buffer, body->str, NULL, NULL, NULL);
@@ -4723,7 +4726,9 @@
 static void
 bsm_finish_setup(BalsaSendmsg *bsmsg, LibBalsaMessageBody *part)
 {
-    g_return_if_fail(part->message);
+    g_return_if_fail(part != NULL);
+    g_return_if_fail(part->message != NULL);
+
     if (part->message->mailbox &&
         !bsmsg->parent_message && !bsmsg->draft_message)
         libbalsa_mailbox_close(part->message->mailbox, FALSE);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]