sync with 0.8.1cvs13
authorPaul Mangan <paul@claws-mail.org>
Tue, 6 Aug 2002 09:34:13 +0000 (09:34 +0000)
committerPaul Mangan <paul@claws-mail.org>
Tue, 6 Aug 2002 09:34:13 +0000 (09:34 +0000)
13 files changed:
ChangeLog
ChangeLog.claws
ChangeLog.jp
configure.in
src/compose.c
src/mimeview.c
src/passphrase.c
src/rfc2015.c
src/select-keys.c
src/sigstatus.c
src/textview.c
src/utils.c
src/utils.h

index a499223..1715e8b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,8 +1,27 @@
+2002-08-06
+
+       * src/compose.c: compose_write_to_file():
+         canonicalize line endings before encrypting/signing (this will fix
+         interoperability with other MUAs).
+         Removed unnecessary strdup.
+         Don't encrypt/sign draft message.
+       * src/utils.[ch]:
+         canonicalize_file(), canonicalize_file_replace(): new.
+       * src/passphrase.c
+         src/select-keys.c: changed g_message() to debug_print() and
+         g_warning().
+       * src/mimeview.c: mimeview_check_signature(): removed unnecessary
+         MIME structure scanning.
+       * src/textview.c: textview_add_part(): show signature status in
+         TextView.
+       * src/rfc2015.c
+         src/sigstatus.c: modified translatable strings and some MIME
+         headers.
+
 2002-08-06
 
        * src/procmsg.c: procmsg_save_to_outbox(): don't forget to remove
          the temporary file when saving from queue.
-
 2002-08-05
 
        * src/compose.c
index 4af9e12..840aa50 100644 (file)
@@ -1,3 +1,8 @@
+2002-08-06 [paul]      0.8.1claws23
+
+       * sync with 0.8.1cvs13
+               see ChangeLog 2002-08-06
+
 2002-08-06 [paul]      0.8.1claws22
 
        * sync with 0.8.1cvs12
index f481707..9958562 100644 (file)
@@ -1,3 +1,22 @@
+2002-08-06
+
+       * src/compose.c: compose_write_to_file():
+         °Å¹æ²½/½ð̾¤ÎÁ°¤Ë¹ÔËö¤òÀµµ¬²½¤¹¤ë¤è¤¦¤Ë¤·¤¿(¾¤Î MUA ¤È¤ÎÁê¸ß±¿ÍÑ
+         À­¤¬½¤Àµ¤µ¤ì¤ë¤Ï¤º)¡£
+         ÉÔÍפʠstrdup ¤ò½üµî¡£
+         Áð¹Æ¥á¥Ã¥»¡¼¥¸¤ò°Å¹æ²½/½ð̾¤·¤Ê¤¤¤è¤¦¤Ë¤·¤¿¡£
+       * src/utils.[ch]:
+         canonicalize_file(), canonicalize_file_replace(): ¿·µ¬¡£
+       * src/passphrase.c
+         src/select-keys.c: g_message() ¤ò debug_print() ¤È g_warning()
+         ¤ËÊѹ¹¡£
+       * src/mimeview.c: mimeview_check_signature(): ÉÔÍפʠMIME ¹½Â¤¤Î
+         ¥¹¥­¥ã¥ó¤òºï½ü¡£
+       * src/textview.c: textview_add_part(): ½ð̾¤Î¥¹¥Æ¡¼¥¿¥¹¤ò TextView
+         ¤Ëɽ¼¨¡£
+       * src/rfc2015.c
+         src/sigstatus.c: ËÝÌõ²Äǽ¤Êʸ»úÎó¤È¤¤¤¯¤Ä¤«¤Î MIME ¥Ø¥Ã¥À¤ò½¤Àµ¡£
+
 2002-08-06
 
        * src/procmsg.c: procmsg_save_to_outbox(): Á÷¿®ÂÔ¤Á¤«¤éÊݸ¤¹¤ë
