#include "alertpanel.h"
#include "send.h"
#include "pgptext.h"
+#include "menu.h"
static void messageview_change_view_type(MessageView *messageview,
MessageType type);
GdkEventKey *event,
MessageView *messageview);
-MessageView *messageview_create(void)
+static void return_receipt_show (NoticeView *noticeview,
+ MsgInfo *msginfo);
+static void return_receipt_send_clicked (NoticeView *noticeview,
+ MsgInfo *msginfo);
+
+static PrefsAccount *select_account_from_list
+ (GList *ac_list);
+
+MessageView *messageview_create(MainWindow *mainwin)
{
MessageView *messageview;
GtkWidget *vbox;
TextView *textview;
ImageView *imageview;
MimeView *mimeview;
+ NoticeView *noticeview;
- debug_print(_("Creating message view...\n"));
+ debug_print("Creating message view...\n");
messageview = g_new0(MessageView, 1);
messageview->type = MVIEW_TEXT;
headerview = headerview_create();
+ noticeview = noticeview_create(mainwin);
+
textview = textview_create();
textview->messageview = messageview;
vbox = gtk_vbox_new(FALSE, 0);
gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(headerview),
FALSE, FALSE, 0);
+ gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(noticeview),
+ FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(vbox), GTK_WIDGET_PTR(textview),
TRUE, TRUE, 0);
messageview->textview = textview;
messageview->imageview = imageview;
messageview->mimeview = mimeview;
+ messageview->noticeview = noticeview;
return messageview;
}
-MessageView *messageview_create_with_new_window(void)
+MessageView *messageview_create_with_new_window(MainWindow *mainwin)
{
GtkWidget *window;
MessageView *msgview;
gtk_widget_set_usize(window, prefs_common.msgwin_width,
prefs_common.msgwin_height);
- msgview = messageview_create();
+ msgview = messageview_create(mainwin);
gtk_signal_connect(GTK_OBJECT(window), "size_allocate",
GTK_SIGNAL_FUNC(messageview_size_allocate_cb),
imageview_init(messageview->imageview);
mimeview_init(messageview->mimeview);
/*messageview_set_font(messageview);*/
+
+ noticeview_hide(messageview->noticeview);
}
-static void notification_convert_header(gchar *dest, gint len, gchar *src,
+static void notification_convert_header(gchar *dest, gint len,
+ const gchar *src_,
gint header_len)
{
- g_return_if_fail(src != NULL);
+ char *src;
+
+ g_return_if_fail(src_ != NULL);
g_return_if_fail(dest != NULL);
if (len < 1) return;
+ Xstrndup_a(src, src_, len, return);
+
remove_return(src);
if (is_ascii_str(src)) {
gchar * to, const gchar *file)
{
FolderItem *queue;
- gchar *tmp, *queue_path;
+ gchar *tmp;
FILE *fp, *src_fp;
- GSList *cur;
gchar buf[BUFFSIZE];
gint num;
- debug_print(_("queueing message...\n"));
+ debug_print("queueing message...\n");
g_return_val_if_fail(account != NULL, -1);
tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
}
queue = folder_get_default_queue();
- folder_item_scan(queue);
- queue_path = folder_item_get_path(queue);
- if (!is_dir_exist(queue_path))
- make_dir_hier(queue_path);
if ((num = folder_item_add_msg(queue, tmp, TRUE)) < 0) {
g_warning(_("can't queue the message\n"));
unlink(tmp);
g_free(tmp);
- g_free(queue_path);
return -1;
}
g_free(tmp);
- if ((fp = procmsg_open_mark_file(queue_path, TRUE)) == NULL)
- g_warning(_("can't open mark file\n"));
- else {
- MsgInfo newmsginfo;
-
- newmsginfo.msgnum = num;
- newmsginfo.flags.perm_flags = newmsginfo.flags.tmp_flags = 0;
- procmsg_write_flags(&newmsginfo, fp);
- fclose(fp);
- }
- g_free(queue_path);
-
- folder_item_scan(queue);
- folderview_update_item(queue, TRUE);
+ folder_update_item(queue, TRUE);
return 0;
}
-static gint disposition_notification_send(MsgInfo * msginfo)
+static gint disposition_notification_send(MsgInfo *msginfo)
{
gchar buf[BUFFSIZE];
gchar tmp[MAXPATHLEN + 1];
FILE *fp;
- GSList * to_list;
+ GSList *to_list;
+ GList *ac_list;
+ PrefsAccount *account;
gint ok;
- gchar * to;
+ gchar *to;
if ((!msginfo->returnreceiptto) &&
- (!msginfo->dispositionnotificationto))
+ (!msginfo->dispositionnotificationto))
+ return -1;
+
+ /* RFC2298: Test for Return-Path */
+ if (msginfo->dispositionnotificationto)
+ to = msginfo->dispositionnotificationto;
+ else
+ to = msginfo->returnreceiptto;
+
+ ok = get_header_from_msginfo(msginfo, buf, sizeof(buf),
+ "Return-Path:");
+ if (ok == 0) {
+ gchar *to_addr = g_strdup(to);
+ extract_address(to_addr);
+ extract_address(buf);
+ ok = strcmp(to_addr, buf);
+ g_free(to_addr);
+ } else {
+ strncpy(buf, _("<No Return-Path found>"),
+ sizeof(buf));
+ }
+
+ if (ok != 0) {
+ AlertValue val;
+ gchar *message;
+ message = g_strdup_printf(
+ _("The notification address to which the "
+ "return receipt is to be sent\n"
+ "does not correspond to the return path:\n"
+ "Notification address: %s\n"
+ "Return path: %s\n"
+ "It is advised to not to send the return "
+ "receipt."), to, buf);
+ val = alertpanel(_("Warning"), message, _("Send"),
+ _("+Don't Send"), NULL);
+ if (val != G_ALERTDEFAULT)
+ return -1;
+ }
+
+ ac_list = account_find_all_from_address(NULL, msginfo->to);
+ ac_list = account_find_all_from_address(ac_list, msginfo->cc);
+
+ if (ac_list == NULL) {
+ alertpanel_error(_("This message is asking for a return "
+ "receipt notification\n"
+ "but according to its 'To:' and 'CC:' "
+ "headers it was not\nofficially addressed "
+ "to you.\n"
+ "Receipt notification cancelled."));
+ return -1;
+ }
+
+ if (g_list_length(ac_list) > 1)
+ account = select_account_from_list(ac_list);
+ else
+ account = (PrefsAccount *) ac_list->data;
+ g_list_free(ac_list);
+
+ if (account == NULL)
return -1;
/* write to temporary file */
fprintf(fp, "Date: %s\n", buf);
/* From */
- if (cur_account->name && *cur_account->name) {
+ if (account->name && *account->name) {
notification_convert_header
- (buf, sizeof(buf), cur_account->name,
+ (buf, sizeof(buf), account->name,
strlen("From: "));
- fprintf(fp, "From: %s <%s>\n", buf, cur_account->address);
+ fprintf(fp, "From: %s <%s>\n", buf, account->address);
} else
- fprintf(fp, "From: %s\n", cur_account->address);
+ fprintf(fp, "From: %s\n", account->address);
- /* To */
- if (msginfo->dispositionnotificationto)
- to = msginfo->dispositionnotificationto;
- else
- to = msginfo->returnreceiptto;
fprintf(fp, "To: %s\n", to);
/* Subject */
return -1;
}
- to_list = address_list_append(NULL, msginfo->dispositionnotificationto);
- ok = send_message(tmp, cur_account, to_list);
+ to_list = address_list_append(NULL, to);
+ ok = send_message(tmp, account, to_list);
if (ok < 0) {
if (prefs_common.queue_msg) {
"Put this notification into queue folder?"),
_("OK"), _("Cancel"), NULL);
if (G_ALERTDEFAULT == val) {
- ok = disposition_notification_queue(cur_account, to, tmp);
+ ok = disposition_notification_queue(account, to, tmp);
if (ok < 0)
alertpanel_error(_("Can't queue the notification."));
}
file = procmsg_get_message_file_path(msginfo);
if (!file) {
- g_warning("can't get message file path.\n");
- procmime_mimeinfo_free(mimeinfo);
+ g_warning(_("can't get message file path.\n"));
+ procmime_mimeinfo_free_all(mimeinfo);
return;
}
- /* FIXME - doesn't tmpmsginfo->flags have the value
- * of msginfo->flags after procheader_parse()???
- * in any case, checking tmpmsginfo->flags for MSG_UNREAD
- * fixes the return-receipt-request bug */
-
tmpmsginfo = procheader_parse_file(file, msginfo->flags, TRUE, TRUE);
- if (MSG_IS_MIME(tmpmsginfo->flags))
- MSG_SET_TMP_FLAGS(msginfo->flags, MSG_MIME);
-
- if (prefs_common.return_receipt
- && (tmpmsginfo->dispositionnotificationto
- || tmpmsginfo->returnreceiptto)
- && (MSG_IS_UNREAD(tmpmsginfo->flags))
- && (MSG_IS_RETRCPT_PENDING(tmpmsginfo->flags))) {
- gint ok;
-
- if (alertpanel(_("Return Receipt"), _("Send return receipt ?"),
- _("Yes"), _("No"), NULL) == G_ALERTDEFAULT) {
- ok = disposition_notification_send(tmpmsginfo);
- if (ok < 0)
- alertpanel_error(_("Error occurred while sending notification."));
- }
- MSG_UNSET_PERM_FLAGS(tmpmsginfo->flags, MSG_RETRCPT_PENDING);
- }
headerview_show(messageview->headerview, tmpmsginfo);
procmsg_msginfo_free(tmpmsginfo);
} else {
messageview_change_view_type(messageview, MVIEW_TEXT);
textview_show_message(messageview->textview, mimeinfo, file);
- procmime_mimeinfo_free(mimeinfo);
+ procmime_mimeinfo_free_all(mimeinfo);
}
+ if (MSG_IS_RETRCPT_PENDING(msginfo->flags))
+ return_receipt_show(messageview->noticeview, msginfo);
+ else
+ noticeview_hide(messageview->noticeview);
+
g_free(file);
}
headerview_clear(messageview->headerview);
textview_clear(messageview->textview);
imageview_clear(messageview->imageview);
+ noticeview_hide(messageview->noticeview);
}
void messageview_destroy(MessageView *messageview)
textview_destroy(messageview->textview);
imageview_destroy(messageview->imageview);
mimeview_destroy(messageview->mimeview);
+ noticeview_destroy(messageview->noticeview);
g_free(messageview);
gtk_widget_destroy(messageview->window);
}
-static void messageview_toggle_view(MessageView *messageview)
-{
- MainWindow *mainwin = messageview->mainwin;
- GtkItemFactory *ifactory;
-
- if (!mainwin) return;
-
- ifactory = gtk_item_factory_from_widget(mainwin->menubar);
- menu_toggle_toggle(ifactory, "/View/Expand Summary View");
-}
-
void messageview_toggle_view_real(MessageView *messageview)
{
MainWindow *mainwin = messageview->mainwin;
gtk_widget_grab_focus(GTK_WIDGET(mainwin->summaryview->ctree));
}
}
+
+static void return_receipt_show(NoticeView *noticeview, MsgInfo *msginfo)
+{
+ noticeview_set_text(noticeview, _("This messages asks for a return receipt."));
+ noticeview_set_button_text(noticeview, _("Send receipt"));
+ noticeview_set_button_press_callback(noticeview,
+ GTK_SIGNAL_FUNC(return_receipt_send_clicked),
+ (gpointer) msginfo);
+ noticeview_show(noticeview);
+}
+
+static void return_receipt_send_clicked(NoticeView *noticeview, MsgInfo *msginfo)
+{
+ MsgInfo *tmpmsginfo;
+ gchar *file;
+
+ file = procmsg_get_message_file_path(msginfo);
+ if (!file) {
+ g_warning(_("can't get message file path.\n"));
+ return;
+ }
+
+ tmpmsginfo = procheader_parse_file(file, msginfo->flags, TRUE, TRUE);
+ tmpmsginfo->folder = msginfo->folder;
+ tmpmsginfo->msgnum = msginfo->msgnum;
+
+ if (disposition_notification_send(tmpmsginfo) >= 0) {
+ procmsg_msginfo_unset_flags(msginfo, MSG_RETRCPT_PENDING, 0);
+ noticeview_hide(noticeview);
+ }
+
+ procmsg_msginfo_free(tmpmsginfo);
+ g_free(file);
+}
+
+static void select_account_cb(GtkWidget *w, gpointer data)
+{
+ *(gint*)data = GPOINTER_TO_INT(gtk_object_get_user_data(GTK_OBJECT(w)));
+}
+
+static PrefsAccount *select_account_from_list(GList *ac_list)
+{
+ GtkWidget *optmenu;
+ GtkWidget *menu;
+ gint account_id;
+
+ g_return_val_if_fail(ac_list != NULL, NULL);
+ g_return_val_if_fail(ac_list->data != NULL, NULL);
+
+ optmenu = gtk_option_menu_new();
+ menu = gtkut_account_menu_new(ac_list, select_account_cb, &account_id);
+ if (!menu)
+ return NULL;
+ gtk_option_menu_set_menu(GTK_OPTION_MENU(optmenu), menu);
+ gtk_option_menu_set_history(GTK_OPTION_MENU(optmenu), 0);
+ account_id = ((PrefsAccount *) ac_list->data)->account_id;
+ if (alertpanel_with_widget(
+ _("Return Receipt Notification"),
+ _("The message was sent to several of your "
+ "accounts.\n"
+ "Please choose which account do you want to "
+ "use for sending the receipt notification:"),
+ _("Send Notification"), _("+Cancel"), NULL,
+ optmenu) != G_ALERTDEFAULT)
+ return NULL;
+ return account_find_from_id(account_id);
+}