let the user decide if he wants to download/delete partially received
authorColin Leroy <colin@colino.net>
Thu, 8 Jul 2004 21:51:06 +0000 (21:51 +0000)
committerColin Leroy <colin@colino.net>
Thu, 8 Jul 2004 21:51:06 +0000 (21:51 +0000)
mails

ChangeLog-gtk2.claws
PATCHSETS
configure.ac
src/messageview.c
src/noticeview.c
src/noticeview.h
src/pop.c
src/pop.h

index c7c40b23b9e6d18d80d4487c70a05f5a0abe1999..daf2a4660d6daf850cbd29d72648f40201d55daf 100644 (file)
@@ -1,3 +1,14 @@
+2004-07-08 [colin]     0.9.11cvs17.16
+
+       * src/noticeview.c
+       * src/noticeview.h
+               Add an optional second button
+       * src/messageview.c
+       * src/pop.c
+       * src/pop.h
+               Don't delete partially received mails after a certain
+               time; rather, let the user decide.
+
 2004-07-08 [colin]     0.9.11cvs17.15
 
        * src/common/smtp.h
index 024d0696472a006bddc666e7b5e174595098f4df..8827532ce0c72f34b2638961e6f12d421ef82947 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
@@ -9,3 +9,4 @@
 ( cvs diff -u -r 1.149.2.7 -r 1.149.2.8 src/inc.c; cvs diff -u -r 1.94.2.8 -r 1.94.2.9 src/messageview.c; cvs diff -u -r 1.56.2.4 -r 1.56.2.5 src/pop.c; cvs diff -u -r 1.17.2.3 -r 1.17.2.4 src/pop.h; cvs diff -u -r 1.150.2.4 -r 1.150.2.5 src/procmsg.c; ) > 0.9.11cvs17.13.patchset
 ( cvs diff -u -r 1.94.2.9 -r 1.94.2.11 src/messageview.c; cvs diff -u -r 1.11.2.2 -r 1.11.2.4 src/common/smtp.c; ) > 0.9.11cvs17.14.patchset
 ( cvs diff -u -r 1.6.2.1 -r 1.6.2.2 src/common/smtp.h; ) > 0.9.11cvs17.15.patchset
+( cvs diff -u -r 1.94.2.11 -r 1.94.2.12 src/messageview.c; cvs diff -u -r 1.5.2.3 -r 1.5.2.4 src/noticeview.c; cvs diff -u -r 1.3.8.1 -r 1.3.8.2 src/noticeview.h; cvs diff -u -r 1.56.2.5 -r 1.56.2.6 src/pop.c; cvs diff -u -r 1.17.2.4 -r 1.17.2.5 src/pop.h; ) > 0.9.11cvs17.16.patchset
index 4178534c90a4e3e933931d8b0f2bcaf39c932671..c6d65fcfcbba04ef26f95715842ac20c1d32ecc5 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=9
 MICRO_VERSION=11
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=17.15
+EXTRA_VERSION=17.16
 EXTRA_RELEASE=
 
 if test \( $EXTRA_VERSION -eq 0 \) -o \( "x$EXTRA_RELEASE" != "x" \); then
index 7c000ff4deccb9e79a7d81de65e35eac2c27a5c3..cc8a74f1d03f9fe1c20acf78587c8f6faa14a963 100644 (file)
@@ -82,6 +82,8 @@ static void partial_recv_show         (NoticeView     *noticeview,
                                         MsgInfo        *msginfo);      
 static void partial_recv_dload_clicked (NoticeView     *noticeview, 
                                          MsgInfo        *msginfo);
+static void partial_recv_del_clicked (NoticeView       *noticeview, 
+                                         MsgInfo        *msginfo);
 static void save_as_cb                 (gpointer        data,
                                         guint           action,
                                         GtkWidget      *widget);