index d5a59fe..7708656 100644 (file)
@@ -8,7 +8,7 @@ MINOR_VERSION=8
 MICRO_VERSION=1
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws22
+EXTRA_VERSION=claws23
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
index f8bf967..675d213 100644 (file)
@@ -3102,7 +3102,8 @@ static gint compose_write_to_file(Compose *compose, const gchar *file,
        chars = gtk_editable_get_chars(GTK_EDITABLE(compose->text), 0, -1);
        len = strlen(chars);
        if (is_ascii_str(chars)) {
-               buf = g_strdup(chars);
+               buf = chars;
+               chars = NULL;
                out_codeset = CS_US_ASCII;
                encoding = ENC_7BIT;
        } else {
@@ -3136,7 +3137,8 @@ static gint compose_write_to_file(Compose *compose, const gchar *file,
                                unlink(file);
                                return -1;
                        } else {
-                               buf = g_strdup(chars);
+                               buf = chars;
+                               chars = NULL;
                        }
                }
        }
@@ -3200,6 +3202,16 @@ static gint compose_write_to_file(Compose *compose, const gchar *file,
        }
 
 #if USE_GPGME
+       if (is_draft)
+               return 0;
+
+       if (compose->use_signing || compose->use_encryption) {
+               if (canonicalize_file_replace(file) < 0) {
+                       unlink(file);
+                       return -1;
+               }
+       }
+
        if (compose->use_signing) {
                GSList *key_list;
 
index 954ece0..77e4aff 100644 (file)
@@ -1064,7 +1064,6 @@ static void mimeview_update_signature_info(MimeView *mimeview)
 static void mimeview_check_signature(MimeView *mimeview)
 {
        MimeInfo *mimeinfo;
-       gchar buf[BUFFSIZE];
        FILE *fp;
 
        g_return_if_fail (mimeview_is_signed(mimeview));
@@ -1082,19 +1081,13 @@ static void mimeview_check_signature(MimeView *mimeview)
                return;
        }
 
-       /* skip headers */
-       if (mimeinfo->mime_type == MIME_MULTIPART) {
-               if (fseek(fp, mimeinfo->fpos, SEEK_SET) < 0)
-               FILE_OP_ERROR(mimeview->file, "fseek");
-               while (fgets(buf, sizeof(buf), fp) != NULL)
-                       if (buf[0] == '\r' || buf[0] == '\n') break;
-       }
-
-       procmime_scan_multipart_message(mimeinfo, fp);
        rfc2015_check_signature(mimeinfo, fp);
        fclose(fp);
 
        mimeview_update_names(mimeview);
        mimeview_update_signature_info(mimeview);
+
+       textview_show_message(mimeview->messageview->textview, mimeinfo,
+                             mimeview->file);
 }
 #endif /* USE_GPGME */
index f88d1b9..55fe5d0 100644 (file)
@@ -44,7 +44,7 @@
 #include "passphrase.h"
 #include "prefs_common.h"
 #include "manage_window.h"
-
+#include "utils.h"
 
 static int grab_all = 0;
 
@@ -158,14 +158,14 @@ passphrase_mbox (const gchar *desc)
         if ( gdk_pointer_grab ( window->window, TRUE, 0,
                                 NULL, NULL, GDK_CURRENT_TIME)) {
             XUngrabServer ( GDK_DISPLAY() );
-            g_message ("OOPS: Could not grab mouse\n");
+            g_warning ("OOPS: Could not grab mouse\n");
             gtk_widget_destroy (window);
             return NULL;
         }
         if ( gdk_keyboard_grab( window->window, FALSE, GDK_CURRENT_TIME )) {
             gdk_pointer_ungrab (GDK_CURRENT_TIME);
             XUngrabServer ( GDK_DISPLAY() );
-            g_message ("OOPS: Could not grab keyboard\n");
+            g_warning ("OOPS: Could not grab keyboard\n");
             gtk_widget_destroy (window);
             return NULL;
         }
@@ -273,7 +273,7 @@ static int free_passphrase(gpointer _unused)
         munlock(last_pass, strlen(last_pass));
         g_free(last_pass);
         last_pass = NULL;
-        g_message("%% passphrase removed");
+        debug_print("%% passphrase removed");
     }
     
     return FALSE;
@@ -295,25 +295,25 @@ gpgmegtk_passphrase_cb (void *opaque, const char *desc, void **r_hd)
         return g_strdup(last_pass);
 
     gpgmegtk_set_passphrase_grab (prefs_common.passphrase_grab);
