2005-03-04 [paul] 1.0.1cvs21
[claws.git] / src / compose.c
index 48727c112d9476c3805b8f87b18ca9f695e7f779..bc19e2a2a348d2380709d08c2356fa300235e488 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2004 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2005 Hiroyuki Yamamoto
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -1358,7 +1358,7 @@ Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
 
        gtk_widget_grab_focus(compose->header_last->entry);
 
-       filename = procmsg_get_message_file(msginfo);
+       filename = procmsg_get_message_file_path(msginfo);
        if (filename == NULL)
                return NULL;
 
@@ -1390,7 +1390,7 @@ Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
        ifactory = gtk_item_factory_from_widget(compose->popupmenu);
        menu_set_sensitive(ifactory, "/Add...", FALSE);
        menu_set_sensitive(ifactory, "/Remove", FALSE);
-       menu_set_sensitive(ifactory, "/Property...", FALSE);
+       menu_set_sensitive(ifactory, "/Properties...", FALSE);
 
        ifactory = gtk_item_factory_from_widget(compose->menubar);
        menu_set_sensitive(ifactory, "/Message/Save", FALSE);
@@ -1398,10 +1398,7 @@ Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo)
        menu_set_sensitive(ifactory, "/Message/Attach file", FALSE);
        menu_set_sensitive(ifactory, "/Message/Insert signature", FALSE);
        menu_set_sensitive(ifactory, "/Edit", FALSE);
-       menu_set_sensitive(ifactory, "/Options/Sign", FALSE);
-       menu_set_sensitive(ifactory, "/Options/Encrypt", FALSE);
-       menu_set_sensitive(ifactory, "/Options/Priority", FALSE);
-       menu_set_sensitive(ifactory, "/Options/Request Return Receipt", FALSE);
+       menu_set_sensitive(ifactory, "/Options", FALSE);
        menu_set_sensitive(ifactory, "/Tools/Show ruler", FALSE);
        menu_set_sensitive(ifactory, "/Tools/Actions", FALSE);
        
@@ -1612,6 +1609,7 @@ static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
        };
 
        FILE *fp;
+       gchar buf[BUFFSIZE];
 
        g_return_val_if_fail(msginfo != NULL, -1);
 
@@ -1620,13 +1618,16 @@ static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
        fclose(fp);
 
        if (hentry[H_REPLY_TO].body != NULL) {
-               conv_unmime_header_overwrite(hentry[H_REPLY_TO].body);
-               compose->replyto = hentry[H_REPLY_TO].body;
+               conv_unmime_header(buf, sizeof(buf), hentry[H_REPLY_TO].body,
+                                  NULL);
+               compose->replyto = g_strdup(buf);
+               g_free(hentry[H_REPLY_TO].body);
                hentry[H_REPLY_TO].body = NULL;
        }
        if (hentry[H_CC].body != NULL) {
-               conv_unmime_header_overwrite(hentry[H_CC].body);
-               compose->cc = hentry[H_CC].body;
+               conv_unmime_header(buf, sizeof(buf), hentry[H_CC].body, NULL);
+               compose->cc = g_strdup(buf);
+               g_free(hentry[H_CC].body);
                hentry[H_CC].body = NULL;
        }
        if (hentry[H_REFERENCES].body != NULL) {
@@ -1641,20 +1642,22 @@ static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
        }
        if (hentry[H_BCC].body != NULL) {
                if (compose->mode == COMPOSE_REEDIT) {
-                       conv_unmime_header_overwrite(hentry[H_BCC].body);
-                       compose->bcc = hentry[H_BCC].body;
-               } else
-                       g_free(hentry[H_BCC].body);
+                       conv_unmime_header
+                               (buf, sizeof(buf), hentry[H_BCC].body, NULL);
+                       compose->bcc = g_strdup(buf);
+               }
+               g_free(hentry[H_BCC].body);
                hentry[H_BCC].body = NULL;
        }
        if (hentry[H_NEWSGROUPS].body != NULL) {
-               conv_unmime_header_overwrite(hentry[H_NEWSGROUPS].body);
                compose->newsgroups = hentry[H_NEWSGROUPS].body;
                hentry[H_NEWSGROUPS].body = NULL;
        }
        if (hentry[H_FOLLOWUP_TO].body != NULL) {
-               conv_unmime_header_overwrite(hentry[H_FOLLOWUP_TO].body);
-               compose->followup_to = hentry[H_FOLLOWUP_TO].body;
+               conv_unmime_header
+                       (buf, sizeof(buf), hentry[H_FOLLOWUP_TO].body, NULL);
+               compose->followup_to = g_strdup(buf);
+               g_free(hentry[H_FOLLOWUP_TO].body);
                hentry[H_FOLLOWUP_TO].body = NULL;
        }
        if (hentry[H_LIST_POST].body != NULL) {
@@ -1690,13 +1693,17 @@ static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
                        compose->priority =  priority;
                }
  
