add check for '.' to QUOTE_IF_REQUIRED
[claws.git] / src / compose.c
index 126cdcd8ea10a45e3976c1e1fbcb65cd415e7489..7b106fa5358e1880448f51f1950d9f259a052f56 100644 (file)
@@ -2743,8 +2743,8 @@ gint compose_send(Compose *compose)
        }
 
        /* write to temporary file */
-       g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg%d",
-                  get_rc_dir(), G_DIR_SEPARATOR, (gint)compose);
+       g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
+                  get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
 
        if (prefs_common.linewrap_at_send)
                compose_wrap_line_all(compose);
@@ -2864,7 +2864,7 @@ static gint compose_redirect_write_headers_from_headerlist(Compose *compose,
        gchar *cc_hdr;
        gchar *to_hdr;
 
-       debug_print(_("Writing redirect header\n"));
+       debug_print("Writing redirect header\n");
 
        cc_hdr = prefs_common.trans_hdr ? _("Cc:") : "Cc:";
        to_hdr = prefs_common.trans_hdr ? _("To:") : "To:";
@@ -3042,43 +3042,69 @@ static gint compose_redirect_write_to_file(Compose *compose, const gchar *file)
 }
 
 
-#ifdef USE_GPGME
-/*
- * interfaces to rfc2015 to keep out the prefs stuff there.
+#if USE_GPGME
+/* interfaces to rfc2015 to keep out the prefs stuff there.
  * returns 0 on success and -1 on error. */
-static int compose_create_signers_list (Compose *compose, GSList **pkey_list)
+static gint compose_create_signers_list(Compose *compose, GSList **pkey_list)
 {
-       const char *keyid = NULL;
+       const gchar *key_id = NULL;
        GSList *key_list;
 
        switch (compose->account->sign_key) {
        case SIGN_KEY_DEFAULT:
                *pkey_list = NULL;
-               return 0;               /* nothing to do */
-
+               return 0;
        case SIGN_KEY_BY_FROM:
-               keyid = compose->account->address;
+               key_id = compose->account->address;
                break;
-
        case SIGN_KEY_CUSTOM:
-               keyid = compose->account->sign_key_id;
+               key_id = compose->account->sign_key_id;
                break;
-
        default:
-               g_assert_not_reached ();
+               break;
        }
 
-       key_list = rfc2015_create_signers_list(keyid);
+       key_list = rfc2015_create_signers_list(key_id);
 
        if (!key_list) {
-           alertpanel_error("Could not find any key associated with currently "
-                               "selected keyid `%s'!", keyid);
-           return -1;
+               alertpanel_error(_("Could not find any key associated with "
+                                  "currently selected key id `%s'."), key_id);
+               return -1;
        }
-       
+
        *pkey_list = key_list;
        return 0;
 }
+
+/* clearsign message body text */
+static gint compose_clearsign_text(Compose *compose, gchar **text)
+{
+       GSList *key_list;
+       gchar *tmp_file;
+
+       tmp_file = get_tmp_file();
+       if (str_write_to_file(*text, tmp_file) < 0) {
+               g_free(tmp_file);
+               return -1;
+       }
+
+       if (canonicalize_file_replace(tmp_file) < 0 ||
+           compose_create_signers_list(compose, &key_list) < 0 ||
+           rfc2015_clearsign(tmp_file, key_list) < 0) {
+               unlink(tmp_file);
+               g_free(tmp_file);
+               return -1;
+       }
+
+       g_free(*text);
+       *text = file_read_to_str(tmp_file);
+       unlink(tmp_file);
+       g_free(tmp_file);
+       if (*text == NULL)
+               return -1;
+
+       return 0;
+}
 #endif /* USE_GPGME */
 
 static gint compose_write_to_file(Compose *compose, const gchar *file,
@@ -3106,7 +3132,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 {
@@ -3140,12 +3167,25 @@ static gint compose_write_to_file(Compose *compose, const gchar *file,
                                unlink(file);
                                return -1;
                        } else {
-                               buf = g_strdup(chars);
+                               buf = chars;
+                               chars = NULL;
                        }
                }
        }
        g_free(chars);
 
