]> git.notmuchmail.org Git - notmuch/commitdiff
Normalize part counting and formatting in show_message_part function.
authorJameson Graef Rollins <jrollins@finestructure.net>
Mon, 23 May 2011 05:08:08 +0000 (22:08 -0700)
committerJameson Graef Rollins <jrollins@finestructure.net>
Mon, 23 May 2011 22:30:26 +0000 (15:30 -0700)
Simplify the function by moving part counting and formatting outside
of conditionals, thereby eliminating redundant code.  This also wraps
message part output handling with proper part formatting.

show-message.c

index c5556d81ba466fabe0a5d5bccc26ae347bc18cbb..4ccd449018850c417c5a324b3952e1767389aa4e 100644 (file)
@@ -28,47 +28,37 @@ show_message_part (GMimeObject *part,
                   const notmuch_show_format_t *format,
                   int first)
 {
+    *part_count += 1;
+
+    if (! (GMIME_IS_PART (part) || GMIME_IS_MULTIPART (part) || GMIME_IS_MESSAGE_PART (part))) {
+       fprintf (stderr, "Warning: Not displaying unknown mime part: %s.\n",
+                g_type_name (G_OBJECT_TYPE (part)));
+       return;
+    }
+
     if (!first)
        fputs (format->part_sep, stdout);
 
+    format->part (part, part_count);
+
     if (GMIME_IS_MULTIPART (part)) {
        GMimeMultipart *multipart = GMIME_MULTIPART (part);
        int i;
 
-       *part_count = *part_count + 1;
-       format->part (part, part_count);
-
        for (i = 0; i < g_mime_multipart_get_count (multipart); i++) {
            show_message_part (g_mime_multipart_get_part (multipart, i),
                               part_count, format, i == 0);
        }
 
-       if (format->part_end)
-           format->part_end (part);
-
-       return;
-    }
-
-    if (GMIME_IS_MESSAGE_PART (part)) {
+    } else if (GMIME_IS_MESSAGE_PART (part)) {
        GMimeMessage *mime_message;
 
        mime_message = g_mime_message_part_get_message (GMIME_MESSAGE_PART (part));
 
        show_message_part (g_mime_message_get_mime_part (mime_message),
                           part_count, format, first);
-
-       return;
-    }
-
-    if (! (GMIME_IS_PART (part))) {
-       fprintf (stderr, "Warning: Not displaying unknown mime part: %s.\n",
-                g_type_name (G_OBJECT_TYPE (part)));
-       return;
     }
 
-    *part_count = *part_count + 1;
-
-    format->part (part, part_count);
     if (format->part_end)
        format->part_end (part);
 }