-    g_message ("%% requesting passphrase for `%s': ", desc );
+    debug_print ("%% requesting passphrase for `%s': ", desc);
     pass = passphrase_mbox (desc);
     gpgmegtk_free_passphrase();
     if (!pass) {
-        g_message ("%% cancel passphrase entry");
+        debug_print ("%% cancel passphrase entry");
         gpgme_cancel (ctx);
     }
     else {
         if (prefs_common.store_passphrase) {
             last_pass = g_strdup(pass);
             if (mlock(last_pass, strlen(last_pass)) == -1)
-                g_message("%% locking passphrase failed");
+                debug_print("%% locking passphrase failed");
 
             if (prefs_common.store_passphrase_timeout > 0) {
                 gtk_timeout_add(prefs_common.store_passphrase_timeout*60*1000,
                                 free_passphrase, NULL);
             }
         }
-        g_message ("%% sending passphrase");
+        debug_print ("%% sending passphrase");
     }
 
     return pass;
index 57409fe..07b6f6d 100644 (file)
@@ -174,7 +174,7 @@ sig_status_with_name (GpgmeSigStat status)
         result = _("Good signature from \"%s\"");
         break;
       case GPGME_SIG_STAT_BAD:
-        result = _("BAD signature  from \"%s\"");
+        result = _("BAD signature from \"%s\"");
         break;
       case GPGME_SIG_STAT_NOKEY:
         result = _("No public key to verify the signature");
@@ -245,7 +245,7 @@ sig_status_full (GpgmeCtx ctx)
                        strftime (ctime_str, sizeof (ctime_str), "%c", 
                                  ctime_val);
                        g_string_sprintfa (str,
-                                          _("Signature made %s\n"),
+                                          _("Signature made at %s\n"),
                                           ctime_str);
                }
                err = gpgme_get_sig_key (ctx, sig_idx, &key);