@@ -1062,9 +1064,12 @@ static void return_receipt_send_clicked(NoticeView *noticeview, MsgInfo *msginfo
 static void partial_recv_show(NoticeView *noticeview, MsgInfo *msginfo)
 {
        gchar *text = NULL;
-       if (!msginfo->planned_download) {
+       if (!pop3_msg_in_uidl_list(msginfo->account_server, msginfo->account_login,
+                                  msginfo->partial_recv))
+               return;
+       if (msginfo->planned_download == 0) {
                text = g_strdup_printf(_("This message has been partially "
-                                "retrieved; it is %s large."), 
+                                "retrieved;\n it is %s large."), 
                                 to_human_readable(
                                        (off_t)(msginfo->total_size)));
 
@@ -1074,16 +1079,39 @@ static void partial_recv_show(NoticeView *noticeview, MsgInfo *msginfo)
                noticeview_set_button_press_callback(noticeview,
                             GTK_SIGNAL_FUNC(partial_recv_dload_clicked),
                             (gpointer) msginfo);
+               noticeview_set_2ndbutton_text(noticeview, _("Mark for deletion"));
+               noticeview_set_2ndbutton_press_callback(noticeview,
+                            GTK_SIGNAL_FUNC(partial_recv_del_clicked),
+                            (gpointer) msginfo);
                noticeview_show(noticeview);
-       } else {
+       } else if (msginfo->planned_download == 1) {
                text = g_strdup_printf(_("This message has been partially "
                                 "retrieved and is planned for "
-                                "download; it is %s large."), 
+                                "download;\n it is %s large."), 
                                 to_human_readable(
                                        (off_t)(msginfo->total_size)));
 
                noticeview_set_text(noticeview, text);
-               noticeview_set_button_text(noticeview, NULL);
+               noticeview_set_button_text(noticeview, _("Mark for deletion"));
+               noticeview_set_2ndbutton_text(noticeview, NULL);
+               noticeview_set_button_press_callback(noticeview,
+                            GTK_SIGNAL_FUNC(partial_recv_del_clicked),
+                            (gpointer) msginfo);
+               g_free(text);
+               noticeview_show(noticeview);
+       } else if (msginfo->planned_download == -1) {
+               text = g_strdup_printf(_("This message has been partially "
+                                "retrieved and is planned for "
+                                "deletion;\n it is %s large."), 
+                                to_human_readable(
+                                       (off_t)(msginfo->total_size)));
+
+               noticeview_set_text(noticeview, text);
+               noticeview_set_button_text(noticeview, _("Mark for download"));
+               noticeview_set_2ndbutton_text(noticeview, NULL);
+               noticeview_set_button_press_callback(noticeview,
+                            GTK_SIGNAL_FUNC(partial_recv_dload_clicked),
+                            (gpointer) msginfo);
                g_free(text);
                noticeview_show(noticeview);
        }
@@ -1116,6 +1144,33 @@ static void partial_recv_dload_clicked(NoticeView *noticeview,
        g_free(file);
 }
 
+static void partial_recv_del_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 (pop3_mark_for_delete(tmpmsginfo->account_server, 
+                                  tmpmsginfo->account_login, 
+                                  tmpmsginfo->partial_recv, file) == 0) {
+               msginfo->planned_download = -1;
+               partial_recv_show(noticeview, msginfo);
+       }
+
+       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)));
index 98f0a26e6db9c43476df1242b45f8bfa11b12932..fae85cba1d372f70b975772a7d07166e05a386b7 100644 (file)
@@ -46,6 +46,7 @@
 #include "noticeview.h"
 
 static void noticeview_button_pressed  (GtkButton *button, NoticeView *noticeview);
+static void noticeview_2ndbutton_pressed(GtkButton *button, NoticeView *noticeview);
 
 NoticeView *noticeview_create(MainWindow *mainwin)
 {
@@ -56,6 +57,7 @@ NoticeView *noticeview_create(MainWindow *mainwin)
        GtkWidget  *icon;
        GtkWidget  *text;
        GtkWidget  *widget;
+       GtkWidget  *widget2;
 
        debug_print("Creating notice view...\n");
        noticeview = g_new0(NoticeView, 1);
@@ -90,12 +92,19 @@ NoticeView *noticeview_create(MainWindow *mainwin)
                         (gpointer) noticeview);
        gtk_box_pack_start(GTK_BOX(hbox), widget, FALSE, FALSE, 4);
        
+       widget2 = gtk_button_new_with_label("");
+       g_signal_connect(G_OBJECT(widget2), "clicked", 
+                        G_CALLBACK(noticeview_2ndbutton_pressed),
+                        (gpointer) noticeview);
+       gtk_box_pack_start(GTK_BOX(hbox), widget2, FALSE, FALSE, 4);
+       
        noticeview->vbox   = vbox;
        noticeview->hsep   = hsep;
        noticeview->hbox   = hbox;
        noticeview->icon   = icon;
        noticeview->text   = text;
        noticeview->button = widget;
+       noticeview->button2 = widget2;
 
        noticeview->visible = TRUE;
 
@@ -161,6 +170,33 @@ static void noticeview_button_pressed(GtkButton *button, NoticeView *noticeview)
        }
 }
 
