add ability to leave downloaded mail on server for n days
authorPaul Mangan <paul@claws-mail.org>
Tue, 19 Mar 2002 17:13:22 +0000 (17:13 +0000)
committerPaul Mangan <paul@claws-mail.org>
Tue, 19 Mar 2002 17:13:22 +0000 (17:13 +0000)
ChangeLog.claws
configure.in
src/inc.c
src/inc.h
src/pop.c
src/prefs_account.c
src/prefs_account.h

index ffc44e9104626b73e26181915983b70fa9ef9f38..a058a97eb6e2906895dd77e093a39bea3e23557a 100644 (file)
@@ -1,3 +1,12 @@
+2002-03-19 [paul]      0.7.4claws24
+
+       * src/inc.[ch]
+         src/pop.c
+         src/prefs_account.[ch]
+               allow the user to leave downloaded mail on the 
+               server for n days. Patch submitted by Colin Leroy 
+               <colin@colino.net>
+
 2002-02-19 [paul]      0.7.4claws23
 
        * sync with sylpheed 0.7.4cvs8
 2002-02-19 [paul]      0.7.4claws23
 
        * sync with sylpheed 0.7.4cvs8
index 4f716f93a6136c021d1bf9f39808b5680d50f8c4..8b888ae1c416c64dcc1ff0198e694e848186ef31 100644 (file)
@@ -8,7 +8,7 @@ MINOR_VERSION=7
 MICRO_VERSION=4
 INTERFACE_AGE=0
 BINARY_AGE=0
 MICRO_VERSION=4
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws23
+EXTRA_VERSION=claws24
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
index 37b535a3534d2bd7b982e7e74698ae8ce42a6a0c..9ef4d97dda207ef1971b9183e3a199c9b3320c89 100644 (file)
--- a/src/inc.c
+++ b/src/inc.c
@@ -420,6 +420,7 @@ static Pop3State *inc_pop3_state_new(PrefsAccount *account)
 
        state->ac_prefs = account;
        state->folder_table = g_hash_table_new(NULL, NULL);
 
        state->ac_prefs = account;
        state->folder_table = g_hash_table_new(NULL, NULL);
+       state->uidl_todelete_list = NULL;
        state->uidl_table = inc_get_uidl_table(account);
        state->inc_state = INC_SUCCESS;
 
        state->uidl_table = inc_get_uidl_table(account);
        state->inc_state = INC_SUCCESS;
 
@@ -440,7 +441,7 @@ static void inc_pop3_state_destroy(Pop3State *state)
                hash_free_strings(state->uidl_table);
                g_hash_table_destroy(state->uidl_table);
        }
                hash_free_strings(state->uidl_table);
                g_hash_table_destroy(state->uidl_table);
        }
-
+       g_slist_free(state->uidl_todelete_list);
        g_free(state->greeting);
        g_free(state->user);
        g_free(state->pass);
        g_free(state->greeting);
        g_free(state->user);
        g_free(state->pass);
@@ -784,8 +785,23 @@ static GHashTable *inc_get_uidl_table(PrefsAccount *ac_prefs)
        table = g_hash_table_new(g_str_hash, g_str_equal);
 
        while (fgets(buf, sizeof(buf), fp) != NULL) {
        table = g_hash_table_new(g_str_hash, g_str_equal);
 
        while (fgets(buf, sizeof(buf), fp) != NULL) {
+               gchar **data = NULL;
+               GDate *curdate = g_date_new();
+
+               g_date_set_time(curdate, time(NULL));   
                strretchomp(buf);
                strretchomp(buf);
-               g_hash_table_insert(table, g_strdup(buf), GINT_TO_POINTER(1));
+               
+               /* data[0] will contain uidl
+                  data[1] will contain day of retrieval */
+               if( strchr(buf, '\t') ) {
+                       data = g_strsplit(buf,"\t",2);
+                       snprintf(data[1], sizeof(data[1]), "%d", g_date_day_of_year(curdate) );
+               }
+               else {
+                       data[0] = g_strdup(buf);
+                       snprintf(data[1], sizeof(data[1]), "%d", g_date_day_of_year(curdate) );
+               }
+               g_hash_table_insert(table, g_strdup(data[0]), g_strdup(data[1]));
        }
 
        fclose(fp);
        }
 
        fclose(fp);
@@ -798,7 +814,8 @@ static void inc_write_uidl_list(Pop3State *state)
        gchar *path;
        FILE *fp;
        gint n;
        gchar *path;
        FILE *fp;
        gint n;
-
+       GDate *curdate = g_date_new();
+       g_date_set_time(curdate, time(NULL));
        if (!state->uidl_is_valid) return;
 
        path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
        if (!state->uidl_is_valid) return;
 
        path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