+#if USE_GPGME
+       if (!is_draft && compose->use_signing && compose->account->clearsign) {
+               if (compose_clearsign_text(compose, &buf) < 0) {
+                       g_warning("clearsign failed\n");
+                       fclose(fp);
+                       unlink(file);
+                       g_free(buf);
+                       return -1;
+               }
+       }
+#endif
+
        /* write headers */
        if (compose_write_headers
                (compose, fp, out_codeset, encoding, is_draft) < 0) {
@@ -3204,18 +3244,29 @@ static gint compose_write_to_file(Compose *compose, const gchar *file,
        }
 
 #if USE_GPGME
-       if (compose->use_signing) {
+       if (is_draft)
+               return 0;
+
+       if ((compose->use_signing && !compose->account->clearsign) ||
+           compose->use_encryption) {
+               if (canonicalize_file_replace(file) < 0) {
+                       unlink(file);
+                       return -1;
+               }
+       }
+
+       if (compose->use_signing && !compose->account->clearsign) {
                GSList *key_list;
-               
-               if (compose_create_signers_list(compose, &key_list) == -1 ||
-                       rfc2015_sign(file, key_list) < 0) {
-                   
+
+               if (compose_create_signers_list(compose, &key_list) < 0 ||
+                   rfc2015_sign(file, key_list) < 0) {
                        unlink(file);
                        return -1;
                }
        }
        if (compose->use_encryption) {
-               if (rfc2015_encrypt(file, compose->to_list, compose->account->ascii_armored) < 0) {
+               if (rfc2015_encrypt(file, compose->to_list,
+                                   compose->account->ascii_armored) < 0) {
                        unlink(file);
                        return -1;
                }
@@ -3301,7 +3352,7 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
         static gboolean lock = FALSE;
        PrefsAccount *mailac = NULL, *newsac = NULL;
        
-       debug_print(_("queueing message...\n"));
+       debug_print("queueing message...\n");
        g_return_val_if_fail(compose->account != NULL, -1);
         g_return_val_if_fail(compose->orig_account != NULL, -1);
 
@@ -3584,7 +3635,8 @@ static void compose_write_attach(Compose *compose, FILE *fp)
 
 #define QUOTE_IF_REQUIRED(out, str)                    \
 {                                                      \
-       if (*str != '"' && strchr(str, ',')) {          \
+       if (*str != '"' && (strchr(str, ',')            \
+                       || strchr(str, '.'))) {         \
                gchar *__tmp;                           \
                gint len;                               \
                                                        \
@@ -3631,7 +3683,7 @@ static gint compose_write_headers_from_headerlist(Compose *compose,
                return 0;
        }
 
-       debug_print(_("Writing %s-header\n"), header);
+       debug_print("Writing %s-header\n", header);
 
        header_w_colon = g_strconcat(header, ":", NULL);
        trans_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
@@ -3891,7 +3943,7 @@ static gint compose_write_headers(Compose *compose, FILE *fp,
                case PRIORITY_LOWEST: fprintf(fp, "Importance: low\n"
                                                  "X-Priority: 5 (Lowest)\n");
                        break;
-               default: debug_print(_("compose: priority unknown : %d\n"),
+               default: debug_print("compose: priority unknown : %d\n",
                                     compose->priority);
        }
 
@@ -3959,7 +4011,7 @@ static void compose_generate_msgid(Compose *compose, gchar *buf, gint len)
                   lt->tm_min, lt->tm_sec,
                   (guint)random(), addr);
 
-       debug_print(_("generated Message-ID: %s\n"), buf);
+       debug_print("generated Message-ID: %s\n", buf);
 
        g_free(addr);
 }
@@ -4345,7 +4397,7 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
 
        g_return_val_if_fail(account != NULL, NULL);
 
-       debug_print(_("Creating compose window...\n"));
+       debug_print("Creating compose window...\n");
        compose = g_new0(Compose, 1);
 
        titles[COL_MIMETYPE] = _("MIME type");
@@ -4672,7 +4724,7 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
                        GtkWidget *menuitem;
 
                        if (!gtkpspell_set_sug_mode(gtkpspell, prefs_common.pspell_sugmode)) {
-                               debug_print(_("Pspell: could not set suggestion mode %s\n"),
+                               debug_print("Pspell: could not set suggestion mode %s\n",
                                    gtkpspellcheckers->error_message);
                                gtkpspell_checkers_reset_error();
                        }
@@ -5471,20 +5523,22 @@ static void attach_property_key_pressed(GtkWidget *widget, GdkEventKey *event,
 
 static void compose_exec_ext_editor(Compose *compose)
 {
-       gchar tmp[64];
+       gchar *tmp;
        pid_t pid;
        gint pipe_fds[2];
 
-       g_snprintf(tmp, sizeof(tmp), "%s%ctmpmsg.%08x",
-                  g_get_tmp_dir(), G_DIR_SEPARATOR, (gint)compose);
+       tmp = g_strdup_printf("%s%ctmpmsg.%08x", get_tmp_dir(),
+                             G_DIR_SEPARATOR, (gint)compose);
 
        if (pipe(pipe_fds) < 0) {
                perror("pipe");
+               g_free(tmp);
                return;
        }
 
        if ((pid = fork()) < 0) {
                perror("fork");
+               g_free(tmp);
                return;
        }
 
@@ -5529,6 +5583,8 @@ static void compose_exec_ext_editor(Compose *compose)
                close(pipe_fds[1]);
                _exit(0);
        }
+
+       g_free(tmp);
 }
 
 static gint compose_exec_ext_editor_real(const gchar *file)
@@ -5623,7 +5679,7 @@ static void compose_input_cb(gpointer data, gint source,
        Compose *compose = (Compose *)data;
        gint i = 0;
 
-       debug_print(_("Compose: input from monitoring process\n"));
+       debug_print("Compose: input from monitoring process\n");
 
        gdk_input_remove(compose->exteditor_tag);
 
@@ -6072,7 +6128,7 @@ static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
 
        lock = TRUE;
 
-       tmp = g_strdup_printf("%s%cdraft.%d", g_get_tmp_dir(),
+       tmp = g_strdup_printf("%s%cdraft.%08x", get_tmp_dir(),
                              G_DIR_SEPARATOR, (gint)compose);
 
        if (compose_write_to_file(compose, tmp, TRUE) < 0) {