-       if (compose->mode == COMPOSE_REEDIT && msginfo->inreplyto)
-               compose->inreplyto = g_strdup(msginfo->inreplyto);
-       else if (compose->mode != COMPOSE_REEDIT &&
-                msginfo->msgid && *msginfo->msgid) {
+       if (compose->mode == COMPOSE_REEDIT) {
+               if (msginfo->inreplyto && *msginfo->inreplyto)
+                       compose->inreplyto = g_strdup(msginfo->inreplyto);
+               return 0;
+       }
+
+       if (msginfo->msgid && *msginfo->msgid)
                compose->inreplyto = g_strdup(msginfo->msgid);
 
-               if (!compose->references) {
+       if (!compose->references) {
+               if (msginfo->msgid && *msginfo->msgid) {
                        if (msginfo->inreplyto && *msginfo->inreplyto)
                                compose->references =
                                        g_strdup_printf("<%s>\n\t<%s>",
@@ -1706,6 +1713,10 @@ static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
                                compose->references =
                                        g_strconcat("<", msginfo->msgid, ">",
                                                    NULL);
+               } else if (msginfo->inreplyto && *msginfo->inreplyto) {
+                       compose->references =
+                               g_strconcat("<", msginfo->inreplyto, ">",
+                                           NULL);
                }
        }
 
@@ -2761,13 +2772,21 @@ static void compose_wrap_line_all_full(Compose *compose, gboolean autowrap)
                                }
 
                                GET_CHAR(cur_pos, cb, clen);
-
-                               /* insert space if it's alphanumeric */
-                               if ((cur_pos != line_pos) &&
-                                   ((clen > 1) || isalnum((guchar)cb[0]))) {
-                                       gtk_stext_insert(text, NULL, NULL,
-                                                       NULL, " ", 1);
-                                       tlen++;
+                               /* insert space between the next line */
+                               if (cur_pos > 0) {
+                                       gint clen_prev;
+                                       gchar cb_prev[MB_LEN_MAX];
+
+                                       GET_CHAR(cur_pos - 1, cb_prev,
+                                                clen_prev);
+                                       if ((clen_prev != clen && clen > 1) ||
+                                           (clen == 1 &&
+                                            !isspace((guchar)cb[0]))) {
+                                               gtk_stext_insert
+                                                       (text, NULL, NULL,
+                                                        NULL, " ", 1);
+                                               tlen++;
+                                       }
                                }
 
                                /* and start over with current line */
@@ -3027,11 +3046,11 @@ static void compose_select_account(Compose *compose, PrefsAccount *account,
 
 #endif
 
-       if (account->default_sign)
+       if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
                menu_set_active(ifactory, "/Options/Sign", TRUE);
        else
                menu_set_active(ifactory, "/Options/Sign", FALSE);
-       if (account->default_encrypt)
+       if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
                menu_set_active(ifactory, "/Options/Encrypt", TRUE);
        else
                menu_set_active(ifactory, "/Options/Encrypt", FALSE);
@@ -3422,6 +3441,7 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
 
                if (action == COMPOSE_WRITE_FOR_SEND) {
                        buf = conv_codeset_strdup(chars, src_codeset, out_codeset);
+                       
                        if (!buf) {
                                AlertValue aval;
                                gchar *msg;
@@ -3450,6 +3470,13 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
        }
        g_free(chars);
 
+       if (encoding == ENC_8BIT || encoding == ENC_7BIT) {
+               if (!strncmp(buf, "From ", sizeof("From ")-1) ||
+                   strstr(buf, "\nFrom ") != NULL) {
+                       encoding = ENC_QUOTED_PRINTABLE;
+               }
+       }
+
        mimetext = procmime_mimeinfo_new();
        mimetext->content = MIMECONTENT_MEM;
        mimetext->data.mem = buf;
@@ -3457,6 +3484,13 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
        mimetext->subtype = g_strdup("plain");
        g_hash_table_insert(mimetext->typeparameters, g_strdup("charset"),
                            g_strdup(out_codeset));
+       /* protect trailing spaces when signing message */
+       if (action == COMPOSE_WRITE_FOR_SEND && compose->use_signing && 
+           privacy_system_can_sign(compose->privacy_system))
+               if (encoding == ENC_7BIT)
+                       encoding = ENC_QUOTED_PRINTABLE;
+               else if (encoding == ENC_8BIT)
+                       encoding = ENC_BASE64;
        if (encoding != ENC_UNKNOWN)
                procmime_encode_content(mimetext, encoding);
 
@@ -3487,6 +3521,8 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action)
                        return -1;
 
        procmime_write_mimeinfo(mimemsg, fp);
+       
+       procmime_mimeinfo_free_all(mimemsg);
 
        return 0;
 }
@@ -3818,6 +3854,13 @@ static void compose_add_attachments(Compose *compose, MimeInfo *parent)
                        mimepart->disposition = DISPOSITIONTYPE_ATTACHMENT;
                }
 
+               if (compose->use_signing) {
+                       if (ainfo->encoding == ENC_7BIT)
+                               ainfo->encoding = ENC_QUOTED_PRINTABLE;
+                       else if (ainfo->encoding == ENC_8BIT)
+                               ainfo->encoding = ENC_BASE64;
+               }
+               
                procmime_encode_content(mimepart, ainfo->encoding);
 
                g_node_append(parent->node, mimepart->node);
@@ -5007,7 +5050,11 @@ static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data)
 
        ifactory = gtk_item_factory_from_widget(compose->menubar);
        menu_set_sensitive(ifactory, "/Options/Sign", can_sign);
+       if (!can_sign)
+               menu_set_active(ifactory, "/Options/Sign", FALSE);
        menu_set_sensitive(ifactory, "/Options/Encrypt", can_encrypt);
+       if (!can_encrypt)
+               menu_set_active(ifactory, "/Options/Encrypt", FALSE);
 }
 
 static void compose_update_privacy_system_menu_item(Compose * compose)
