2006-10-12 [colin] 2.5.5cvs4
authorColin Leroy <colin@colino.net>
Thu, 12 Oct 2006 17:20:05 +0000 (17:20 +0000)
committerColin Leroy <colin@colino.net>
Thu, 12 Oct 2006 17:20:05 +0000 (17:20 +0000)
* src/prefs_common.c
* src/prefs_common.h
* src/prefs_message.c
* src/procmime.c
Fix bug 1035, 'Incorrect handling
of flowed lines'. We now optionnaly
handle this format (preference is in
Message View/Text options section)

ChangeLog
PATCHSETS
configure.ac
src/prefs_common.c
src/prefs_common.h
src/prefs_message.c
src/procmime.c

index 7625a0a..4041e5c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2006-10-12 [colin]     2.5.5cvs4
+
+       * src/prefs_common.c
+       * src/prefs_common.h
+       * src/prefs_message.c
+       * src/procmime.c
+               Fix bug 1035, 'Incorrect handling 
+               of flowed lines'. We now optionnaly
+               handle this format (preference is in
+               Message View/Text options section)
+
 2006-10-12 [colin]     2.5.5cvs3
 
        * po/POTFILES.in
index fc2b884..07a5dd5 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.96.2.154 -r 1.96.2.155 src/textview.c;  ) > 2.5.3cvs32.patchset
 ( cvs diff -u -r 1.382.2.314 -r 1.382.2.315 src/compose.c;  ) > 2.5.5cvs2.patchset
 ( cvs diff -u -r 1.53.2.19 -r 1.53.2.20 po/POTFILES.in;  cvs diff -u -r 1.1.2.4 -r 1.1.2.5 src/plugins/pgpcore/pgp_viewer.c;  cvs diff -u -r 1.1.2.30 -r 1.1.2.31 src/plugins/pgpcore/sgpgme.c;  ) > 2.5.5cvs3.patchset
+( cvs diff -u -r 1.204.2.104 -r 1.204.2.105 src/prefs_common.c;  cvs diff -u -r 1.103.2.62 -r 1.103.2.63 src/prefs_common.h;  cvs diff -u -r 1.1.2.17 -r 1.1.2.18 src/prefs_message.c;  cvs diff -u -r 1.49.2.81 -r 1.49.2.82 src/procmime.c;  ) > 2.5.5cvs4.patchset
index 095faeb..adf3ec8 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=5
 MICRO_VERSION=5
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=3
+EXTRA_VERSION=4
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index 53abf3e..7a21720 100644 (file)
@@ -573,6 +573,8 @@ static PrefParam param[] = {
         NULL, NULL, NULL},
        {"scroll_half_page", "FALSE", &prefs_common.scroll_halfpage, P_BOOL,
         NULL, NULL, NULL},
+       {"respect_flowed_format", "FALSE", &prefs_common.respect_flowed_format, P_BOOL,
+        NULL, NULL, NULL},
 
        {"show_other_header", "FALSE", &prefs_common.show_other_header, P_BOOL,
         NULL, NULL, NULL},
index d46b2c1..5a1861b 100644 (file)
@@ -277,6 +277,7 @@ struct _PrefsCommon
        gboolean enable_smooth_scroll;
        gint scroll_step;
        gboolean scroll_halfpage;
+       gboolean respect_flowed_format;
 
        gboolean show_other_header;
        gboolean use_different_print_font;
index b9d1029..904a579 100644 (file)
@@ -59,6 +59,7 @@ typedef struct _MessagePage
        GtkWidget *chkbtn_halfpage;
 
        GtkWidget *chkbtn_attach_desc;
+       GtkWidget *chkbtn_respect_flowed_format;
 } MessagePage;
 
 static void disphdr_pane_toggled(GtkToggleButton *toggle_btn, GtkWidget *widget)
@@ -100,6 +101,7 @@ void prefs_message_create_widget(PrefsPage *_page, GtkWindow *window,
        GtkWidget *chkbtn_halfpage;
 
        GtkWidget *chkbtn_attach_desc;
+       GtkWidget *chkbtn_respect_flowed_format;
 
        vbox1 = gtk_vbox_new (FALSE, VSPACING);
        gtk_widget_show (vbox1);
@@ -225,8 +227,14 @@ void prefs_message_create_widget(PrefsPage *_page, GtkWindow *window,
 
        SET_TOGGLE_SENSITIVITY (chkbtn_smoothscroll, hbox_scr)
 
-       PACK_CHECK_BUTTON(vbox1, chkbtn_attach_desc,
+       vbox2 = gtk_vbox_new (FALSE, 0);
+       gtk_widget_show (vbox2);
+       PACK_CHECK_BUTTON(vbox2, chkbtn_attach_desc,
                          _("Show attachment descriptions (rather than names)"));
+       PACK_CHECK_BUTTON(vbox2, chkbtn_respect_flowed_format,
+                         _("Respect flowed format"));
+       gtk_box_pack_start (GTK_BOX (vbox1), vbox2,
+                         FALSE, TRUE, 0);
 
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chkbtn_disphdrpane),
                prefs_common.display_header_pane);
@@ -246,6 +254,8 @@ void prefs_message_create_widget(PrefsPage *_page, GtkWindow *window,
                prefs_common.scroll_halfpage);
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chkbtn_attach_desc),
                prefs_common.attach_desc);
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(chkbtn_respect_flowed_format),
+               prefs_common.respect_flowed_format);
        gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_linespc),
                prefs_common.line_space);
        gtk_spin_button_set_value(GTK_SPIN_BUTTON(spinbtn_scrollstep),
@@ -262,7 +272,8 @@ void prefs_message_create_widget(PrefsPage *_page, GtkWindow *window,
        prefs_message->spinbtn_scrollstep = spinbtn_scrollstep;
        prefs_message->chkbtn_halfpage = chkbtn_halfpage;
        prefs_message->chkbtn_attach_desc = chkbtn_attach_desc;
-       
+       prefs_message->chkbtn_respect_flowed_format = chkbtn_respect_flowed_format;
+
        prefs_message->page.widget = vbox1;
 }
 
@@ -286,6 +297,8 @@ void prefs_message_save(PrefsPage *_page)
                GTK_TOGGLE_BUTTON(page->chkbtn_halfpage));
        prefs_common.attach_desc = gtk_toggle_button_get_active(
                GTK_TOGGLE_BUTTON(page->chkbtn_attach_desc));
