{
return GPOINTER_TO_INT(a) - GPOINTER_TO_INT(b);
}
+
+gchar *generate_msgid(const gchar *address, gchar *buf, gint len)
+{
+ /* steal from compose.c::compose_generate_msgid() */
+ struct tm *lt;
+ time_t t;
+ gchar *addr;
+
+ t = time(NULL);
+ lt = localtime(&t);
+
+ if (address && *address) {
+ if (strchr(address, '@'))
+ addr = g_strdup(address);
+ else
+ addr = g_strconcat(address, "@", get_domain_name(), NULL);
+ } else
+ addr = g_strconcat(g_get_user_name(), "@", get_domain_name(),
+ NULL);
+
+ g_snprintf(buf, len, "%04d%02d%02d%02d%02d%02d.%08x.%s",
+ lt->tm_year + 1900, lt->tm_mon + 1,
+ lt->tm_mday, lt->tm_hour,
+ lt->tm_min, lt->tm_sec,
+ (guint)random(), addr);
+
+ g_free(addr);
+ return buf;
+}
conv_encode_header(dest, len, src, header_len, FALSE);
}
-static gint disposition_notification_queue(PrefsAccount * account,
- gchar * to, const gchar *file)
-{
- FolderItem *queue;
- gchar *tmp;
- FILE *fp, *src_fp;
- gchar buf[BUFFSIZE];
- gint num;
-
- debug_print("queueing message...\n");
- g_return_val_if_fail(account != NULL, -1);
-
- tmp = g_strdup_printf("%s%cqueue.%d", g_get_tmp_dir(),
- G_DIR_SEPARATOR, (gint)file);
- if ((fp = fopen(tmp, "wb")) == NULL) {
- FILE_OP_ERROR(tmp, "fopen");
- g_free(tmp);
- return -1;
- }
- if ((src_fp = fopen(file, "rb")) == NULL) {
- FILE_OP_ERROR(file, "fopen");
- fclose(fp);
- unlink(tmp);
- g_free(tmp);
- return -1;
- }
- if (change_file_mode_rw(fp, tmp) < 0) {
- FILE_OP_ERROR(tmp, "chmod");
- g_warning("can't change file mode\n");
- }
-
- /* queueing variables */
- fprintf(fp, "AF:\n");
- fprintf(fp, "NF:0\n");
- fprintf(fp, "PS:10\n");
- fprintf(fp, "SRH:1\n");
- fprintf(fp, "SFN:\n");
- fprintf(fp, "DSR:\n");
- fprintf(fp, "MID:\n");
- fprintf(fp, "CFG:\n");
- fprintf(fp, "PT:0\n");
- fprintf(fp, "S:%s\n", account->address);
- fprintf(fp, "RQ:\n");
- if (account->smtp_server)
- fprintf(fp, "SSV:%s\n", account->smtp_server);
- else
- fprintf(fp, "SSV:\n");
- if (account->nntp_server)
- fprintf(fp, "NSV:%s\n", account->nntp_server);
- else
- fprintf(fp, "NSV:\n");
- fprintf(fp, "SSH:\n");
- fprintf(fp, "R:<%s>", to);
- fprintf(fp, "\n");
- fprintf(fp, "\n");
-
- while (fgets(buf, sizeof(buf), src_fp) != NULL) {
- if (fputs(buf, fp) == EOF) {
- FILE_OP_ERROR(tmp, "fputs");
- fclose(fp);
- fclose(src_fp);
- unlink(tmp);
- g_free(tmp);
- return -1;
- }
- }
-
- fclose(src_fp);
- if (fclose(fp) == EOF) {
- FILE_OP_ERROR(tmp, "fclose");
- unlink(tmp);
- g_free(tmp);
- return -1;
- }
-
- queue = folder_get_default_queue();
- if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
- g_warning("can't queue the message\n");
- unlink(tmp);
- g_free(tmp);
- return -1;
- }
- g_free(tmp);
-
- return 0;
-}
-
static gint disposition_notification_send(MsgInfo *msginfo)
{
gchar buf[BUFFSIZE];
gchar tmp[MAXPATHLEN + 1];
FILE *fp;
- GSList *to_list;
GList *ac_list;
PrefsAccount *account;
gint ok;
gchar *to;
+ FolderItem *queue, *outbox;
+ gint num;
+ gchar *path;
if ((!msginfo->returnreceiptto) &&
(!msginfo->dispositionnotificationto))
g_warning("can't change file mode\n");
}
+ /* write queue headers */
+ fprintf(fp, "AF:\n");
+ fprintf(fp, "NF:0\n");
+ fprintf(fp, "PS:10\n");
+ fprintf(fp, "SRH:1\n");
+ fprintf(fp, "SFN:\n");
+ fprintf(fp, "DSR:\n");
+ fprintf(fp, "MID:\n");
+ fprintf(fp, "CFG:\n");
+ fprintf(fp, "PT:0\n");
+ fprintf(fp, "S:%s\n", account->address);
+ fprintf(fp, "RQ:\n");
+ if (account->smtp_server)
+ fprintf(fp, "SSV:%s\n", account->smtp_server);
+ else
+ fprintf(fp, "SSV:\n");
+ fprintf(fp, "SSH:\n");
+ fprintf(fp, "R:<%s>\n", to);
+
+ /* check whether we need to save the message */
+ outbox = account_get_special_folder(account, F_OUTBOX);
+ if (folder_get_default_outbox() == outbox && !prefs_common.savemsg)
+ outbox = NULL;
+ if (outbox) {
+ path = folder_item_get_identifier(outbox);
+ fprintf(fp, "SCF:%s\n", path);
+ g_free(path);
+ }
+
+ fprintf(fp, "\n");
+
/* Date */
get_rfc822_date(buf, sizeof(buf));
fprintf(fp, "Date: %s\n", buf);
strlen("Subject: "));
fprintf(fp, "Subject: Disposition notification: %s\n", buf);
+ /* Message ID */
+ generate_msgid(account->address, buf, sizeof buf);
+ fprintf(fp, "Message-Id: <%s>\n", buf);
+
if (fclose(fp) == EOF) {
FILE_OP_ERROR(tmp, "fclose");
unlink(tmp);
return -1;
}
- to_list = address_list_append(NULL, to);
- ok = send_message(tmp, account, to_list);
-
- if (ok < 0) {
- if (prefs_common.queue_msg) {
- AlertValue val;
-
- val = alertpanel
- (_("Queueing"),
- _("Error occurred while sending the notification.\n"
- "Put this notification into queue folder?"),
- _("OK"), _("Cancel"), NULL);
- if (G_ALERTDEFAULT == val) {
- ok = disposition_notification_queue(account, to, tmp);
- if (ok < 0)
- alertpanel_error(_("Can't queue the notification."));
- }
- } else
- alertpanel_error_log(_("Error occurred while sending the notification."));
+ /* put it in queue */
+ queue = account_get_special_folder(account, F_QUEUE);
+ if (!queue) queue = folder_get_default_queue();
+ if (!queue) {
+ g_warning("can't find queue folder\n");
+ unlink(tmp);
+ return -1;
}
-
- if (unlink(tmp) < 0) FILE_OP_ERROR(tmp, "unlink");
+ folder_item_scan(queue);
+ if ((num = folder_item_add_msg(queue, tmp, NULL, TRUE)) < 0) {
+ g_warning("can't queue the message\n");
+ unlink(tmp);
+ return -1;
+ }
+
+ /* send it */
+ path = folder_item_fetch_msg(queue, num);
+ ok = procmsg_send_message_queue(path);
+ g_free(path);
+ folder_item_remove_msg(queue, num);
return ok;
}