@@ -5276,7 +5323,9 @@ static void compose_destroy(Compose *compose)
        prefs_common.compose_width = compose->scrolledwin->allocation.width;
        prefs_common.compose_height = compose->window->allocation.height;
 
-       gtk_widget_destroy(compose->paned);
+       if (!compose->paned->parent)
+               gtk_widget_destroy(compose->paned);
+       gtk_widget_destroy(compose->popupmenu);
 
        toolbar_destroy(compose->toolbar);
        g_free(compose->toolbar);
@@ -6111,7 +6160,7 @@ static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
        }
        fprintf(fp, "X-Sylpheed-Sign:%d\n", compose->use_signing);
        fprintf(fp, "X-Sylpheed-Encrypt:%d\n", compose->use_encryption);
-       fprintf(fp, "X-Sylpheed-Gnupg-Mode:%s\n", compose->privacy_system);
+       fprintf(fp, "X-Sylpheed-Privacy-System:%s\n", compose->privacy_system);
        fprintf(fp, "\n");
 
        if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE) < 0) {
@@ -6907,7 +6956,44 @@ static void compose_add_field_list( Compose *compose, GList *listAddress ) {
        }
 }
 
+void compose_reply_from_messageview(MessageView *msgview, GSList *msginfo_list, 
+                                   guint action)
+{
+       gchar *body;
+       GSList *new_msglist = NULL;
+       MsgInfo *tmp_msginfo = NULL;
+
+       g_return_if_fail(msgview != NULL);
+
+       g_return_if_fail(msginfo_list != NULL);
+
+       if (g_slist_length(msginfo_list) == 1) {
+               MimeInfo *mimeinfo = messageview_get_selected_mime_part(msgview);
+               MsgInfo *orig_msginfo = (MsgInfo *)msginfo_list->data;
+               
+               if (mimeinfo != NULL && mimeinfo->type == MIMETYPE_MESSAGE && 
+                   !g_strcasecmp(mimeinfo->subtype, "rfc822")) {
+                       
+                       tmp_msginfo = procmsg_msginfo_new_from_mimeinfo(
+                                               orig_msginfo, mimeinfo);
+                       if (tmp_msginfo != NULL) {
+                               new_msglist = g_slist_append(NULL, tmp_msginfo);
+                       } 
+               }
+       }
+
+       body = messageview_get_selection(msgview);
+
+       if (new_msglist) {
+               compose_reply_mode((ComposeMode)action, new_msglist, body);
+               procmsg_msginfo_free(tmp_msginfo);
+               g_slist_free(new_msglist);
+       } else
+               compose_reply_mode((ComposeMode)action, msginfo_list, body);
+
+       g_free(body);
+}
+
 /*
  * End of Source.
  */
-