2005-12-02 [paul] 1.9.100cvs55
[claws.git] / src / plugins / pgpmime / pgpmime.c
index 8241c8bf106a0fe9cb993db78bce88d722244693..2784e53bccd4a59788aab7e384915ff4c4b3e0b2 100644 (file)
@@ -394,13 +394,27 @@ gboolean pgpmime_sign(MimeInfo *mimeinfo, PrefsAccount *account)
        MimeInfo *msgcontent, *sigmultipart, *newinfo;
        gchar *textstr, *micalg;
        FILE *fp;
-       gchar *boundary, *sigcontent;
+       gchar *boundary = NULL;
+       gchar *sigcontent;
        gpgme_ctx_t ctx;
        gpgme_data_t gpgtext, gpgsig;
        size_t len;
        struct passphrase_cb_info_s info;
        gpgme_sign_result_t result = NULL;
+       gchar *test_msg;
+       
+       fp = my_tmpfile();
+       if (fp == NULL) {
+               perror("my_tmpfile");
+               return FALSE;
+       }
+       procmime_write_mimeinfo(mimeinfo, fp);
+       rewind(fp);
 
+       /* read temporary file into memory */
+       test_msg = file_read_stream_to_str(fp);
+       fclose(fp);
+       
        memset (&info, 0, sizeof info);
 
        /* remove content node from message */
@@ -411,7 +425,15 @@ gboolean pgpmime_sign(MimeInfo *mimeinfo, PrefsAccount *account)
        sigmultipart = procmime_mimeinfo_new();
        sigmultipart->type = MIMETYPE_MULTIPART;
        sigmultipart->subtype = g_strdup("signed");
-       boundary = generate_mime_boundary("Signature");
+       
+       do {
+               if (boundary)
+                       g_free(boundary);
+               boundary = generate_mime_boundary("Sig");
+       } while (strstr(test_msg, boundary) != NULL);
+       
+       g_free(test_msg);
+
        g_hash_table_insert(sigmultipart->typeparameters, g_strdup("boundary"),
                             g_strdup(boundary));
        g_hash_table_insert(sigmultipart->typeparameters, g_strdup("protocol"),
@@ -421,6 +443,10 @@ gboolean pgpmime_sign(MimeInfo *mimeinfo, PrefsAccount *account)
 
        /* write message content to temporary file */
        fp = my_tmpfile();
+       if (fp == NULL) {
+               perror("my_tmpfile");
+               return FALSE;
+       }
        procmime_write_mimeinfo(sigmultipart, fp);
        rewind(fp);
 
@@ -476,7 +502,12 @@ gboolean pgpmime_sign(MimeInfo *mimeinfo, PrefsAccount *account)
        newinfo = procmime_mimeinfo_new();
        newinfo->type = MIMETYPE_APPLICATION;
        newinfo->subtype = g_strdup("pgp-signature");
+       g_hash_table_insert(newinfo->typeparameters, g_strdup("name"),
+                            g_strdup("signature.asc"));
        newinfo->content = MIMECONTENT_MEM;
+       newinfo->disposition = DISPOSITIONTYPE_ATTACHMENT;
+       g_hash_table_insert(newinfo->dispositionparameters, g_strdup("filename"),
+                           g_strdup("signature.asc"));
        newinfo->data.mem = g_malloc(len + 1);
        g_memmove(newinfo->data.mem, sigcontent, len);
        newinfo->data.mem[len] = '\0';
@@ -543,6 +574,10 @@ gboolean pgpmime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data)
 
        /* write message content to temporary file */
        fp = my_tmpfile();
+       if (fp == NULL) {
+               perror("my_tmpfile");
+               return FALSE;
+       }
        procmime_write_mimeinfo(encmultipart, fp);
        rewind(fp);