@@ -817,10 +834,33 @@ static void inc_write_uidl_list(Pop3State *state)
                                FILE_OP_ERROR(path, "fputs");
                                break;
                        }
                                FILE_OP_ERROR(path, "fputs");
                                break;
                        }
-                       if (fputc('\n', fp) == EOF) {
+                       if (fputc('\t', fp) == EOF) {
                                FILE_OP_ERROR(path, "fputc");
                                break;
                        }
                                FILE_OP_ERROR(path, "fputc");
                                break;
                        }
+                       if(g_hash_table_lookup(state->uidl_table, state->msg[n].uidl ) != NULL) {
+                               const char *sdate = g_hash_table_lookup(state->uidl_table, state->msg[n].uidl);
+                               int tdate = g_date_day_of_year(curdate);
+                               if(sdate != NULL)
+                                       tdate = atoi(sdate);
+
+                               if(fprintf(fp, "%3d", tdate) == EOF) {
+                                       FILE_OP_ERROR(path, "fprintf");
+                                       break;
+                               }
+                       } else {
+                               if(fprintf(fp, "%d", g_date_day_of_year(curdate)) == EOF) {
+                                       FILE_OP_ERROR(path, "fputs");
+                                       break;
+                               }
+
+                       }
+
+                       if (fputc('\n', fp) == EOF) {
+                               FILE_OP_ERROR(path, "fputc");
+                               break;
+                       }               
+                       
                }
        }
 
                }
        }
 
index 6da9fc8188f28e7adc8ea69a5b57602552a7cf1a..76f643c7444c791636d741c57faad71390b4f59a 100644 (file)
--- a/src/inc.h
+++ b/src/inc.h
@@ -89,7 +89,8 @@ struct _Pop3State
        Pop3MsgInfo *msg;
 
        GHashTable *uidl_table;
        Pop3MsgInfo *msg;
 
        GHashTable *uidl_table;
-
+       GSList *uidl_todelete_list;
+       
        gboolean uidl_is_valid;
 
        gint error_val;
        gboolean uidl_is_valid;
 
        gint error_val;
index 052c8a38f7b0a88c4d35ac6fb918dc1b7fe022c3..c74573f1376ea9d13fcd476db04ee1e05e21b80e 100644 (file)
--- a/src/pop.c
+++ b/src/pop.c
@@ -288,7 +288,7 @@ gint pop3_getrange_uidl_recv(SockInfo *sock, gpointer data)
        if (pop3_ok(sock, NULL) != PS_SUCCESS) return POP3_GETRANGE_LAST_SEND;
 
        if (!state->uidl_table) new = TRUE;
        if (pop3_ok(sock, NULL) != PS_SUCCESS) return POP3_GETRANGE_LAST_SEND;
 
        if (!state->uidl_table) new = TRUE;
-       if (state->ac_prefs->rmmail || state->ac_prefs->getall)
+       if (state->ac_prefs->getall)
                get_all = TRUE;
 
        while (sock_gets(sock, buf, sizeof(buf)) >= 0) {
                get_all = TRUE;
 
        while (sock_gets(sock, buf, sizeof(buf)) >= 0) {
@@ -312,6 +312,11 @@ gint pop3_getrange_uidl_recv(SockInfo *sock, gpointer data)
                                }
                        }
                }
                                }
                        }
                }
+
+               if(should_delete(buf, (Pop3State *)state))
+                       state->uidl_todelete_list = g_slist_append
+                                       (state->uidl_todelete_list, g_strdup(buf));             
+               
        }
 
        state->uidl_is_valid = TRUE;
        }
 
        state->uidl_is_valid = TRUE;
@@ -321,6 +326,32 @@ gint pop3_getrange_uidl_recv(SockInfo *sock, gpointer data)
        else
                return POP3_LOGOUT_SEND;
 }
        else
                return POP3_LOGOUT_SEND;
 }