@@ -865,7 +865,7 @@ rfc2015_encrypt (const char *file, GSList *recp_list, gboolean ascii_armored)
 
     if (ascii_armored) {
         fprintf(fp, 
-            "Content-Type: text/plain; charset=us-ascii\r\n"
+            "Content-Type: text/plain; charset=US-ASCII\r\n"
             "Content-Transfer-Encoding: 7bit\r\n"  
             "\r\n");
     } else {
@@ -904,10 +904,9 @@ rfc2015_encrypt (const char *file, GSList *recp_list, gboolean ascii_armored)
     /* and the final boundary */
     if (!ascii_armored) {
         fprintf (fp,
-               "\r\n"
-               "--%s--\r\n"
-               "\r\n",
-            boundary);
+                "\r\n"
+                "--%s--\r\n",
+                boundary);
     }
     fflush (fp);
     if (ferror (fp)) {
@@ -1179,15 +1178,17 @@ rfc2015_sign (const char *file, GSList *key_list)
     header = NULL;
 
     if (!mime_version_seen) 
-        fputs ("MIME-Version: 1\r\n", fp);
+        fputs ("MIME-Version: 1.0\r\n", fp);
     fprintf (fp, "Content-Type: multipart/signed; "
              "protocol=\"application/pgp-signature\";\r\n");
     if (micalg)
-        fprintf (fp, " micalg=%s;", micalg );
-    fprintf (fp, " boundary=\"%s\"\r\n", boundary );
+        fprintf (fp, " micalg=\"%s\";", micalg);
+    fprintf (fp, " boundary=\"%s\"\r\n", boundary);
 
     /* Part 1: signed material */
-    fprintf (fp, "\r\n--%s\r\n", boundary);
+    fprintf (fp, "\r\n"
+                 "--%s\r\n",
+                 boundary);
     err = gpgme_data_rewind (plain);
     if (err) {
         debug_print ("gpgme_data_rewind on plain failed: %s\n",
@@ -1203,7 +1204,9 @@ rfc2015_sign (const char *file, GSList *key_list)
     }
 
     /* Part 2: signature */
-    fprintf (fp, "\r\n--%s\r\n", boundary);
+    fprintf (fp, "\r\n"
+                 "--%s\r\n",
+                 boundary);
     fputs ("Content-Type: application/pgp-signature\r\n"
           "\r\n", fp);
 
@@ -1223,7 +1226,9 @@ rfc2015_sign (const char *file, GSList *key_list)
     }
 
     /* Final boundary */
-    fprintf (fp, "\r\n--%s--\r\n\r\n", boundary);
+    fprintf (fp, "\r\n"
+                 "--%s--\r\n",
+                 boundary);
     fflush (fp);
     if (ferror (fp)) {
         FILE_OP_ERROR (file, "fwrite");
index 638c8ae..2e2ab58 100644 (file)
@@ -129,11 +129,11 @@ gpgmegtk_recipient_selection (GSList *recp_names)
 
     err = gpgme_recipients_new (&sk.rset);
     if (err) {
-        g_message ("** failed to allocate recipients set: %s",
+        g_warning ("failed to allocate recipients set: %s",
                    gpgme_strerror (err));
         return NULL;
     }
-        
+
     open_dialog (&sk);
 
     do {
@@ -228,8 +228,8 @@ fill_clist (struct select_keys_s *sk, const char *pattern)
 
     err = gpgme_op_keylist_start (ctx, pattern, 0);
     if (err) {
-        g_message ("** gpgme_op_keylist_start(%s) failed: %s",
-                   pattern, gpgme_strerror (err));
+        debug_print ("** gpgme_op_keylist_start(%s) failed: %s",
+                     pattern, gpgme_strerror (err));
         sk->select_ctx = NULL;
         return;
     }
@@ -243,16 +243,14 @@ fill_clist (struct select_keys_s *sk, const char *pattern)
     }
     debug_print ("%% %s:%d:  ready\n", __FILE__ ,__LINE__ );
     if (err != GPGME_EOF)
-        g_message ("** gpgme_op_keylist_next failed: %s",
-                   gpgme_strerror (err));
+        debug_print ("** gpgme_op_keylist_next failed: %s",
+                     gpgme_strerror (err));
     sk->select_ctx = NULL;
     gpgme_release (ctx);
     /*gtk_clist_thaw (select_keys.clist);*/
 }
 
 
-
-
 static void 
 create_dialog (struct select_keys_s *sk)
 {
@@ -400,7 +398,7 @@ select_btn_cb (GtkWidget *widget, gpointer data)
 
     g_return_if_fail (sk);
     if (!sk->clist->selection) {
-        g_message ("** nothing selected");
+        debug_print ("** nothing selected");
         return;
     }
     row = GPOINTER_TO_INT(sk->clist->selection->data);
@@ -411,7 +409,7 @@ select_btn_cb (GtkWidget *widget, gpointer data)
                                                    NULL, 0 );
         if ( gpgme_key_get_ulong_attr (key, GPGME_ATTR_VALIDITY, NULL, 0 )
              < GPGME_VALIDITY_FULL ) {
-            g_message ("** FIXME: we are faking the trust calculation");
+            debug_print ("** FIXME: we are faking the trust calculation");
         }
         if (!gpgme_recipients_add_name_with_validity (sk->rset, s,
                                                       GPGME_VALIDITY_FULL) ) {
@@ -522,5 +520,4 @@ sort_keys_email (GtkWidget *widget, gpointer data)
     sort_keys ((struct select_keys_s*)data, COL_EMAIL);
 }
 
-
 #endif /*USE_GPGME*/
index b2b4871..57d914f 100644 (file)
@@ -61,37 +61,37 @@ static void do_destroy(GpgmegtkSigStatus hd)
                        gtk_timeout_remove(hd->timeout_id);
                        hd->timeout_id_valid = 0;
                }
-               if (hd->destroy_pending)
+               if (hd->destroy_pending) 
                g_free(hd);
        }
 }
 
 static void okay_cb(GtkWidget *widget, gpointer data)
 {
-        GpgmegtkSigStatus hd = data;
+       GpgmegtkSigStatus hd = data;
 
-        hd->running = 0;
-        do_destroy(hd);
+       hd->running = 0;
+       do_destroy(hd);
 }
 
 static gint delete_event(GtkWidget *widget, GdkEventAny *event, gpointer data)
 {
-        GpgmegtkSigStatus hd = data;
+       GpgmegtkSigStatus hd = data;
 
-        hd->running = 0;
-        do_destroy(hd);
+       hd->running = 0;
+       do_destroy(hd);
 
        return TRUE;
 }
 
 static void key_pressed(GtkWidget *widget, GdkEventKey *event, gpointer data)
 {
-        GpgmegtkSigStatus hd = data;
+       GpgmegtkSigStatus hd = data;
 
-        if (event && event->keyval == GDK_Escape) {
-                hd->running = 0;
-                do_destroy(hd);
-        }
+       if (event && event->keyval == GDK_Escape) {
+               hd->running = 0;
+               do_destroy(hd);
+       }
 }
 
 GpgmegtkSigStatus gpgmegtk_sig_status_create(void)
