bounce mails
authorHoà Viêt Dinh <dinh.viet.hoa@free.fr>
Wed, 14 Nov 2001 07:37:32 +0000 (07:37 +0000)
committerHoà Viêt Dinh <dinh.viet.hoa@free.fr>
Wed, 14 Nov 2001 07:37:32 +0000 (07:37 +0000)
ChangeLog.claws
configure.in
src/compose.c
src/compose.h
src/mainwindow.c
src/summaryview.c

index 85cbb89..42df8f3 100644 (file)
@@ -1,6 +1,12 @@
+2001-11-14 [hoa] 0.6.5claws12
+
+       * src/compose.[ch]
+       * src/mainwindow.c
+       * src/summaryview.c
+               add "bounce mail" option
+
 2001-11-13 [christoph] 0.6.5claws11
 
-       * src/compose.c
                Cleanup a mess i add before commiting
 
 2001-11-13 [hoa]       0.6.5claws10
index 0ca29c9..c5032b7 100644 (file)
@@ -8,7 +8,7 @@ MINOR_VERSION=6
 MICRO_VERSION=5
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws11
+EXTRA_VERSION=claws12
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl
index d37c050..db8b551 100644 (file)
@@ -480,6 +480,58 @@ Compose * compose_new(PrefsAccount *account)
        return compose_generic_new(account, NULL, NULL);
 }
 
