Patch: Distinguish between "is multipart" and "has attachments"



I'm now going through my private changes to the Balsa to see if there is 
anything more I ought to submit, or that I have submitted without getting 
any response.

Here is one such update: It introduces the distinction between "is 
multipart" and "has attachments". The topic as been discussed at great 
length on the list, so I don't see any point in repeating why I think this 
is necessary.

-- 
Toralf Lund <toralf@kscanners.com>  +47 66 85 51 22
Kongsberg Scanners AS               +47 66 85 51 00 (switchboard)
http://www.kscanners.no/~toralf     +47 66 85 51 01 (fax)
Index: libbalsa/message.c
===================================================================
RCS file: /cvs/gnome/balsa/libbalsa/message.c,v
retrieving revision 1.68
diff -u -b -r1.68 message.c
--- libbalsa/message.c	2001/10/29 21:10:04	1.68
+++ libbalsa/message.c	2001/11/13 08:44:03
@@ -757,7 +757,6 @@
     }
 }
 
-
 #ifdef DEBUG
 static char *
 mime_content_type2str(int contenttype)
@@ -887,9 +886,8 @@
 }
 
 gboolean
-libbalsa_message_has_attachment(LibBalsaMessage * message)
+libbalsa_message_is_multipart(LibBalsaMessage * message)
 {
-    gboolean ret;
     HEADER *msg_header;
 
     g_return_val_if_fail(LIBBALSA_IS_MESSAGE(message), FALSE);
@@ -898,13 +896,32 @@
 
     msg_header = message->header;	
 
-    if (msg_header->content->type != TYPETEXT) {
-	ret = TRUE;
-    } else {
-	ret = g_strcasecmp("plain", msg_header->content->subtype) != 0;
+    if (msg_header->content->type == TYPEMULTIPART) {
+	return TRUE;
     }
+    
+    return FALSE;
+}
+
+gboolean
+libbalsa_message_has_attachment(LibBalsaMessage * message)
+{
+    HEADER *msg_header;
+    LibBalsaMessageBody *body;
+
+    g_return_val_if_fail(LIBBALSA_IS_MESSAGE(message), FALSE);
+    g_return_val_if_fail(message->mailbox, FALSE);
+    g_return_val_if_fail(CLIENT_CONTEXT(message->mailbox)->hdrs, FALSE);
+
+    msg_header = message->header;
 
-    return ret;
+    /* FIXME: This is wrong, but less so than earlier versions; a message
+              has attachments if main message or one of the parts has 
+	      Content-type: multipart/mixed AND members with
+	      Content-disposition: attachment. Unfortunately, part list may
+	      not be available at this stage. */
+    return (msg_header->content->type==TYPEMULTIPART &&
+	    g_strcasecmp("mixed", msg_header->content->subtype)==0);
 }
 
 gchar *
Index: libbalsa/message.h
===================================================================
RCS file: /cvs/gnome/balsa/libbalsa/message.h,v
retrieving revision 1.36
diff -u -b -r1.36 message.h
--- libbalsa/message.h	2001/11/12 09:44:57	1.36
+++ libbalsa/message.h	2001/11/13 08:44:03
@@ -212,6 +212,7 @@
 
 const gchar *libbalsa_message_pathname(LibBalsaMessage * message);
 const gchar *libbalsa_message_charset(LibBalsaMessage * message);
+gboolean libbalsa_message_is_multipart(LibBalsaMessage * message);
 gboolean libbalsa_message_has_attachment(LibBalsaMessage * message);
 
 GList *libbalsa_message_user_hdrs(LibBalsaMessage * message);
Index: src/main-window.c
===================================================================
RCS file: /cvs/gnome/balsa/src/main-window.c,v
retrieving revision 1.438
diff -u -b -r1.438 main-window.c
--- src/main-window.c	2001/11/04 21:50:32	1.438
+++ src/main-window.c	2001/11/13 08:44:07
@@ -1042,7 +1042,7 @@
     }
 
     /* Handle items which require multiple parts to the mail */
-    if (message && !libbalsa_message_has_attachment(message)) {
+    if (message && !libbalsa_message_is_multipart(message)) {
         gtk_widget_set_sensitive(message_menu[MENU_MESSAGE_NEXT_PART_POS].widget, FALSE);
         gtk_widget_set_sensitive(message_menu[MENU_MESSAGE_PREVIOUS_PART_POS].widget, FALSE);
     } else {


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