@@ -102,21 +102,21 @@ GpgmegtkSigStatus gpgmegtk_sig_status_create(void)
        GtkWidget *label;
        GtkWidget *okay_btn;
        GtkWidget *okay_area;
-        GpgmegtkSigStatus hd;
+       GpgmegtkSigStatus hd;
 
-        hd = g_malloc0(sizeof *hd);
-        hd->running = 1;
+       hd = g_malloc0(sizeof *hd);
+       hd->running = 1;
 
        window = gtk_window_new(GTK_WINDOW_DIALOG);
-        hd->mainwindow = window;
+       hd->mainwindow = window;
        gtk_widget_set_usize(window, 400, -1);
        gtk_container_set_border_width(GTK_CONTAINER(window), 8);
        gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
-       gtk_window_set_policy(GTK_WINDOW(window), FALSE, FALSE, FALSE);
-        gtk_signal_connect(GTK_OBJECT(window), "delete_event",
-                           GTK_SIGNAL_FUNC(delete_event), hd);
-        gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
-                           GTK_SIGNAL_FUNC(key_pressed), hd);
+       gtk_window_set_policy(GTK_WINDOW(window), FALSE, TRUE, FALSE);
+       gtk_signal_connect(GTK_OBJECT(window), "delete_event",
+                          GTK_SIGNAL_FUNC(delete_event), hd);
+       gtk_signal_connect(GTK_OBJECT(window), "key_press_event",
+                          GTK_SIGNAL_FUNC(key_pressed), hd);
 
        vbox = gtk_vbox_new(FALSE, 8);
        gtk_container_add(GTK_CONTAINER(window), vbox);
@@ -127,7 +127,7 @@ GpgmegtkSigStatus gpgmegtk_sig_status_create(void)
        gtk_widget_show(hbox);
 
        label = gtk_label_new(_("Checking signature"));
-        hd->label = label;
+       hd->label = label;
        gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 8);
        gtk_widget_show(label);
 
@@ -135,109 +135,109 @@ GpgmegtkSigStatus gpgmegtk_sig_status_create(void)
                                NULL, NULL, NULL, NULL);
        gtk_box_pack_end(GTK_BOX(vbox), okay_area, FALSE, FALSE, 0);
        gtk_widget_grab_default(okay_btn);
-        gtk_signal_connect(GTK_OBJECT(okay_btn), "clicked",
-                           GTK_SIGNAL_FUNC(okay_cb), hd);
+       gtk_signal_connect(GTK_OBJECT(okay_btn), "clicked",
+                          GTK_SIGNAL_FUNC(okay_cb), hd);
 
        gtk_widget_show_all(window);
 
-        while (gtk_events_pending())
-            gtk_main_iteration();
+       while (gtk_events_pending())
+               gtk_main_iteration();
 