+Compose * compose_bounce(PrefsAccount *account, MsgInfo *msginfo)
+{
+       Compose * c;
+       gchar * filename;
+       GtkItemFactory *ifactory;
+       
+       c = compose_generic_new(account, NULL, NULL);
+
+       filename = procmsg_get_message_file(msginfo);
+       if (filename == NULL)
+               return NULL;
+
+       c->bounce_filename = filename;
+
+       if (msginfo->subject)
+               gtk_entry_set_text(GTK_ENTRY(c->subject_entry),
+                                  msginfo->subject);
+       gtk_editable_set_editable(GTK_EDITABLE(c->subject_entry), FALSE);
+
+       compose_quote_fmt(c, msginfo, "%M", NULL);
+       gtk_editable_set_editable(GTK_EDITABLE(c->text), FALSE);
+
+       ifactory = gtk_item_factory_from_widget(c->popupmenu);
+       menu_set_sensitive(ifactory, "/Add...", FALSE);
+       menu_set_sensitive(ifactory, "/Remove", FALSE);
+       menu_set_sensitive(ifactory, "/Property...", FALSE);
+
+       ifactory = gtk_item_factory_from_widget(c->menubar);
+       menu_set_sensitive(ifactory, "/File/Insert file", FALSE);
+       menu_set_sensitive(ifactory, "/File/Attach file", FALSE);
+       menu_set_sensitive(ifactory, "/File/Insert signature", FALSE);
+       menu_set_sensitive(ifactory, "/Edit/Paste", FALSE);
+       menu_set_sensitive(ifactory, "/Edit/Wrap current paragraph", FALSE);
+       menu_set_sensitive(ifactory, "/Edit/Wrap all long lines", FALSE);
+       menu_set_sensitive(ifactory, "/Edit/Edit with external editor", FALSE);
+       menu_set_sensitive(ifactory, "/Message/Attach", FALSE);
+#if USE_GPGME
+       menu_set_sensitive(ifactory, "/Message/Sign", FALSE);
+       menu_set_sensitive(ifactory, "/Message/Encrypt", FALSE);
+#endif
+       menu_set_sensitive(ifactory, "/Message/Request Return Receipt", FALSE);
+       menu_set_sensitive(ifactory, "/Tool/Template", FALSE);
+       
+       gtk_widget_set_sensitive(c->insert_btn, FALSE);
+       gtk_widget_set_sensitive(c->attach_btn, FALSE);
+       gtk_widget_set_sensitive(c->sig_btn, FALSE);
+       gtk_widget_set_sensitive(c->exteditor_btn, FALSE);
+       gtk_widget_set_sensitive(c->linewrap_btn, FALSE);
+
+       return c;
+}
+
 Compose * compose_new_with_recipient(PrefsAccount *account, const gchar *to)
 {
        return compose_generic_new(account, to, NULL);
@@ -2606,6 +2658,144 @@ static gboolean compose_use_attach(Compose *compose) {
     return(gtk_clist_get_row_data(GTK_CLIST(compose->attach_clist), 0) != NULL);
 }
 
+
+
+
+
+static gint compose_bounce_write_headers_from_headerlist(Compose *compose, 
+                                                        FILE *fp)
+{
+       gchar buf[BUFFSIZE];
+       gchar *str;
+       gboolean first_address;
+       GSList *list;
+       compose_headerentry *headerentry;
+       gchar * headerentryname;
+       gchar * header_w_colon;
+       gchar * cc_hdr;
+       gchar * to_hdr;
+
+       debug_print(_("Writing bounce header\n"));
+
+       header_w_colon = g_strconcat("To:", NULL);
+       to_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
+       header_w_colon = g_strconcat("Cc:", NULL);
+       cc_hdr = (prefs_common.trans_hdr ? gettext(header_w_colon) : header_w_colon);
+       
+       first_address = TRUE;
+       for(list = compose->header_list; list; list = list->next) {
+               headerentry = ((compose_headerentry *)list->data);
+               headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
+
+               if(g_strcasecmp(headerentryname, cc_hdr) == 0 
+                  || g_strcasecmp(headerentryname, to_hdr) == 0) {
+                       str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
+                       Xstrdup_a(str, str, return -1);
+                       g_strstrip(str);
+                       if(str[0] != '\0') {
+                               compose_convert_header
+                                       (buf, sizeof(buf), str,
+                                       strlen("Resent-To") + 2);
+                               if(first_address) {
+                                       fprintf(fp, "Resent-To: ");
+                                       first_address = FALSE;
+                               } else {
+                                       fprintf(fp, ",");
+                               }
+                               fprintf(fp, "%s", buf);
+                       }
+               }
+       }
+       //      if(!first_address) {
+       fprintf(fp, "\n");
+               //      }
+
+       return(0);
+}
+
+
+static gint compose_bounce_write_headers(Compose *compose, FILE *fp)
+{
+       gchar buf[BUFFSIZE];
+       gchar *str;
+       /* struct utsname utsbuf; */
+
+       g_return_val_if_fail(fp != NULL, -1);
+       g_return_val_if_fail(compose->account != NULL, -1);
+       g_return_val_if_fail(compose->account->address != NULL, -1);
+
+       /* Date */
+       get_rfc822_date(buf, sizeof(buf));
+       fprintf(fp, "Resent-Date: %s\n", buf);
+
+       /* From */
+       if (compose->account->name && *compose->account->name) {
+               compose_convert_header
+                       (buf, sizeof(buf), compose->account->name,
+                        strlen("From: "));
+               fprintf(fp, "Resent-From: %s <%s>\n",
+                       buf, compose->account->address);
+       } else
+               fprintf(fp, "Resent-From: %s\n", compose->account->address);
+
+       /* To */
+       compose_bounce_write_headers_from_headerlist(compose, fp);
+
+       /* separator between header and body */
+       fputs("\n", fp);
+
+       return 0;
+}
+
+static gint compose_bounce_write_to_file(Compose *compose, const gchar *file)
+{
+       FILE *fp;
+       FILE *fdest;
+       size_t len;
+       gchar buf[BUFFSIZE];
+
+       if ((fp = fopen(compose->bounce_filename, "r")) == NULL) {
+               FILE_OP_ERROR(file, "fopen");
+               return -1;
+       }
+
+       if ((fdest = fopen(file, "a+")) == NULL) {
+               FILE_OP_ERROR(file, "fopen");
+               fclose(fp);
+               return -1;
+       }
+
+       /* chmod for security */
+       if (change_file_mode_rw(fdest, file) < 0) {
+               FILE_OP_ERROR(file, "chmod");
+               g_warning(_("can't change file mode\n"));
+       }
+
+       while (procheader_get_unfolded_line(buf, sizeof(buf), fp)) {
+               if (fputs(buf, fdest) == -1)
+                       goto error;
+               if (fputs("\n", fdest) == -1)
+                       goto error;
+       }
+
+       compose_bounce_write_headers(compose, fdest);
+
+       while ((len = fread(buf, sizeof(gchar), BUFFSIZE, fp)) > 0) {
+               if (fwrite(buf, sizeof(gchar), len, fdest) == -1)
+                       goto error;
+       }
+
+       fclose(fdest);
+       fclose(fp);
+
+       return 0;
+ error:
+       fclose(fdest);
+       fclose(fp);
+
+       return -1;
+}
+
 static gint compose_write_to_file(Compose *compose, const gchar *file,
                                  gboolean is_draft)
 {
@@ -2836,6 +3026,7 @@ static gint compose_remove_reedit_target(Compose *compose)
        return 0;
 }
 
+
 static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
 {
        FolderItem *queue;
@@ -2958,10 +3149,19 @@ static gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item)
        fprintf(fp, "\n");
        fclose(fp);
 
-        if (compose_write_to_file(compose, tmpfilename, FALSE) < 0) {
-               unlink(tmpfilename);
-               lock = FALSE;
-               return -1;
+       if (compose->bounce_filename != NULL) {
+               if (compose_bounce_write_to_file(compose, tmpfilename) < 0) {
+                       unlink(tmpfilename);
+                       lock = FALSE;
+                       return -1;
+               }
+       }
+       else {
+               if (compose_write_to_file(compose, tmpfilename, FALSE) < 0) {
+                       unlink(tmpfilename);
+                       lock = FALSE;
+                       return -1;
+               }
        }
                                                
        /* queue message */
@@ -3105,7 +3305,7 @@ static gint compose_write_headers_from_headerlist(Compose *compose,
                headerentry = ((compose_headerentry *)list->data);
                headerentryname = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(headerentry->combo)->entry));
 
-               if(!strcmp(trans_hdr, headerentryname)) {
+               if(!g_strcasecmp(trans_hdr, headerentryname)) {
                        str = gtk_entry_get_text(GTK_ENTRY(headerentry->entry));
                        Xstrdup_a(str, str, return -1);
                        g_strstrip(str);
@@ -4037,6 +4237,8 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
        compose->exteditor_readdes = -1;
        compose->exteditor_tag     = -1;
 
+       compose->bounce_filename = NULL;
+
        compose_set_title(compose);
 
 #if 0 /* NEW COMPOSE GUI */
@@ -4425,6 +4627,9 @@ static void compose_destroy(Compose *compose)
        g_free(compose->msgid);
        g_free(compose->boundary);
 
+       if (compose->bounce_filename)
+               g_free(compose->bounce_filename);
+
        g_free(compose->exteditor_file);
 
        for (row = 0; (ainfo = gtk_clist_get_row_data(clist, row)) != NULL;
@@ -5276,6 +5481,9 @@ static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
        Compose *compose = (Compose *)data;
        GList *file_list;
 
+       if (compose->bounce_filename != NULL)
+               return;
+
        file_list = filesel_select_multiple_files(_("Select file"), NULL);
 
        if (file_list) {
index 22fb594..bc3a98c 100644 (file)
@@ -60,6 +60,7 @@ typedef enum
        COMPOSE_REPLY_TO_ALL_WITHOUT_QUOTE,
        COMPOSE_FORWARD,
        COMPOSE_FORWARD_AS_ATTACH,
+       COMPOSE_BOUNCE,
        COMPOSE_NEW,
        COMPOSE_REEDIT
 } ComposeMode;
@@ -183,6 +184,8 @@ struct _Compose
         /* Pspell spell checker */
         GtkPspell *gtkpspell;
 #endif
+
+       gchar * bounce_filename;
 };
 
 struct _AttachInfo
@@ -215,6 +218,7 @@ Compose * compose_forward   (PrefsAccount *account,
                                 gboolean        as_attach);
 Compose * compose_forward_multiple(PrefsAccount * account, 
                          GSList *msginfo_list);
+Compose * compose_bounce(PrefsAccount *account, MsgInfo *msginfo);
                          
 void compose_reedit            (MsgInfo        *msginfo);
 
index a960920..d058d53 100644 (file)
@@ -530,6 +530,7 @@ static GtkItemFactoryEntry mainwin_entries[] =
        {N_("/_Message/_Forward"),              "<shift><alt>F", reply_cb, COMPOSE_FORWARD, NULL},
        {N_("/_Message/Forward as a_ttachment"),
                                                "<shift><control>F", reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
+       {N_("/_Message/Bounce"),                NULL, reply_cb, COMPOSE_BOUNCE, NULL},
        {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
        {N_("/_Message/Re-_edit"),              NULL, reedit_cb, 0, NULL},
        {N_("/_Message/---"),                   NULL, NULL, 0, "<Separator>"},
@@ -2466,6 +2467,9 @@ static void reply_cb(MainWindow *mainwin, guint action, GtkWidget *widget)
                        g_slist_free(msginfo_list);
                }                       
                break;
+       case COMPOSE_BOUNCE:
+                       compose_bounce(NULL, msginfo);
+                       break;
        default:
                g_warning("reply_cb(): invalid action type: %d\n", action);
        }
index 112edfc..ee8f682 100644 (file)
@@ -384,6 +384,7 @@ static GtkItemFactoryEntry summary_popup_entries[] =
        {N_("/_Forward"),               NULL, summary_reply_cb, COMPOSE_FORWARD, NULL},
        {N_("/Forward as a_ttachment"),
                                        NULL, summary_reply_cb, COMPOSE_FORWARD_AS_ATTACH, NULL},
+       {N_("/Bounce"),                 NULL, summary_reply_cb, COMPOSE_BOUNCE, NULL},
        {N_("/---"),                    NULL, NULL,             0, "<Separator>"},
        {N_("/Re-_edit"),               NULL, summary_reedit,   0, NULL},
        {N_("/---"),                    NULL, NULL,             0, "<Separator>"},
@@ -1004,6 +1005,7 @@ static void summary_set_menu_sensitive(SummaryView *summaryview)
        menu_set_sensitive(ifactory, "/Reply to all",             sens);
        menu_set_sensitive(ifactory, "/Forward",                  TRUE);
        menu_set_sensitive(ifactory, "/Forward as attachment",    TRUE);
+       menu_set_sensitive(ifactory, "/Bounce",                   TRUE);
 
        menu_set_sensitive(ifactory, "/Add sender to address book", sens);
 
@@ -4284,6 +4286,9 @@ static void summary_reply_cb(SummaryView *summaryview, guint action,
                        g_slist_free(msginfo_list);
                }                       
                break;
+       case COMPOSE_BOUNCE:
+               compose_bounce(NULL, msginfo);
+               break;
        default:
                g_warning("summary_reply_cb(): invalid action: %d\n", action);
        }