sync with 0.8.3cvs3
authorPaul Mangan <paul@claws-mail.org>
Thu, 19 Sep 2002 17:36:44 +0000 (17:36 +0000)
committerPaul Mangan <paul@claws-mail.org>
Thu, 19 Sep 2002 17:36:44 +0000 (17:36 +0000)
ChangeLog
ChangeLog.claws
ChangeLog.jp
configure.in
src/rfc2015.c
src/utils.c
src/utils.h

index f30b3f5..db6eaf2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2002-09-19
+
+       * src/rfc2015.c: check_signature(): corrected error handling and
+         fixed memory leak.
+
+2002-09-19
+
+       * src/rfc2015.c: check_signature(): correctly remove the last empty
+         line, and canonicalize the file part before verifying (this should
+         fix incompatibility with Evolution or some other MUAs).
+       * src/utils.[ch]: copy_file_part(): new. It copies the specified
+         range of file stream to another file.
+
 2002-09-19
 
        * src/compose.c: compose_write_to_file(): force BASE64 encoding for
index ac1b888..df3915b 100644 (file)
@@ -1,3 +1,8 @@
+2002-09-19 [paul]      0.8.2claws60
+
+       * sync with 0.8.2cvs3
+               see ChangeLog 2002-09-19
+
 2002-09-19 [paul]      0.8.2claws59
 
        * src/prefs_folder_item.c
index 8734519..485cc4c 100644 (file)
@@ -1,3 +1,15 @@
+2002-09-19
+
+       * src/rfc2015.c: check_signature(): ¥¨¥é¡¼½èÍý¤È¥á¥â¥ê¥ê¡¼¥¯¤ò½¤Àµ¡£
+
+2002-09-19
+
+       * src/rfc2015.c: check_signature(): ¸¡¾ÚÁ°¤Ë¥Õ¥¡¥¤¥ë¥Ñ¡¼¥È¤ÎºÇ¸å¤Î
+         ¶õ¹Ô¤òÀµ¤·¤¯½üµî¤·¡¢Àµµ¬²½¤¹¤ë¤è¤¦¤Ë¤·¤¿(Evolution ¤½¤Î¾ MUA
+         ¤È¤ÎÈó¸ß´¹À­¤ò²ò¾Ã¤¹¤ë¤Ï¤º)¡£
+       * src/utils.[ch]: copy_file_part(): ¿·µ¬¡£»ØÄꤷ¤¿ÈϰϤΥե¡¥¤¥ë
+         ¥¹¥È¥ê¡¼¥à¤òÊ̤Υե¡¥¤¥ë¤Ë¥³¥Ô¡¼¤¹¤ë¡£
+
 2002-09-19
 
        * src/compose.c: compose_write_to_file(): 8-bit ¥Æ¥­¥¹¥È¤Î½ð̾»þ¤Ë
index 252c660..8963053 100644 (file)
@@ -10,7 +10,7 @@ MINOR_VERSION=8
 MICRO_VERSION=2
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws59
+EXTRA_VERSION=claws60
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
index 2f89a7d..527c64a 100644 (file)
@@ -278,6 +278,8 @@ static void check_signature (MimeInfo *mimeinfo, MimeInfo *partinfo, FILE *fp)
     GpgmeSigStat status = GPGME_SIG_STAT_NONE;
     GpgmegtkSigStatus statuswindow = NULL;
     const char *result = NULL;
+    gchar *tmp_file;
+    gint n_exclude_chars = 0;
 
     if (prefs_common.gpg_signature_popup)
        statuswindow = gpgmegtk_sig_status_create ();
@@ -288,12 +290,47 @@ static void check_signature (MimeInfo *mimeinfo, MimeInfo *partinfo, FILE *fp)
        goto leave;
     }
 