+       prefs_common.respect_flowed_format = gtk_toggle_button_get_active(
+               GTK_TOGGLE_BUTTON(page->chkbtn_respect_flowed_format));
        prefs_common.line_space = gtk_spin_button_get_value_as_int(
                GTK_SPIN_BUTTON(page->spinbtn_linespc));
        prefs_common.scroll_step = gtk_spin_button_get_value_as_int(
index 64fc558..4314ec7 100644 (file)
@@ -227,6 +227,24 @@ const gchar *procmime_mimeinfo_get_parameter(MimeInfo *mimeinfo, const gchar *na
        return value;
 }
 
+#define FLUSH_LASTLINE() {                                                     \
+       if (*lastline != '\0') {                                                \
+               gint llen = 0;                                                  \
+               strretchomp(lastline);                                          \
+               llen = strlen(lastline);                                        \
+               if (lastline[llen-1] == ' ' && strcmp(lastline,"-- ")) {        \
+                       /* this is flowed */                                    \
+                       if (delsp)                                              \
+                               lastline[llen-1] = '\0';                        \
+                       fputs(lastline, outfp);                                 \
+               } else {                                                        \
+                       fputs(lastline, outfp);                                 \
+                       fputs("\n", outfp);                                     \
+               }                                                               \
+       }                                                                       \
+       strcpy(lastline, buf);                                                  \
+}
+
 gboolean procmime_decode_content(MimeInfo *mimeinfo)
 {
        gchar buf[BUFFSIZE];
@@ -235,17 +253,34 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
        FILE *outfp, *infp;
        struct stat statbuf;
        gboolean tmp_file = FALSE;
-
+       gboolean flowed = FALSE;
+       gboolean delsp = FALSE; 
        EncodingType encoding = forced_encoding 
                                ? forced_encoding
                                : mimeinfo->encoding_type;
+       gchar lastline[BUFFSIZE];
+       memset(lastline, 0, BUFFSIZE);
                   
        g_return_val_if_fail(mimeinfo != NULL, FALSE);
 
-       if (encoding == ENC_UNKNOWN ||
-           encoding == ENC_BINARY ||
-           encoding == ENC_7BIT ||
-           encoding == ENC_8BIT)
+       if (prefs_common.respect_flowed_format &&
+           mimeinfo->type == MIMETYPE_TEXT && 
+           !strcasecmp(mimeinfo->subtype, "plain")) {
+               if (procmime_mimeinfo_get_parameter(mimeinfo, "format") != NULL &&
+                   !strcasecmp(procmime_mimeinfo_get_parameter(mimeinfo, "format"),"flowed"))
+                       flowed = TRUE;
+               if (flowed &&
+                   procmime_mimeinfo_get_parameter(mimeinfo, "delsp") != NULL &&
+                   !strcasecmp(procmime_mimeinfo_get_parameter(mimeinfo, "delsp"),"yes"))
+                       delsp = TRUE;
+       }
+       
+       if (!flowed && (
+            encoding == ENC_UNKNOWN ||
+            encoding == ENC_BINARY ||
+            encoding == ENC_7BIT ||
+            encoding == ENC_8BIT
+           ))
                return TRUE;
 
        infp = g_fopen(mimeinfo->data.filename, "rb");
@@ -268,8 +303,15 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
                while ((ftell(infp) < readend) && (fgets(buf, sizeof(buf), infp) != NULL)) {
                        gint len;
                        len = qp_decode_line(buf);
-                       fwrite(buf, 1, len, outfp);
+                       buf[len]='\0';
+                       if (!flowed) {
+                               fwrite(buf, 1, len, outfp);
+                       } else {
+                               FLUSH_LASTLINE();
+                       }
                }
+               if (flowed)
+                       FLUSH_LASTLINE();
        } else if (encoding == ENC_BASE64) {
                gchar outbuf[BUFFSIZE];
                gint len;
@@ -339,8 +381,14 @@ gboolean procmime_decode_content(MimeInfo *mimeinfo)
                }
        } else {
                while ((ftell(infp) < readend) && (fgets(buf, sizeof(buf), infp) != NULL)) {
-                       fputs(buf, outfp);
+                       if (!flowed) {
+                               fputs(buf, outfp);
+                       } else {
+                               FLUSH_LASTLINE();
+                       }
                }
+               if (flowed)
+                       FLUSH_LASTLINE();
        }
 
        fclose(outfp);