From 039506bb9afffe413ba5ad25b0c3fa8fe12314bf Mon Sep 17 00:00:00 2001 From: Colin Leroy Date: Thu, 8 Jul 2004 10:34:39 +0000 Subject: [PATCH] fix partial-downloading issues --- ChangeLog-gtk2.claws | 15 ++++++ PATCHSETS | 1 + configure.ac | 2 +- src/inc.c | 9 +++- src/messageview.c | 29 +++++++----- src/pop.c | 106 +++++++++++++++++++++++++++++-------------- src/pop.h | 7 ++- src/procmsg.c | 4 ++ 8 files changed, 123 insertions(+), 50 deletions(-) diff --git a/ChangeLog-gtk2.claws b/ChangeLog-gtk2.claws index 93d9a173f..e00b83b42 100644 --- a/ChangeLog-gtk2.claws +++ b/ChangeLog-gtk2.claws @@ -1,3 +1,18 @@ +2004-07-08 [colin] 0.9.11cvs17.13 + + * src/inc.c + * src/messageview.c + * src/pop.c + * src/pop.h + * src/procmsg.c + Fix partial-downloading issues: + catch unsupported TOP + don't delete partially downloaded mails before 5 days + don't update existing with non-MH folders; that'll + make dups, but it's better than trashing the folder + free new msginfo parts + Fix indentation ;-) + 2004-07-08 [colin] 0.9.11cvs17.12 * src/common/smtp.c diff --git a/PATCHSETS b/PATCHSETS index 0e6396cec..25f1e836e 100644 --- a/PATCHSETS +++ b/PATCHSETS @@ -6,3 +6,4 @@ 1.87.2.5 -r 1.2.4.1 1.1.4.1 1.87.2.6 src/folder.h; cvs diff -u -r 1.149.2.6 -r 1.149.2.7 src/inc.c; cvs diff -u -r 1.94.2.7 -r 1.94.2.8 src/messageview.c; cvs diff -u -r 1.47.2.5 -r 1.47.2.6 src/procheader.c; cvs diff -u -r 1.150.2.3 -r 1.150.2.4 src/procmsg.c; cvs diff -u -r 1.60.2.4 -r 1.60.2.5 src/procmsg.h; ) > 0.9.11cvs17.10.patchset ( cvs diff -u -r 1.395.2.15 -r 1.395.2.16 src/summaryview.c; cvs diff -u -r 1.204.2.11 -r 1.204.2.12 src/prefs_common.c; cvs diff -u -r 1.103.2.5 -r 1.103.2.6 src/prefs_common.h; cvs diff -u -r 1.1.2.3 -r 1.1.2.4 src/gtk/quicksearch.c; cvs diff -u -r 1.1.2.1 -r 1.1.2.2 src/gtk/quicksearch.h; ) > 0.9.11cvs17.11.patchset ( cvs diff -u -r 1.11.2.1 -r 1.11.2.2 src/common/smtp.c; cvs diff -u -r 1.6 -r 1.7 src/common/smtp.h; ) > 0.9.11cvs17.12.patchset +( 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 diff --git a/configure.ac b/configure.ac index 25d40f5af..b956220cf 100644 --- a/configure.ac +++ b/configure.ac @@ -11,7 +11,7 @@ MINOR_VERSION=9 MICRO_VERSION=11 INTERFACE_AGE=0 BINARY_AGE=0 -EXTRA_VERSION=17.12 +EXTRA_VERSION=17.13 EXTRA_RELEASE= if test \( $EXTRA_VERSION -eq 0 \) -o \( "x$EXTRA_RELEASE" != "x" \); then diff --git a/src/inc.c b/src/inc.c index 2d0c9c28d..9483d0b9b 100644 --- a/src/inc.c +++ b/src/inc.c @@ -1040,7 +1040,8 @@ static gint inc_recv_message(Session *session, const gchar *msg, gpointer data) return 0; } -static gint inc_drop_message(Pop3Session *session, const gchar *file, gboolean update_file) +static gint inc_drop_message(Pop3Session *session, const gchar *file, + gboolean update_file) { FolderItem *inbox; FolderItem *dropfolder; @@ -1061,11 +1062,15 @@ static gint inc_drop_message(Pop3Session *session, const gchar *file, gboolean u return -1; } + if (FOLDER_TYPE(inbox->folder) != F_MH) + update_file = FALSE; + /* CLAWS: claws uses a global .processing folder for the filtering. */ dropfolder = folder_get_default_processing(); /* add msg file to drop folder */ - if ((msgnum = folder_item_add_msg(dropfolder, file, NULL, !update_file)) < 0) { + if ((msgnum = folder_item_add_msg( + dropfolder, file, NULL, !update_file)) < 0) { unlink(file); return -1; } diff --git a/src/messageview.c b/src/messageview.c index d9f023339..1c35bba28 100644 --- a/src/messageview.c +++ b/src/messageview.c @@ -723,11 +723,13 @@ gint messageview_show(MessageView *messageview, MsgInfo *msginfo, mimeview_show_message(messageview->mimeview, mimeinfo, file); if (messageview->msginfo->partial_recv) - partial_recv_show(messageview->noticeview, messageview->msginfo); + partial_recv_show(messageview->noticeview, + messageview->msginfo); else if ((messageview->msginfo->dispositionnotificationto || messageview->msginfo->returnreceiptto) && !MSG_IS_RETRCPT_SENT(messageview->msginfo->flags)) - return_receipt_show(messageview->noticeview, messageview->msginfo); + return_receipt_show(messageview->noticeview, + messageview->msginfo); else noticeview_hide(messageview->noticeview); @@ -1061,18 +1063,21 @@ static void partial_recv_show(NoticeView *noticeview, MsgInfo *msginfo) { gchar *text = NULL; if (!msginfo->planned_download) { - text = g_strdup_printf(_("This message has been partially retrieved; it is %dKB large."), - msginfo->total_size/1024); + text = g_strdup_printf(_("This message has been partially " + "retrieved; it is %dKB large."), + msginfo->total_size/1024); noticeview_set_text(noticeview, text); g_free(text); noticeview_set_button_text(noticeview, _("Mark for download")); noticeview_set_button_press_callback(noticeview, - GTK_SIGNAL_FUNC(partial_recv_dload_clicked), - (gpointer) msginfo); + GTK_SIGNAL_FUNC(partial_recv_dload_clicked), + (gpointer) msginfo); noticeview_show(noticeview); } else { - text = g_strdup_printf(_("This message has been partially retrieved and is planned for download; it is %dKB large."), - msginfo->total_size/1024); + text = g_strdup_printf(_("This message has been partially " + "retrieved and is planned for " + "download; it is %dKB large."), + msginfo->total_size/1024); noticeview_set_text(noticeview, text); noticeview_set_button_text(noticeview, NULL); g_free(text); @@ -1080,7 +1085,8 @@ static void partial_recv_show(NoticeView *noticeview, MsgInfo *msginfo) } } -static void partial_recv_dload_clicked(NoticeView *noticeview, MsgInfo *msginfo) +static void partial_recv_dload_clicked(NoticeView *noticeview, + MsgInfo *msginfo) { MsgInfo *tmpmsginfo; gchar *file; @@ -1095,8 +1101,9 @@ static void partial_recv_dload_clicked(NoticeView *noticeview, MsgInfo *msginfo) tmpmsginfo->folder = msginfo->folder; tmpmsginfo->msgnum = msginfo->msgnum; - if (pop3_mark_for_download(tmpmsginfo->account_server, tmpmsginfo->account_login, - tmpmsginfo->partial_recv, file) == 0) { + if (pop3_mark_for_download(tmpmsginfo->account_server, + tmpmsginfo->account_login, + tmpmsginfo->partial_recv, file) == 0) { msginfo->planned_download = 1; partial_recv_show(noticeview, msginfo); } diff --git a/src/pop.c b/src/pop.c index ff0f9dd12..045a8a8dc 100644 --- a/src/pop.c +++ b/src/pop.c @@ -91,7 +91,8 @@ static gint pop3_session_recv_data_finished (Session *session, guchar *data, guint len); -static gchar *pop3_get_filename_for_partial_mail(Pop3Session *session, gchar *muidl); +static gchar *pop3_get_filename_for_partial_mail(Pop3Session *session, + gchar *muidl); static gint pop3_greeting_recv(Pop3Session *session, const gchar *msg) { @@ -260,10 +261,12 @@ static gint pop3_getrange_uidl_recv(Pop3Session *session, const gchar *data, session->msg[num].uidl = g_strdup(id); - recv_time = (time_t)g_hash_table_lookup(session->uidl_table, id); + recv_time = (time_t)g_hash_table_lookup( + session->uidl_table, id); session->msg[num].recv_time = recv_time; - partial_recv = (gint)g_hash_table_lookup(session->partial_recv_table, id); + partial_recv = (gint)g_hash_table_lookup( + session->partial_recv_table, id); if (!session->ac_prefs->getall && recv_time != RECV_TIME_NONE) { session->msg[num].received = (partial_recv != 2); @@ -351,16 +354,20 @@ static gint pop3_retr_recv(Pop3Session *session, const gchar *data, guint len) g_free(mail_receive_data.data); if (session->msg[session->cur_msg].partial_recv == 2) { - gchar *old_file = pop3_get_filename_for_partial_mail(session, session->msg[session->cur_msg].uidl); - unlink(old_file); - rename(file, old_file); - g_free(file); - file = old_file; + gchar *old_file = pop3_get_filename_for_partial_mail( + session, session->msg[session->cur_msg].uidl); + if (old_file != NULL) { + move_file(file, old_file, TRUE); + g_free(file); + file = old_file; + } /* drop_ok: 0: success 1: don't receive -1: error */ - drop_ok = session->drop_message(session, file, TRUE); + drop_ok = session->drop_message( + session, file, old_file != NULL); } else { /* drop_ok: 0: success 1: don't receive -1: error */ - drop_ok = session->drop_message(session, file, FALSE); + drop_ok = session->drop_message( + session, file, FALSE); } g_free(file); if (drop_ok < 0) { @@ -368,7 +375,6 @@ static gint pop3_retr_recv(Pop3Session *session, const gchar *data, guint len) return -1; } -stats: session->cur_total_bytes += session->msg[session->cur_msg].size; session->cur_total_recv_bytes += session->msg[session->cur_msg].size; session->cur_total_num++; @@ -382,10 +388,11 @@ stats: return PS_SUCCESS; } -static gint pop3_top_send(Pop3Session *session) +static gint pop3_top_send(Pop3Session *session, gint max_size) { + gint num_lines = (max_size*1024)/82; /* consider lines to be 80 chars */ session->state = POP3_TOP; - pop3_gen_send(session, "TOP %d 10", session->cur_msg); + pop3_gen_send(session, "TOP %d %d", session->cur_msg, num_lines); return PS_SUCCESS; } @@ -533,7 +540,7 @@ static void pop3_session_destroy(Session *session) g_free(pop3_session->error_msg); } -GHashTable *pop3_get_uidl_table(PrefsAccount *ac_prefs, Pop3Session *session) +void pop3_get_uidl_table(PrefsAccount *ac_prefs, Pop3Session *session) { GHashTable *table; GHashTable *partial_recv_table; @@ -562,7 +569,7 @@ GHashTable *pop3_get_uidl_table(PrefsAccount *ac_prefs, Pop3Session *session) g_free(path); session->uidl_table = table; session->partial_recv_table = partial_recv_table; - return table; + return; } } g_free(path); @@ -599,10 +606,11 @@ GHashTable *pop3_get_uidl_table(PrefsAccount *ac_prefs, Pop3Session *session) session->uidl_table = table; session->partial_recv_table = partial_recv_table; - return table; + return; } -static gchar *pop3_get_filename_for_partial_mail(Pop3Session *session, gchar *muidl) +static gchar *pop3_get_filename_for_partial_mail(Pop3Session *session, + gchar *muidl) { gchar *path; gchar *result = NULL; @@ -614,7 +622,8 @@ static gchar *pop3_get_filename_for_partial_mail(Pop3Session *session, gchar *mu gint partial_recv; path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, - "uidl", G_DIR_SEPARATOR_S, session->ac_prefs->recv_server, + "uidl", G_DIR_SEPARATOR_S, + session->ac_prefs->recv_server, "-", session->ac_prefs->userid, NULL); if ((fp = fopen(path, "rb")) == NULL) { if (ENOENT != errno) FILE_OP_ERROR(path, "fopen"); @@ -656,7 +665,8 @@ static gchar *pop3_get_filename_for_partial_mail(Pop3Session *session, gchar *mu return result; } -int pop3_mark_for_download(const gchar *server, const gchar *login, const gchar *muidl, const gchar *filename) +int pop3_mark_for_download(const gchar *server, const gchar *login, + const gchar *muidl, const gchar *filename) { gchar *path; gchar *pathnew; @@ -704,7 +714,8 @@ int pop3_mark_for_download(const gchar *server, const gchar *login, const gchar recv_time = RECV_TIME_NONE; sprintf(partial_recv,"0"); - if (sscanf(buf, "%s\t%ld\t%s", uidl, &recv_time, &partial_recv) < 2) { + if (sscanf(buf, "%s\t%ld\t%s", + uidl, &recv_time, &partial_recv) < 2) { if (sscanf(buf, "%s", uidl) != 1) continue; else { @@ -712,17 +723,18 @@ int pop3_mark_for_download(const gchar *server, const gchar *login, const gchar } } if (strcmp(muidl, uidl)) { - fprintf(fpnew, "%s\t%ld\t%s\n", uidl, recv_time, partial_recv); + fprintf(fpnew, "%s\t%ld\t%s\n", + uidl, recv_time, partial_recv); } else { - fprintf(fpnew, "%s\t%ld\t%s\n", uidl, recv_time, filename); + fprintf(fpnew, "%s\t%ld\t%s\n", + uidl, recv_time, filename); } } fclose(fpnew); fclose(fp); - unlink(path); - rename(pathnew, path); - + move_file(pathnew, path, TRUE); + g_free(path); g_free(pathnew); @@ -773,7 +785,8 @@ gint pop3_write_uidl_list(Pop3Session *session) for (n = 1; n <= session->count; n++) { msg = &session->msg[n]; if (msg->uidl && msg->received && !msg->deleted) { - fprintf(fp, "%s\t%ld\t%d\n", msg->uidl, msg->recv_time, msg->partial_recv); + fprintf(fp, "%s\t%ld\t%d\n", + msg->uidl, msg->recv_time, msg->partial_recv); } } @@ -882,11 +895,20 @@ static Pop3State pop3_lookup_next(Pop3Session *session) msg->recv_time != RECV_TIME_KEEP && session->current_time - msg->recv_time >= ac->msg_leave_time * 24 * 60 * 60) { - log_message - (_("POP3: Deleting expired message %d\n"), - session->cur_msg); - pop3_delete_send(session); - return POP3_DELETE; + 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; + } } if (size_limit_over) { @@ -895,7 +917,7 @@ static Pop3State pop3_lookup_next(Pop3Session *session) session->cur_msg, size); if (!msg->received && msg->partial_recv != 2) { - pop3_top_send(session); + pop3_top_send(session, ac->size_limit); return POP3_TOP; } else if (msg->partial_recv == 2) { break; @@ -951,9 +973,11 @@ static Pop3ErrorValue pop3_ok(Pop3Session *session, const gchar *msg) break; case POP3_GETRANGE_LAST: case POP3_GETRANGE_UIDL: + case POP3_TOP: log_warning(_("command not supported\n")); ok = PS_NOTSUPPORTED; break; + default: log_warning(_("error occurred on POP3 session\n")); ok = PS_ERROR; @@ -1065,8 +1089,12 @@ static gint pop3_session_recv_msg(Session *session, const gchar *msg) session_recv_data(session, 0, ".\r\n"); break; case POP3_TOP: - pop3_session->state = POP3_TOP_RECV; - session_recv_data(session, 0, ".\r\n"); + if (val == PS_NOTSUPPORTED) { + pop3_session->error_val = PS_SUCCESS; + } else { + pop3_session->state = POP3_TOP_RECV; + session_recv_data(session, 0, ".\r\n"); + } break; case POP3_DELETE: pop3_delete_recv(pop3_session); @@ -1143,6 +1171,16 @@ static gint pop3_session_recv_data_finished(Session *session, guchar *data, return -1; } break; + case POP3_TOP: + log_warning(_("TOP command unsupported\n")); + if (pop3_session->cur_msg == pop3_session->count) + pop3_logout_send(pop3_session); + else { + pop3_session->cur_msg++; + if (pop3_lookup_next(pop3_session) == POP3_ERROR) + return -1; + } + break; case POP3_ERROR: default: return -1; diff --git a/src/pop.h b/src/pop.h index ef7a31cf7..3ada75b6a 100644 --- a/src/pop.h +++ b/src/pop.h @@ -154,8 +154,11 @@ struct _Pop3Session Session *pop3_session_new (PrefsAccount *account); -GHashTable *pop3_get_uidl_table (PrefsAccount *account, Pop3Session *session); +void pop3_get_uidl_table (PrefsAccount *account, Pop3Session *session); gint pop3_write_uidl_list (Pop3Session *session); -int pop3_mark_for_download(const gchar *server, const gchar *login, const gchar *uidl, const gchar *filename); +int pop3_mark_for_download (const gchar *server, + const gchar *login, + const gchar *uidl, + const gchar *filename); #endif /* __POP_H__ */ diff --git a/src/procmsg.c b/src/procmsg.c index f9b7cd6a1..dfd47a332 100644 --- a/src/procmsg.c +++ b/src/procmsg.c @@ -942,6 +942,10 @@ void procmsg_msginfo_free(MsgInfo *msginfo) g_free(msginfo->inreplyto); g_free(msginfo->xref); + g_free(msginfo->partial_recv); + g_free(msginfo->account_server); + g_free(msginfo->account_login); + g_free(msginfo); } -- 2.25.1