-    /* don't include the last character (LF). It does not belong to the
-     * signed text */
-    err = gpgme_data_new_from_filepart (&text, NULL, fp,
-                                       mimeinfo->children->fpos,
-                                       mimeinfo->children->size ?
-                                       (mimeinfo->children->size - 1) : 0 );
+    /* don't include the last empty line.
+       It does not belong to the signed text */
+    if (mimeinfo->children->size > 0) {
+       if (fseek(fp, mimeinfo->children->fpos + mimeinfo->children->size - 1,
+                 SEEK_SET) < 0) {
+           perror("fseek");
+           goto leave;
+       }
+       if (fgetc(fp) == '\n') {
+           n_exclude_chars++;
+           if (mimeinfo->children->size > 1) {
+               if (fseek(fp, mimeinfo->children->fpos + mimeinfo->children->size - 2,
+                         SEEK_SET) < 0) {
+                   perror("fseek");
+                   goto leave;
+               }
+               if (fgetc(fp) == '\r')
+                   n_exclude_chars++;
+           }
+       }
+    }
+
+    /* canonicalize the file part. */
+    tmp_file = get_tmp_file();
+    if (copy_file_part(fp, mimeinfo->children->fpos,
+                      mimeinfo->children->size - n_exclude_chars,
+                      tmp_file) < 0) {
+       g_free(tmp_file);
+       goto leave;
+    }
+    if (canonicalize_file_replace(tmp_file) < 0) {
+       unlink(tmp_file);
+       g_free(tmp_file);
+       goto leave;
+    }
+
+    err = gpgme_data_new_from_file(&text, tmp_file, 1);
+
+    unlink(tmp_file);
+    g_free(tmp_file);
+
     if (!err)
        err = gpgme_data_new_from_filepart (&sig, NULL, fp,
                                            partinfo->fpos, partinfo->size);
index 39b99fe..ae24967 100644 (file)
@@ -2104,6 +2104,64 @@ gint move_file(const gchar *src, const gchar *dest, gboolean overwrite)
        return 0;
 }
 
+gint copy_file_part(FILE *fp, off_t offset, size_t length, const gchar *dest)
+{
+       FILE *dest_fp;
+       gint n_read;
+       gint bytes_left, to_read;
+       gchar buf[BUFSIZ];
+       gboolean err = FALSE;
+
+       if (fseek(fp, offset, SEEK_SET) < 0) {
+               perror("fseek");
+               return -1;
+       }
+
+       if ((dest_fp = fopen(dest, "wb")) == NULL) {
+               FILE_OP_ERROR(dest, "fopen");
+               return -1;
+       }
+
+       if (change_file_mode_rw(dest_fp, dest) < 0) {
+               FILE_OP_ERROR(dest, "chmod");
+               g_warning("can't change file mode\n");
+       }
+
+       bytes_left = length;
+       to_read = MIN(bytes_left, sizeof(buf));
+
+       while ((n_read = fread(buf, sizeof(gchar), to_read, fp)) > 0) {
+               if (n_read < to_read && ferror(fp))
+                       break;
+               if (fwrite(buf, n_read, 1, dest_fp) < 1) {
+                       g_warning(_("writing to %s failed.\n"), dest);
+                       fclose(dest_fp);
+                       unlink(dest);
+                       return -1;
+               }
+               bytes_left -= n_read;
+               if (bytes_left == 0)
+                       break;
+               to_read = MIN(bytes_left, sizeof(buf));
+       }
+
+       if (ferror(fp)) {
+               perror("fread");
+               err = TRUE;
+       }
+       if (fclose(dest_fp) == EOF) {
+               FILE_OP_ERROR(dest, "fclose");
+               err = TRUE;
+       }
+
+       if (err) {
+               unlink(dest);
+               return -1;
+       }
+
+       return 0;
+}
+
 /* convert line endings into CRLF. If the last line doesn't end with
  * linebreak, add it.
  */
index 94b9d3d..fa7ee02 100644 (file)
@@ -336,6 +336,10 @@ gint copy_file                     (const gchar    *src,
 gint move_file                 (const gchar    *src,
                                 const gchar    *dest,
                                 gboolean        overwrite);
+gint copy_file_part            (FILE           *fp,
+                                off_t           offset,
+                                size_t          length,
+                                const gchar    *dest);
 gint canonicalize_file         (const gchar    *src,
                                 const gchar    *dest);
 gint canonicalize_file_replace (const gchar    *file);