+void noticeview_set_2ndbutton_text(NoticeView *noticeview, const char *text)
+{
+       g_return_if_fail(noticeview);
+
+       if (text != NULL) {
+               gtk_label_set_text
+                       (GTK_LABEL(GTK_BIN(noticeview->button2)->child), text);
+               gtk_widget_show(noticeview->button2);
+       } else
+               gtk_widget_hide(noticeview->button2);
+}
+
+void noticeview_set_2ndbutton_press_callback(NoticeView        *noticeview,
+                                         GtkSignalFunc  callback,
+                                         gpointer      *user_data)
+{
+       noticeview->press2     = (void (*) (NoticeView *, gpointer)) callback;
+       noticeview->user_data2 = user_data;
+}
+
+static void noticeview_2ndbutton_pressed(GtkButton *button, NoticeView *noticeview)
+{
+       if (noticeview->press2) {
+               noticeview->press2(noticeview, noticeview->user_data2);
+       }
+}
+
 void noticeview_set_icon(NoticeView *noticeview, StockPixmap icon)
 {
        GdkPixmap *pixmap;
index 054317ccf2a34e3b2b8fe51e30bbb5640aa8d2c9..634bd91934bfe3301e92a9399c5d635133fc6d17 100644 (file)
@@ -32,10 +32,13 @@ struct _NoticeView
        GtkWidget       *icon;
        GtkWidget       *text;
        GtkWidget       *button;
+       GtkWidget       *button2;
        GtkWidget       *window;
        gboolean         visible;
        gpointer         user_data;
+       gpointer         user_data2;
        void            (*press) (NoticeView *, gpointer user_data);
+       void            (*press2) (NoticeView *, gpointer user_data);
 };
 
 NoticeView     *noticeview_create      (MainWindow     *mainwin);
@@ -48,6 +51,9 @@ void           noticeview_set_text    (NoticeView     *noticeview,
 void            noticeview_set_button_text 
                                        (NoticeView     *noticeview,
                                         const gchar    *text);
+void            noticeview_set_2ndbutton_text 
+                                       (NoticeView     *noticeview,
+                                        const gchar    *text);
 gboolean        noticeview_is_visible  (NoticeView     *noticeview);
 void            noticeview_show        (NoticeView     *noticeview);
 void            noticeview_hide        (NoticeView     *noticeview);
@@ -56,5 +62,9 @@ void           noticeview_set_button_press_callback
                                        (NoticeView     *noticeview,
                                         GtkSignalFunc   callback,
                                         gpointer       *user_data);
+void            noticeview_set_2ndbutton_press_callback
+                                       (NoticeView     *noticeview,
+                                        GtkSignalFunc   callback,
+                                        gpointer       *user_data);
                                        
 #endif /* NOTICEVIEW_H__ */
index 045a8a8dc87fc3cdaaf1a44ee11b4f6e413d95db..20f4006af6466e19f2daab9bbc7af164fd8d6448 100644 (file)
--- a/src/pop.c
+++ b/src/pop.c
@@ -609,6 +609,59 @@ void pop3_get_uidl_table(PrefsAccount *ac_prefs, Pop3Session *session)
        return;
 }
 
+int pop3_msg_in_uidl_list(const gchar *server, const gchar *login, 
+                         const gchar *muidl)
+{
+       gchar *path;
+       FILE *fp;
+       gchar buf[POPBUFSIZE];
+       gchar uidl[POPBUFSIZE];
+       time_t recv_time;
+       time_t now;
+       gint partial_recv;
+       
+       path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
+                          "uidl", G_DIR_SEPARATOR_S, server,
+                          "-", login, NULL);
+       if ((fp = fopen(path, "rb")) == NULL) {
+               if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
+               g_free(path);
+               path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
+                                  "uidl-", server,
+                                  "-", login, NULL);
+               if ((fp = fopen(path, "rb")) == NULL) {
+                       if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
+                       g_free(path);
+                       return FALSE;
+               }
+       }
+       g_free(path);
+
+       now = time(NULL);
+
+       while (fgets(buf, sizeof(buf), fp) != NULL) {
+               gchar tmp[POPBUFSIZE];
+               strretchomp(buf);
+               recv_time = RECV_TIME_NONE;
+               partial_recv = 0;
+               
+               if (sscanf(buf, "%s\t%ld\t%s", uidl, &recv_time, &tmp) < 2) {
+                       if (sscanf(buf, "%s", uidl) != 1)
+                               continue;
+                       else {
+                               recv_time = now;
+                       }
+               }
+               if (!strcmp(uidl, muidl)) {
+                       fclose(fp);
+                       return TRUE;
+               }
+       }
+
+       fclose(fp);     
+       return FALSE;
+}
+
 static gchar *pop3_get_filename_for_partial_mail(Pop3Session *session, 
                                                 gchar *muidl)
 {
@@ -665,8 +718,11 @@ static gchar *pop3_get_filename_for_partial_mail(Pop3Session *session,
        return result;
 }
 
-int pop3_mark_for_download(const gchar *server, const gchar *login, 
-                          const gchar *muidl, const gchar *filename)
+#define DOWNLOAD_MAIL 1
+#define DELETE_MAIL 2
+static int pop3_mark_mail(const gchar *server, const gchar *login, 
+                         const gchar *muidl, const gchar *filename, 
+                         int download)
 {
        gchar *path;
        gchar *pathnew;
@@ -677,9 +733,9 @@ int pop3_mark_for_download(const gchar *server, const gchar *login,
        time_t recv_time;
        time_t now;
        int len;
+       int start = TRUE;
        gchar partial_recv[POPBUFSIZE];
        
-
        path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                           "uidl", G_DIR_SEPARATOR_S, server,
                           "-", login, NULL);
@@ -727,7 +783,8 @@ int pop3_mark_for_download(const gchar *server, const gchar *login,
                                uidl, recv_time, partial_recv);
                } else {
                        fprintf(fpnew, "%s\t%ld\t%s\n", 
-                               uidl, recv_time, filename);
+                               uidl, recv_time, 
+                               download==DOWNLOAD_MAIL?filename:"0");
                }
        }
        fclose(fpnew);
