* src/common/utils.[ch]
authorAlfons Hoogervorst <alfons@proteus.demon.nl>
Tue, 29 Jul 2003 19:47:24 +0000 (19:47 +0000)
committerAlfons Hoogervorst <alfons@proteus.demon.nl>
Tue, 29 Jul 2003 19:47:24 +0000 (19:47 +0000)
add generate_msgid()
* src/messageview.c
save ack'ed RRR; fixes #205, "return receipt is not saved in
sent folder".

ChangeLog.claws
configure.ac
src/common/utils.c
src/common/utils.h
src/messageview.c

index efa153a..983a010 100644 (file)
@@ -1,3 +1,11 @@
+2003-07-29 [alfons]    0.9.3claws76
+
+       * src/common/utils.[ch]
+               add generate_msgid()
+       * src/messageview.c
+               save ack'ed RRR; fixes #205, "return receipt is not saved in
+               sent folder".
+
 2003-07-29 [alfons]    0.9.3claws75
 
        * src/messageview.c
index 43fe059..287622f 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=9
 MICRO_VERSION=3
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=75
+EXTRA_VERSION=76
 if test $EXTRA_VERSION -eq 0; then
     VERSION=${MAJOR_VERSION}.${MINOR_VERSION}.${MICRO_VERSION}claws
 else
index 9950bd2..3282109 100644 (file)
@@ -3566,3 +3566,32 @@ gint g_int_compare(gconstpointer a, gconstpointer b)
 {
        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;
+}
index 3de9bae..8ce95a9 100644 (file)
@@ -444,4 +444,6 @@ guint g_stricase_hash       (gconstpointer gptr);
 gint g_stricase_equal  (gconstpointer gptr1, gconstpointer gptr2);
 gint g_int_compare     (gconstpointer a, gconstpointer b);
 
+gchar *generate_msgid  (const gchar *address, gchar *buf, gint len);
+
 #endif /* __UTILS_H__ */
index 53a8c53..a7ba6f9 100644 (file)
@@ -441,103 +441,18 @@ static void notification_convert_header(gchar *dest, gint len,
                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)) 
@@ -617,6 +532,37 @@ static gint disposition_notification_send(MsgInfo *msginfo)
                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);
@@ -637,34 +583,36 @@ static gint disposition_notification_send(MsgInfo *msginfo)
                                    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;
 }