-        return hd;
+       return hd;
 }
 
 static gint timeout_cb(gpointer data)
 {
-    GpgmegtkSigStatus hd = data;
+       GpgmegtkSigStatus hd = data;
 
-    hd->running = 0;
-    hd->timeout_id_valid = 0;
-    do_destroy(hd);
+       hd->running = 0;
+       hd->timeout_id_valid = 0;
+       do_destroy(hd);
 
-    return FALSE;
+       return FALSE;
 }
 
 void gpgmegtk_sig_status_destroy(GpgmegtkSigStatus hd)
 {
-        if( hd ) {
-                hd->destroy_pending = 1;
-                if (hd->running && !hd->timeout_id_valid) {
-                    hd->timeout_id = gtk_timeout_add(MY_TIMEOUT,
-                                                     timeout_cb, hd);
-                    hd->timeout_id_valid = 1;
-                }
-                do_destroy(hd);
-        }
+       if (hd) {
+               hd->destroy_pending = 1;
+               if (hd->running && !hd->timeout_id_valid) {
+                       hd->timeout_id = gtk_timeout_add(MY_TIMEOUT,
+                                                        timeout_cb, hd);
+                       hd->timeout_id_valid = 1;
+               }
+               do_destroy(hd);
+       }
 }
 
 /* Fixme: remove status and get it from the context */
 void gpgmegtk_sig_status_update(GpgmegtkSigStatus hd, GpgmeCtx ctx)
 {
-    gint idx;
-    time_t created;
-    GpgmeSigStat status;
-    gchar *text = NULL;
+       gint idx;
+       time_t created;
+       GpgmeSigStat status;
+       gchar *text = NULL;
 
-    if (!hd || !hd->running || !ctx)
-        return;
+       if (!hd || !hd->running || !ctx)
+               return;
 
        for (idx = 0; gpgme_get_sig_status(ctx, idx, &status, &created);
             idx++) {
-        gchar *tmp;
-        const gchar *userid;
-        GpgmeKey key = NULL;
+               gchar *tmp;
+               const gchar *userid;
+               GpgmeKey key = NULL;
 
-        if ( !gpgme_get_sig_key (ctx, idx, &key) ) {
+               if (!gpgme_get_sig_key (ctx, idx, &key)) {
                        userid = gpgme_key_get_string_attr
                                (key, GPGME_ATTR_USERID, NULL, 0);
-        } else
-            userid = "[?]";
-
-        tmp = g_strdup_printf ( "%s%s%s from \"%s\"",
-                                text? text:"",
-                                text? "\n":"",
-                                gpgmegtk_sig_status_to_string(status),
-                                userid );
-        g_free (text);
-        text = tmp;
-        gpgme_key_unref (key);
-    }
-
-    gtk_label_set_text(GTK_LABEL(hd->label), text ); 
-    g_free (text);
-
-    while (gtk_events_pending())
-        gtk_main_iteration();
+               } else
+                       userid = "[?]";
+
+               tmp = g_strdup_printf(_("%s%s%s from \"%s\""),
+                                     text ? text : "",
+                                     text ? "\n" : "",
+                                     gpgmegtk_sig_status_to_string(status),
+                                     userid);
+               g_free (text);
+               text = tmp;
+               gpgme_key_unref (key);
+       }
+
+       gtk_label_set_text(GTK_LABEL(hd->label), text); 
+       g_free(text);
+
+       while (gtk_events_pending())
+               gtk_main_iteration();
 }
 
 const char *gpgmegtk_sig_status_to_string(GpgmeSigStat status)
 {
-        const char *result = "?";
-
-        switch ( status ) {
-            case GPGME_SIG_STAT_NONE:
-                result = _("Oops: Signature not verified");
-                break;
-            case GPGME_SIG_STAT_NOSIG:
-                result = _("No signature found");
-                break;
-            case GPGME_SIG_STAT_GOOD:
-                result = _("Good signature");
-                break;
-            case GPGME_SIG_STAT_BAD:
-                result = _("BAD signature");
-                break;
-            case GPGME_SIG_STAT_NOKEY:
-                result = _("No public key to verify the signature");
-                break;
-            case GPGME_SIG_STAT_ERROR:
-                result = _("Error verifying the signature");
-                break;
+       const char *result = "?";
+
+       switch (status) {
+       case GPGME_SIG_STAT_NONE:
+               result = _("Oops: Signature not verified");
+               break;
+       case GPGME_SIG_STAT_NOSIG:
+               result = _("No signature found");
+               break;
+       case GPGME_SIG_STAT_GOOD:
+               result = _("Good signature");
+               break;
+       case GPGME_SIG_STAT_BAD:
+               result = _("BAD signature");
+               break;
+       case GPGME_SIG_STAT_NOKEY:
+               result = _("No public key to verify the signature");
+               break;
+       case GPGME_SIG_STAT_ERROR:
+               result = _("Error verifying the signature");
+               break;
        default:
                break;
-        }
+       }
 
-        return result;
+       return result;
 }
 
 #endif /* USE_GPGME */
index a8d5348..ba03b07 100644 (file)
@@ -478,6 +478,12 @@ static void textview_add_part(TextView *textview, MimeInfo *mimeinfo, FILE *fp)
 
        gtk_stext_freeze(text);
 