+gboolean should_delete(char * uidl, gpointer data) {
+       Pop3State *state = (Pop3State *)data;
+       /* answer[0] will contain id
+          answer[0] will contain uidl */
+       gchar **answer;
+       GDate *curdate = g_date_new();
+       int id = 0;
+       g_date_set_time(curdate, time(NULL));
+       if( state->ac_prefs->rmmail && strchr(uidl,' ') ) {
+               /* remove \r\n */
+               uidl = g_strndup(uidl, strlen(uidl)-2);
+               answer = g_strsplit(uidl, " ", 2);
+               id = atoi(answer[0]);
+               if( g_hash_table_lookup(state->uidl_table, answer[1]) != NULL ) {
+                       gchar *sdate = g_hash_table_lookup(state->uidl_table, answer[1]);
+                       int tdate = atoi(sdate);
+                       int keep_for = atoi(state->ac_prefs->leave_time);
+                       int today = g_date_day_of_year(curdate);
+                       int nb_days = 365;
+                       if ( g_date_is_leap_year (g_date_year(curdate)) ) 
+                               nb_days = 366;
+                       return ( (tdate + keep_for)%nb_days <= today );
+               }
+       }
+       return FALSE;
+}
 
 gint pop3_getsize_list_send(SockInfo *sock, gpointer data)
 {
 
 gint pop3_getsize_list_send(SockInfo *sock, gpointer data)
 {
@@ -434,7 +465,8 @@ gint pop3_retr_recv(SockInfo *sock, gpointer data)
        Pop3State *state = (Pop3State *)data;
        const gchar *file;
        gint ok, drop_ok;
        Pop3State *state = (Pop3State *)data;
        const gchar *file;
        gint ok, drop_ok;
-
+       int keep_for=atoi(g_strdup(state->ac_prefs->leave_time));
+       
        if ((ok = pop3_ok(sock, NULL)) == PS_SUCCESS) {
                if (recv_write_to_file(sock, (file = get_tmp_file())) < 0) {
                        if (state->inc_state == INC_SUCCESS)
        if ((ok = pop3_ok(sock, NULL)) == PS_SUCCESS) {
                if (recv_write_to_file(sock, (file = get_tmp_file())) < 0) {
                        if (state->inc_state == INC_SUCCESS)
@@ -446,12 +478,13 @@ gint pop3_retr_recv(SockInfo *sock, gpointer data)
                        state->inc_state = INC_ERROR;
                        return -1;
                }
                        state->inc_state = INC_ERROR;
                        return -1;
                }
-
+       
                state->cur_total_bytes += state->msg[state->cur_msg].size;
                state->cur_total_num++;
 
                state->cur_total_bytes += state->msg[state->cur_msg].size;
                state->cur_total_num++;
 
-               if (drop_ok == 0 && state->ac_prefs->rmmail)
+               if (drop_ok == 0 && state->ac_prefs->rmmail && keep_for == 0) {
                        return POP3_DELETE_SEND;
                        return POP3_DELETE_SEND;
+               }
 
                state->msg[state->cur_msg].received = TRUE;
 
 
                state->msg[state->cur_msg].received = TRUE;
 
@@ -505,7 +538,17 @@ gint pop3_delete_recv(SockInfo *sock, gpointer data)
 gint pop3_logout_send(SockInfo *sock, gpointer data)
 {
        Pop3State *state = (Pop3State *)data;
 gint pop3_logout_send(SockInfo *sock, gpointer data)
 {
        Pop3State *state = (Pop3State *)data;
-
+       while (state->uidl_todelete_list != NULL) {
+               gchar **parts;
+               gint ok;
+               parts=g_strsplit((gchar *)state->uidl_todelete_list->data," ",2);
+               state->uidl_todelete_list = g_slist_remove(
+                                       state->uidl_todelete_list, state->uidl_todelete_list->data);
+               pop3_gen_send(sock, "DELE %s",parts[0]);
+               if ((ok = pop3_ok(sock, NULL)) != PS_SUCCESS)
+                       log_warning(_("error occurred on DELE\n"));
+       }
+       
        inc_progress_update(state, POP3_LOGOUT_SEND);
 
        pop3_gen_send(sock, "QUIT");
        inc_progress_update(state, POP3_LOGOUT_SEND);
 
        pop3_gen_send(sock, "QUIT");
index 252322c8884cdd9d378c5341c363c20fb7e89e4a..25b62ce799d50b8664ee97bbc467ecb92d15583f 100644 (file)
@@ -86,6 +86,7 @@ static struct Basic {
 static struct Receive {
        GtkWidget *pop3_frame;
        GtkWidget *rmmail_chkbtn;
 static struct Receive {
        GtkWidget *pop3_frame;
        GtkWidget *rmmail_chkbtn;
+       GtkWidget *leave_time_entry;
        GtkWidget *getall_chkbtn;
        GtkWidget *size_limit_chkbtn;
        GtkWidget *size_limit_entry;
        GtkWidget *getall_chkbtn;
        GtkWidget *size_limit_chkbtn;
        GtkWidget *size_limit_entry;
@@ -248,6 +249,10 @@ static PrefParam param[] = {
        {"remove_mail", "TRUE", &tmp_ac_prefs.rmmail, P_BOOL,
         &receive.rmmail_chkbtn,
         prefs_set_data_from_toggle, prefs_set_toggle},
        {"remove_mail", "TRUE", &tmp_ac_prefs.rmmail, P_BOOL,
         &receive.rmmail_chkbtn,
         prefs_set_data_from_toggle, prefs_set_toggle},
+       
+       {"leave_mail_time", "0", &tmp_ac_prefs.leave_time, P_STRING,
+        &receive.leave_time_entry,
+        prefs_set_data_from_entry, prefs_set_entry},
 
        {"get_all_mail", "FALSE", &tmp_ac_prefs.getall, P_BOOL,
         &receive.getall_chkbtn,
 
        {"get_all_mail", "FALSE", &tmp_ac_prefs.getall, P_BOOL,
         &receive.getall_chkbtn,
@@ -988,8 +993,12 @@ static void prefs_account_receive_create(void)
        GtkWidget *label;
        GtkWidget *filter_on_recv_chkbtn;
        GtkWidget *vbox3;
        GtkWidget *label;
        GtkWidget *filter_on_recv_chkbtn;
        GtkWidget *vbox3;
+       GtkWidget *hbox2;
        GtkWidget *inbox_label;
        GtkWidget *inbox_entry;
        GtkWidget *inbox_label;
        GtkWidget *inbox_entry;
+       GtkWidget *leave_time_entry;
+       GtkWidget *leave_time_label;
+       GtkWidget *leave_time_hint;     
        GtkWidget *inbox_btn;
        GtkWidget *frame2;
        GtkWidget *imapdir_label;
        GtkWidget *inbox_btn;
        GtkWidget *frame2;
        GtkWidget *imapdir_label;
@@ -1008,8 +1017,26 @@ static void prefs_account_receive_create(void)
        gtk_container_add (GTK_CONTAINER (frame1), vbox2);
        gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
 
        gtk_container_add (GTK_CONTAINER (frame1), vbox2);
        gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
 
-       PACK_CHECK_BUTTON (vbox2, rmmail_chkbtn,
-                          _("Remove messages on server when received"));
+       hbox2 = gtk_hbox_new (FALSE, 0);
+       gtk_widget_show (hbox2);
+       gtk_container_add (GTK_CONTAINER (vbox2), hbox2);
+       gtk_container_set_border_width (GTK_CONTAINER (hbox2), 0);
+
+       PACK_CHECK_BUTTON (hbox2, rmmail_chkbtn,
+                          _("Remove messages on server when received for "));
+       leave_time_entry = gtk_entry_new ();
+       gtk_widget_show (leave_time_entry);
+       gtk_widget_set_usize (leave_time_entry, DEFAULT_ENTRY_WIDTH, -1);
+       gtk_box_pack_start (GTK_BOX (hbox2), leave_time_entry, TRUE, TRUE, 0);
+       
+       leave_time_label = gtk_label_new (_(" days"));
+       gtk_widget_show (leave_time_label);
+       gtk_box_pack_start (GTK_BOX (hbox2), leave_time_label, FALSE, FALSE, 0);
+       
+       leave_time_hint=gtk_label_new (_("(Setting to 0 days will delete messages immediately)"));
+       gtk_widget_show(leave_time_hint);
+       gtk_box_pack_start (GTK_BOX (vbox2), leave_time_hint, FALSE, FALSE, 0);
+               
        PACK_CHECK_BUTTON (vbox2, getall_chkbtn,
                           _("Download all messages on server"));
 
        PACK_CHECK_BUTTON (vbox2, getall_chkbtn,
                           _("Download all messages on server"));
 
@@ -1092,6 +1119,7 @@ static void prefs_account_receive_create(void)
 
        receive.pop3_frame            = frame1;
        receive.rmmail_chkbtn         = rmmail_chkbtn;
 
        receive.pop3_frame            = frame1;
        receive.rmmail_chkbtn         = rmmail_chkbtn;
+       receive.leave_time_entry      = leave_time_entry;
        receive.getall_chkbtn         = getall_chkbtn;
        receive.size_limit_chkbtn     = size_limit_chkbtn;
        receive.size_limit_entry      = size_limit_entry;
        receive.getall_chkbtn         = getall_chkbtn;
        receive.size_limit_chkbtn     = size_limit_chkbtn;
        receive.size_limit_entry      = size_limit_entry;
index 139f9bb801c6641225dfbda60a8d3e77fd4f7d10..45f1d7f6554ab0c0a77649cd1bfcec646bcbbac4 100644 (file)
@@ -102,6 +102,7 @@ struct _PrefsAccount
 
        /* Receive */
        gboolean rmmail;
 
        /* Receive */
        gboolean rmmail;
+       gchar *leave_time;      
        gboolean getall;
        gboolean recv_at_getall;
        gboolean enable_size_limit;
        gboolean getall;
        gboolean recv_at_getall;
        gboolean enable_size_limit;