@@ -750,8 +807,17 @@ int pop3_mark_for_download(const gchar *server, const gchar *login,
                return -1;
        }
        
-       fprintf(fpnew, "SC-Marked-For-Download: 1\n");
        while ((len = fread(buf, sizeof(gchar), sizeof(buf), fp)) > 0) {
+               if (start) {
+                       start = FALSE;
+                       fprintf(fpnew, "SC-Marked-For-Download: %d\n", download);
+                       printf("buf '%s'\n", buf);
+                       if(!strncmp(buf, "SC-Marked-For-Download:", 
+                                   strlen("SC-Marked-For-Download:"))) {
+                               fprintf(fpnew, "%s", buf+strlen("SC-Marked-For-Download: x\n"));
+                               continue;
+                       }
+               }
                fprintf(fpnew, "%s", buf);
        }
        fclose(fpnew);
@@ -763,6 +829,18 @@ int pop3_mark_for_download(const gchar *server, const gchar *login,
        return 0;
 }
 
+int pop3_mark_for_delete(const gchar *server, const gchar *login, 
+                        const gchar *muidl, const gchar *filename)
+{
+       return pop3_mark_mail(server, login, muidl, filename, DELETE_MAIL);
+}
+
+int pop3_mark_for_download(const gchar *server, const gchar *login, 
+                        const gchar *muidl, const gchar *filename)
+{
+       return pop3_mark_mail(server, login, muidl, filename, DOWNLOAD_MAIL);
+}
+
 gint pop3_write_uidl_list(Pop3Session *session)
 {
        gchar *path;
@@ -893,22 +971,14 @@ static Pop3State pop3_lookup_next(Pop3Session *session)
                if (ac->rmmail &&
                    msg->recv_time != RECV_TIME_NONE &&
                    msg->recv_time != RECV_TIME_KEEP &&
+                   msg->partial_recv == 0 &&
                    session->current_time - msg->recv_time >=
                    ac->msg_leave_time * 24 * 60 * 60) {
-                       if (msg->partial_recv == 0) {
-                               log_message
-                                       (_("POP3: Deleting expired message "
-                                          "%d\n"), session->cur_msg);
-                               pop3_delete_send(session);
-                               return POP3_DELETE;
-                       } else if (session->current_time - msg->recv_time >=
-                                  5 * 24 * 60 * 60) {
-                               log_message
-                                       (_("POP3: Deleting too big expired "
-                                          "message %d\n"), session->cur_msg);
-                               pop3_delete_send(session);
-                               return POP3_DELETE;
-                       }
+                       log_message
+                               (_("POP3: Deleting expired message "
+                                  "%d\n"), session->cur_msg);
+                       pop3_delete_send(session);
+                       return POP3_DELETE;
                }
 
                if (size_limit_over) {
index 3ada75b6abb6d69057f870ff187a2bbf042b4628..c60ccea81ba31959969cab316dde3b244d9b1ce9 100644 (file)
--- a/src/pop.h
+++ b/src/pop.h
@@ -156,9 +156,16 @@ struct _Pop3Session
 Session *pop3_session_new      (PrefsAccount   *account);
 void pop3_get_uidl_table       (PrefsAccount   *account, Pop3Session *session);
 gint pop3_write_uidl_list      (Pop3Session    *session);
+gint pop3_msg_in_uidl_list     (const gchar    *server, 
+                                const gchar    *login, 
+                                const gchar    *uidl);
 int pop3_mark_for_download     (const gchar    *server, 
                                 const gchar    *login, 
                                 const gchar    *uidl, 
                                 const gchar    *filename);
+int pop3_mark_for_delete       (const gchar    *server, 
+                                const gchar    *login, 
+                                const gchar    *uidl, 
+                                const gchar    *filename);
 
 #endif /* __POP_H__ */