+#if USE_GPGME
+       if (mimeinfo->sigstatus)
+               g_snprintf(buf, sizeof(buf), "\n[%s (%s)]\n",
+                          mimeinfo->content_type, mimeinfo->sigstatus);
+       else
+#endif
        if (mimeinfo->filename || mimeinfo->name)
                g_snprintf(buf, sizeof(buf), "\n[%s  %s (%d bytes)]\n",
                           mimeinfo->filename ? mimeinfo->filename :
index c9fc6bf..c072f74 100644 (file)
@@ -2076,6 +2076,102 @@ gint move_file(const gchar *src, const gchar *dest)
        return 0;
 }
 
+/* convert line endings into CRLF. If the last line doesn't end with
+ * linebreak, add it.
+ */
+gint canonicalize_file(const gchar *src, const gchar *dest)
+{
+       FILE *src_fp, *dest_fp;
+       gchar buf[BUFFSIZE];
+       gint len;
+       gboolean err = FALSE;
+       gboolean last_linebreak = FALSE;
+
+       if ((src_fp = fopen(src, "rb")) == NULL) {
+               FILE_OP_ERROR(src, "fopen");
+               return -1;
+       }
+
+       if ((dest_fp = fopen(dest, "wb")) == NULL) {
+               FILE_OP_ERROR(dest, "fopen");
+               fclose(src_fp);
+               return -1;
+       }
+
+       if (change_file_mode_rw(dest_fp, dest) < 0) {
+               FILE_OP_ERROR(dest, "chmod");
+               g_warning("can't change file mode\n");
+       }
+
+       while (fgets(buf, sizeof(buf), src_fp) != NULL) {
+               gint r = 0;
+
+               len = strlen(buf);
+               if (len == 0) break;
+               last_linebreak = FALSE;
+
+               if (buf[len - 1] != '\n') {
+                       last_linebreak = TRUE;
+                       r = fputs(buf, dest_fp);
+               } else if (len > 1 && buf[len - 1] == '\n' && buf[len - 2] == '\r') {
+                       r = fputs(buf, dest_fp);
+               } else {
+                       if (len > 1)
+                               r = fwrite(buf, len - 1, 1, dest_fp);
+                       if (r != EOF)
+                               r = fputs("\r\n", dest_fp);
+               }
+
+               if (r == EOF) {
+                       g_warning("writing to %s failed.\n", dest);
+                       fclose(dest_fp);
+                       fclose(src_fp);
+                       unlink(dest);
+                       return -1;
+               }
+       }
+
+       if (last_linebreak == TRUE) {
+               if (fputs("\r\n", dest_fp) == EOF)
+                       err = TRUE;
+       }
+
+       if (ferror(src_fp)) {
+               FILE_OP_ERROR(src, "fread");
+               err = TRUE;
+       }
+       fclose(src_fp);
+       if (fclose(dest_fp) == EOF) {
+               FILE_OP_ERROR(dest, "fclose");
+               err = TRUE;
+       }
+
+       if (err) {
+               unlink(dest);
+               return -1;
+       }
+
+       return 0;
+}
+
+gint canonicalize_file_replace(const gchar *file)
+{
+       gchar *tmp_file;
+
+       tmp_file = get_tmp_file();
+
+       if (canonicalize_file(file, tmp_file) < 0)
+               return -1;
+
+       if (rename(tmp_file, file) < 0) {
+               FILE_OP_ERROR(file, "rename");
+               unlink(tmp_file);
+               return -1;
+       }
+
+       return 0;
+}
+
 gint change_file_mode_rw(FILE *fp, const gchar *file)
 {
 #if HAVE_FCHMOD
index b99fd96..791e9ad 100644 (file)
@@ -333,6 +333,9 @@ gint copy_file                      (const gchar    *src,
                                 const gchar    *dest);
 gint move_file                 (const gchar    *src,
                                 const gchar    *dest);
+gint canonicalize_file         (const gchar    *src,
+                                const gchar    *dest);
+gint canonicalize_file_replace (const gchar    *file);
 gint change_file_mode_rw       (FILE           *fp,
                                 const gchar    *file);
 FILE *my_tmpfile               (void);