2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2003 Hiroyuki Yamamoto
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #include <gtk/gtkmain.h>
28 #include <gtk/gtkwindow.h>
29 #include <gtk/gtksignal.h>
30 #include <gtk/gtkprogressbar.h>
35 #include <sys/types.h>
44 #include "mainwindow.h"
45 #include "folderview.h"
46 #include "summaryview.h"
47 #include "prefs_common.h"
48 #include "prefs_account.h"
58 #include "statusbar.h"
59 #include "manage_window.h"
60 #include "stock_pixmap.h"
61 #include "progressdialog.h"
62 #include "inputdialog.h"
63 #include "alertpanel.h"
65 #include "filtering.h"
69 static GList *inc_dialog_list = NULL;
71 static guint inc_lock_count = 0;
73 static GdkPixmap *currentxpm;
74 static GdkBitmap *currentxpmmask;
75 static GdkPixmap *errorxpm;
76 static GdkBitmap *errorxpmmask;
77 static GdkPixmap *okxpm;
78 static GdkBitmap *okxpmmask;
80 #define MSGBUFSIZE 8192
82 static void inc_finished (MainWindow *mainwin,
83 gboolean new_messages);
84 static gint inc_account_mail (PrefsAccount *account,
87 static IncProgressDialog *inc_progress_dialog_create (void);
88 static void inc_progress_dialog_destroy (IncProgressDialog *inc_dialog);
90 static IncSession *inc_session_new (PrefsAccount *account);
91 static void inc_session_destroy (IncSession *session);
92 static gint inc_start (IncProgressDialog *inc_dialog);
93 static IncState inc_pop3_session_do (IncSession *session);
95 static gint inc_recv_data_progressive (Session *session,
99 static gint inc_recv_data_finished (Session *session,
102 static gint inc_recv_message (Session *session,
106 static void inc_put_error (IncState istate,
109 static void inc_cancel_cb (GtkWidget *widget,
111 static gint inc_dialog_delete_cb (GtkWidget *widget,
115 static gint inc_spool (void);
116 static gint get_spool (FolderItem *dest,
119 static gint inc_spool_account(PrefsAccount *account);
120 static gint inc_all_spool(void);
121 static void inc_autocheck_timer_set_interval (guint interval);
122 static gint inc_autocheck_func (gpointer data);
124 static void inc_notify_cmd (gint new_msgs,
127 #define FOLDER_SUMMARY_MISMATCH(f, s) \
128 (f) && (s) ? ((s)->newmsgs != (f)->new_msgs) || ((f)->unread_msgs != (s)->unread) || ((f)->total_msgs != (s)->messages) \
133 * @mainwin: Main window.
134 * @new_messages: TRUE if some messages have been received.
136 * Update the folder view and the summary view after receiving
137 * messages. If @new_messages is FALSE, this function avoids unneeded
140 static void inc_finished(MainWindow *mainwin, gboolean new_messages)
144 if (prefs_common.scan_all_after_inc)
145 folderview_check_new(NULL);
147 if (!new_messages && !prefs_common.scan_all_after_inc) return;
149 if (prefs_common.open_inbox_on_inc) {
150 item = cur_account && cur_account->inbox
151 ? folder_find_item_from_identifier(cur_account->inbox)
152 : folder_get_default_inbox();
153 if (FOLDER_SUMMARY_MISMATCH(item, mainwin->summaryview)) {
154 folderview_unselect(mainwin->folderview);
155 folderview_select(mainwin->folderview, item);
160 void inc_mail(MainWindow *mainwin, gboolean notify)
163 gint account_new_msgs = 0;
165 if (inc_lock_count) return;
167 if (prefs_common.work_offline)
168 if (alertpanel(_("Offline warning"),
169 _("You're working offline. Override?"),
170 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
174 inc_autocheck_timer_remove();
175 main_window_lock(mainwin);
177 if (prefs_common.use_extinc && prefs_common.extinc_cmd) {
178 /* external incorporating program */
179 if (execute_command_line(prefs_common.extinc_cmd, FALSE) < 0) {
180 main_window_unlock(mainwin);
181 inc_autocheck_timer_set();
185 if (prefs_common.inc_local) {
186 account_new_msgs = inc_spool();
187 if (account_new_msgs > 0)
188 new_msgs += account_new_msgs;
191 if (prefs_common.inc_local) {
192 account_new_msgs = inc_spool();
193 if (account_new_msgs > 0)
194 new_msgs += account_new_msgs;
196 cur_account->session = STYPE_NORMAL;
197 account_new_msgs = inc_account_mail(cur_account, mainwin);
198 if (account_new_msgs > 0)
199 new_msgs += account_new_msgs;
202 inc_finished(mainwin, new_msgs > 0);
203 main_window_unlock(mainwin);
204 inc_notify_cmd(new_msgs, notify);
205 inc_autocheck_timer_set();
209 void inc_pop_before_smtp(PrefsAccount *acc)
211 acc->session = STYPE_POP_BEFORE_SMTP;
212 inc_account_mail(acc, NULL);
215 static gint inc_account_mail(PrefsAccount *account, MainWindow *mainwin)
217 IncProgressDialog *inc_dialog;
220 FolderItem *item = NULL;
222 if(mainwin && mainwin->summaryview)
223 item = mainwin->summaryview->folder_item;
225 switch (account->protocol) {
229 * FIXME: it should return foldeview_check_new() value.
230 * TODO: do it when bug [19] is fixed (IMAP folder sets
231 * an incorrect new message count)
233 folderview_check_new(FOLDER(account->folder));
237 session = inc_session_new(account);
238 if (!session) return 0;
240 inc_dialog = inc_progress_dialog_create();
241 inc_dialog->queue_list = g_list_append(inc_dialog->queue_list,
243 inc_dialog->mainwin = mainwin;
244 session->data = inc_dialog;
247 text[1] = account->account_name;
248 text[2] = _("Standby");
249 gtk_clist_append(GTK_CLIST(inc_dialog->dialog->clist), text);
252 toolbar_main_set_sensitive(mainwin);
253 main_window_set_menu_sensitive(mainwin);
256 return inc_start(inc_dialog);
259 return inc_spool_account(account);
267 void inc_all_account_mail(MainWindow *mainwin, gboolean notify)
269 GList *list, *queue_list = NULL;
270 IncProgressDialog *inc_dialog;
272 gint account_new_msgs = 0;
274 if (prefs_common.work_offline)
275 if (alertpanel(_("Offline warning"),
276 _("You're working offline. Override?"),
277 _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
280 if (inc_lock_count) return;
282 inc_autocheck_timer_remove();
283 main_window_lock(mainwin);
285 if (prefs_common.inc_local) {
286 account_new_msgs = inc_spool();
287 if (account_new_msgs > 0)
288 new_msgs += account_new_msgs;
291 list = account_get_list();
293 inc_finished(mainwin, new_msgs > 0);
294 main_window_unlock(mainwin);
295 inc_notify_cmd(new_msgs, notify);
296 inc_autocheck_timer_set();
300 /* check local folders */
301 account_new_msgs = inc_all_spool();
302 if (account_new_msgs > 0)
303 new_msgs += account_new_msgs;
305 /* check IMAP4 folders */
306 for (; list != NULL; list = list->next) {
307 PrefsAccount *account = list->data;
308 if ((account->protocol == A_IMAP4 ||
309 account->protocol == A_NNTP) && account->recv_at_getall) {
310 new_msgs += folderview_check_new(FOLDER(account->folder));
314 /* check POP3 accounts */
315 for (list = account_get_list(); list != NULL; list = list->next) {
317 PrefsAccount *account = list->data;
318 account->session = STYPE_NORMAL;
319 if (account->recv_at_getall) {
320 session = inc_session_new(account);
322 queue_list = g_list_append(queue_list, session);
327 inc_finished(mainwin, new_msgs > 0);
328 main_window_unlock(mainwin);
329 inc_notify_cmd(new_msgs, notify);
330 inc_autocheck_timer_set();
334 inc_dialog = inc_progress_dialog_create();
335 inc_dialog->queue_list = queue_list;
336 inc_dialog->mainwin = mainwin;
337 for (list = queue_list; list != NULL; list = list->next) {
338 IncSession *session = list->data;
339 Pop3Session *pop3_session = POP3_SESSION(session->session);
342 session->data = inc_dialog;
345 text[1] = pop3_session->ac_prefs->account_name;
346 text[2] = _("Standby");
347 gtk_clist_append(GTK_CLIST(inc_dialog->dialog->clist), text);
350 toolbar_main_set_sensitive(mainwin);
351 main_window_set_menu_sensitive(mainwin);
353 new_msgs += inc_start(inc_dialog);
354 inc_finished(mainwin, new_msgs > 0);
355 main_window_unlock(mainwin);
356 inc_notify_cmd(new_msgs, notify);
357 inc_autocheck_timer_set();
360 static IncProgressDialog *inc_progress_dialog_create(void)
362 IncProgressDialog *dialog;
363 ProgressDialog *progress;
365 dialog = g_new0(IncProgressDialog, 1);
367 progress = progress_dialog_create();
368 gtk_window_set_title(GTK_WINDOW(progress->window),
369 _("Retrieving new messages"));
370 gtk_signal_connect(GTK_OBJECT(progress->cancel_btn), "clicked",
371 GTK_SIGNAL_FUNC(inc_cancel_cb), dialog);
372 gtk_signal_connect(GTK_OBJECT(progress->window), "delete_event",
373 GTK_SIGNAL_FUNC(inc_dialog_delete_cb), dialog);
374 /* manage_window_set_transient(GTK_WINDOW(progress->window)); */
376 progress_dialog_set_value(progress, 0.0);
378 stock_pixmap_gdk(progress->clist, STOCK_PIXMAP_COMPLETE,
380 stock_pixmap_gdk(progress->clist, STOCK_PIXMAP_CONTINUE,
381 ¤txpm, ¤txpmmask);
382 stock_pixmap_gdk(progress->clist, STOCK_PIXMAP_ERROR,
383 &errorxpm, &errorxpmmask);
385 if (prefs_common.recv_dialog_mode == RECV_DIALOG_ALWAYS ||
386 (prefs_common.recv_dialog_mode == RECV_DIALOG_ACTIVE &&
387 manage_window_get_focus_window())) {
388 dialog->show_dialog = TRUE;
389 gtk_widget_show_now(progress->window);
392 dialog->dialog = progress;
393 dialog->queue_list = NULL;
395 inc_dialog_list = g_list_append(inc_dialog_list, dialog);
400 static void inc_progress_dialog_clear(IncProgressDialog *inc_dialog)
402 progress_dialog_set_value(inc_dialog->dialog, 0.0);
403 progress_dialog_set_label(inc_dialog->dialog, "");
404 if (inc_dialog->mainwin)
405 gtk_progress_bar_update
406 (GTK_PROGRESS_BAR(inc_dialog->mainwin->progressbar), 0.0);
409 static void inc_progress_dialog_destroy(IncProgressDialog *inc_dialog)
411 g_return_if_fail(inc_dialog != NULL);
413 inc_dialog_list = g_list_remove(inc_dialog_list, inc_dialog);
414 if (inc_dialog->mainwin)
415 gtk_progress_bar_update
416 (GTK_PROGRESS_BAR(inc_dialog->mainwin->progressbar), 0.0);
417 progress_dialog_destroy(inc_dialog->dialog);
422 static IncSession *inc_session_new(PrefsAccount *account)
426 g_return_val_if_fail(account != NULL, NULL);
428 if (account->protocol != A_POP3 && account->protocol != A_APOP)
430 if (!account->recv_server || !account->userid)
433 session = g_new0(IncSession, 1);
434 session->session = pop3_session_new(account);
435 session->session->data = session;
440 static void inc_session_destroy(IncSession *session)
442 g_return_if_fail(session != NULL);
444 session_destroy(session->session);
448 static gint inc_start(IncProgressDialog *inc_dialog)
451 GtkCList *clist = GTK_CLIST(inc_dialog->dialog->clist);
452 Pop3Session *pop3_session;
459 FolderItem *processing, *inbox;
461 GSList *msglist, *msglist_element;
463 while (inc_dialog->queue_list != NULL) {
464 session = inc_dialog->queue_list->data;
465 pop3_session = POP3_SESSION(session->session);
467 inc_progress_dialog_clear(inc_dialog);
469 gtk_clist_moveto(clist, num, -1, 1.0, 0.0);
471 pop3_session->user = g_strdup(pop3_session->ac_prefs->userid);
472 if (pop3_session->ac_prefs->passwd)
474 g_strdup(pop3_session->ac_prefs->passwd);
475 else if (pop3_session->ac_prefs->tmp_pass)
477 g_strdup(pop3_session->ac_prefs->tmp_pass);
481 pass = input_dialog_query_password
482 (pop3_session->ac_prefs->recv_server,
485 if (inc_dialog->mainwin && inc_dialog->show_dialog)
486 manage_window_focus_in
487 (inc_dialog->mainwin->window,
490 pop3_session->ac_prefs->tmp_pass =
492 pop3_session->pass = pass;
494 inc_session_destroy(session);
495 inc_dialog->queue_list = g_list_remove
496 (inc_dialog->queue_list, session);
501 gtk_clist_set_pixmap(clist, num, 0, currentxpm, currentxpmmask);
502 gtk_clist_set_text(clist, num, 2, _("Retrieving"));
504 session_set_recv_message_notify(session->session,
505 inc_recv_message, session);
506 session_set_recv_data_progressive_notify
507 (session->session, inc_recv_data_progressive, session);
508 session_set_recv_data_notify(session->session,
509 inc_recv_data_finished, session);
511 /* begin POP3 session */
512 inc_state = inc_pop3_session_do(session);
516 if (pop3_session->cur_total_num > 0)
517 msg = g_strdup_printf
518 (_("Done (%d message(s) (%s) received)"),
519 pop3_session->cur_total_num,
520 to_human_readable(pop3_session->cur_total_recv_bytes));
522 msg = g_strdup_printf(_("Done (no new messages)"));
523 gtk_clist_set_pixmap(clist, num, 0, okxpm, okxpmmask);
524 gtk_clist_set_text(clist, num, 2, msg);
527 case INC_CONNECT_ERROR:
528 gtk_clist_set_pixmap(clist, num, 0, errorxpm, errorxpmmask);
529 gtk_clist_set_text(clist, num, 2, _("Connection failed"));
531 case INC_AUTH_FAILED:
532 gtk_clist_set_pixmap(clist, num, 0, errorxpm, errorxpmmask);
533 gtk_clist_set_text(clist, num, 2, _("Auth failed"));
536 gtk_clist_set_pixmap(clist, num, 0, errorxpm, errorxpmmask);
537 gtk_clist_set_text(clist, num, 2, _("Locked"));
542 case INC_SOCKET_ERROR:
543 gtk_clist_set_pixmap(clist, num, 0, errorxpm, errorxpmmask);
544 gtk_clist_set_text(clist, num, 2, _("Error"));
547 gtk_clist_set_pixmap(clist, num, 0, okxpm, okxpmmask);
548 gtk_clist_set_text(clist, num, 2, _("Cancelled"));
554 if (pop3_session->error_val == PS_AUTHFAIL) {
555 if(!prefs_common.no_recv_err_panel) {
556 if((prefs_common.recv_dialog_mode == RECV_DIALOG_ALWAYS) ||
557 ((prefs_common.recv_dialog_mode == RECV_DIALOG_ACTIVE) && focus_window)) {
558 manage_window_focus_in(inc_dialog->dialog->window, NULL, NULL);
561 (_("Authorization for %s on %s failed"),
563 pop3_session->ac_prefs->recv_server);
567 /* CLAWS: perform filtering actions on dropped message */
568 /* CLAWS: get default inbox (perhaps per account) */
569 if (pop3_session->ac_prefs->inbox) {
570 /* CLAWS: get destination folder / mailbox */
571 inbox = folder_find_item_from_identifier(pop3_session->ac_prefs->inbox);
573 inbox = folder_get_default_inbox();
575 inbox = folder_get_default_inbox();
577 /* get list of messages in processing */
578 processing = folder_get_default_processing();
579 folder_item_scan(processing);
580 msglist = folder_item_get_msg_list(processing);
582 folder_item_update_freeze();
584 /* process messages */
585 for(msglist_element = msglist; msglist_element != NULL; msglist_element = msglist_element->next) {
586 msginfo = (MsgInfo *) msglist_element->data;
587 if (!pop3_session->ac_prefs->filter_on_recv || !procmsg_msginfo_filter(msginfo))
588 folder_item_move_msg(inbox, msginfo);
589 procmsg_msginfo_free(msginfo);
591 g_slist_free(msglist);
593 folder_item_update_thaw();
596 new_msgs += pop3_session->cur_total_num;
598 if (pop3_session->error_val == PS_AUTHFAIL &&
599 pop3_session->ac_prefs->tmp_pass) {
600 g_free(pop3_session->ac_prefs->tmp_pass);
601 pop3_session->ac_prefs->tmp_pass = NULL;
604 pop3_write_uidl_list(pop3_session);
606 if (inc_state != INC_SUCCESS && inc_state != INC_CANCEL) {
608 if (inc_dialog->show_dialog)
609 manage_window_focus_in
610 (inc_dialog->dialog->window,
612 inc_put_error(inc_state, pop3_session->error_msg);
613 if (inc_dialog->show_dialog)
614 manage_window_focus_out
615 (inc_dialog->dialog->window,
617 if (inc_state == INC_NO_SPACE ||
618 inc_state == INC_IO_ERROR)
622 inc_session_destroy(session);
623 inc_dialog->queue_list =
624 g_list_remove(inc_dialog->queue_list, session);
630 fin_msg = g_strdup_printf(_("Finished (%d new message(s))"),
633 fin_msg = g_strdup_printf(_("Finished (no new messages)"));
635 progress_dialog_set_label(inc_dialog->dialog, fin_msg);
637 if (error_num && !prefs_common.no_recv_err_panel) {
638 if (inc_dialog->show_dialog)
639 manage_window_focus_in(inc_dialog->dialog->window,
641 alertpanel_error_log(_("Some errors occurred while getting mail."));
642 if (inc_dialog->show_dialog)
643 manage_window_focus_out(inc_dialog->dialog->window,
647 while (inc_dialog->queue_list != NULL) {
648 session = inc_dialog->queue_list->data;
649 inc_session_destroy(session);
650 inc_dialog->queue_list =
651 g_list_remove(inc_dialog->queue_list, session);
654 if (prefs_common.close_recv_dialog)
655 inc_progress_dialog_destroy(inc_dialog);
657 gtk_window_set_title(GTK_WINDOW(inc_dialog->dialog->window),
659 gtk_label_set_text(GTK_LABEL(GTK_BIN(inc_dialog->dialog->cancel_btn)->child),
668 static IncState inc_pop3_session_do(IncSession *session)
670 Pop3Session *pop3_session = POP3_SESSION(session->session);
671 IncProgressDialog *inc_dialog = (IncProgressDialog *)session->data;
676 debug_print("getting new messages of account %s...\n",
677 pop3_session->ac_prefs->account_name);
679 buf = g_strdup_printf(_("%s: Retrieving new messages"),
680 pop3_session->ac_prefs->recv_server);
681 gtk_window_set_title(GTK_WINDOW(inc_dialog->dialog->window), buf);
684 server = pop3_session->ac_prefs->recv_server;
686 port = pop3_session->ac_prefs->set_popport ?
687 pop3_session->ac_prefs->popport :
688 pop3_session->ac_prefs->ssl_pop == SSL_TUNNEL ? 995 : 110;
689 SESSION(pop3_session)->ssl_type = pop3_session->ac_prefs->ssl_pop;
691 port = pop3_session->ac_prefs->set_popport ?
692 pop3_session->ac_prefs->popport : 110;
695 statusbar_verbosity_set(TRUE);
696 buf = g_strdup_printf(_("Connecting to POP3 server: %s ..."), server);
697 log_message("%s\n", buf);
699 progress_dialog_set_label(inc_dialog->dialog, buf);
703 statusbar_verbosity_set(FALSE);
705 if (session_connect(SESSION(pop3_session), server, port) < 0) {
706 log_warning(_("Can't connect to POP3 server: %s:%d\n"),
708 if(!prefs_common.no_recv_err_panel) {
709 if((prefs_common.recv_dialog_mode == RECV_DIALOG_ALWAYS) ||
710 ((prefs_common.recv_dialog_mode == RECV_DIALOG_ACTIVE) && focus_window)) {
711 manage_window_focus_in(inc_dialog->dialog->window, NULL, NULL);
713 alertpanel_error(_("Can't connect to POP3 server: %s:%d"),
715 manage_window_focus_out(inc_dialog->dialog->window, NULL, NULL);
717 session->inc_state = INC_CONNECT_ERROR;
718 return INC_CONNECT_ERROR;
721 statusbar_verbosity_set(TRUE);
723 while (SESSION(pop3_session)->state != SESSION_DISCONNECTED &&
724 SESSION(pop3_session)->state != SESSION_ERROR)
725 gtk_main_iteration();
728 statusbar_verbosity_set(FALSE);
729 if (session->inc_state == INC_SUCCESS) {
730 switch (pop3_session->error_val) {
732 if (SESSION(pop3_session)->state == SESSION_ERROR) {
733 if (pop3_session->state == POP3_READY)
734 session->inc_state = INC_CONNECT_ERROR;
736 session->inc_state = INC_ERROR;
738 session->inc_state = INC_SUCCESS;
741 session->inc_state = INC_AUTH_FAILED;
744 session->inc_state = INC_IO_ERROR;
747 session->inc_state = INC_SOCKET_ERROR;
750 session->inc_state = INC_LOCKED;
753 session->inc_state = INC_ERROR;
758 return session->inc_state;
761 static gint inc_recv_data_progressive(Session *session, guint cur_len,
762 guint total_len, gpointer data)
764 gchar buf[MSGBUFSIZE];
765 IncSession *inc_session = (IncSession *)data;
766 Pop3Session *pop3_session = POP3_SESSION(session);
767 IncProgressDialog *inc_dialog = (IncProgressDialog *)inc_session->data;
768 ProgressDialog *dialog = inc_dialog->dialog;
772 cur_total = pop3_session->cur_total_bytes + cur_len;
773 if (cur_total > pop3_session->total_bytes)
774 cur_total = pop3_session->total_bytes;
776 Xstrdup_a(total_size, to_human_readable(pop3_session->total_bytes),
778 g_snprintf(buf, sizeof(buf),
779 _("Retrieving message (%d / %d) (%s / %s)"),
780 pop3_session->cur_msg, pop3_session->count,
781 to_human_readable(cur_total), total_size);
782 progress_dialog_set_label(dialog, buf);
783 progress_dialog_set_percentage
784 (dialog, (gfloat)cur_total / (gfloat)pop3_session->total_bytes);
785 if (inc_dialog->mainwin)
786 gtk_progress_bar_update
787 (GTK_PROGRESS_BAR(inc_dialog->mainwin->progressbar),
788 (gfloat)cur_total / (gfloat)pop3_session->total_bytes);
794 static gint inc_recv_data_finished(Session *session, guint len, gpointer data)
796 inc_recv_data_progressive(session, 0, len, data);
800 static gint inc_recv_message(Session *session, const gchar *msg, gpointer data)
802 gchar buf[MSGBUFSIZE];
803 IncSession *inc_session = (IncSession *)data;
804 Pop3Session *pop3_session = POP3_SESSION(session);
805 IncProgressDialog *inc_dialog = (IncProgressDialog *)inc_session->data;
806 ProgressDialog *dialog = inc_dialog->dialog;
808 switch (pop3_session->state) {
811 case POP3_GETAUTH_USER:
812 case POP3_GETAUTH_PASS:
813 case POP3_GETAUTH_APOP:
814 progress_dialog_set_label(dialog, _("Authenticating..."));
816 case POP3_GETRANGE_STAT:
817 progress_dialog_set_label
818 (dialog, _("Getting the number of new messages (STAT)..."));
820 case POP3_GETRANGE_LAST:
821 progress_dialog_set_label
822 (dialog, _("Getting the number of new messages (LAST)..."));
824 case POP3_GETRANGE_UIDL:
825 progress_dialog_set_label
826 (dialog, _("Getting the number of new messages (UIDL)..."));
828 case POP3_GETSIZE_LIST:
829 progress_dialog_set_label
830 (dialog, _("Getting the size of messages (LIST)..."));
833 inc_recv_data_progressive
835 pop3_session->msg[pop3_session->cur_msg].size, data);
838 if (pop3_session->msg[pop3_session->cur_msg].recv_time <
839 pop3_session->current_time) {
840 g_snprintf(buf, sizeof(buf), _("Deleting message %d"),
841 pop3_session->cur_msg);
842 progress_dialog_set_label(dialog, buf);
846 progress_dialog_set_label(dialog, _("Quitting"));
855 gint inc_drop_message(const gchar *file, Pop3Session *session)
858 FolderItem *dropfolder;
860 IncSession *inc_session = (IncSession *)(SESSION(session)->data);
863 if (session->ac_prefs->inbox) {
864 inbox = folder_find_item_from_identifier
865 (session->ac_prefs->inbox);
867 inbox = folder_get_default_inbox();
869 inbox = folder_get_default_inbox();
875 /* CLAWS: claws uses a global .processing folder for the filtering. */
876 dropfolder = folder_get_default_processing();
878 /* add msg file to drop folder */
879 if ((msgnum = folder_item_add_msg(dropfolder, file, TRUE)) < 0) {
887 static void inc_put_error(IncState istate, const gchar *msg)
891 if (prefs_common.no_recv_err_panel)
894 alertpanel_error(_("Error occurred while processing mail:\n%s"), msg);
896 alertpanel_error(_("Error occurred while processing mail."));
899 alertpanel_error(_("No disk space left."));
902 alertpanel_error(_("Can't write file."));
904 case INC_SOCKET_ERROR:
905 if (prefs_common.no_recv_err_panel)
907 alertpanel_error(_("Socket error."));
910 if (prefs_common.no_recv_err_panel)
913 alertpanel_error(_("Mailbox is locked:\n%s"), msg);
915 alertpanel_error(_("Mailbox is locked."));
917 case INC_AUTH_FAILED:
918 if (prefs_common.no_recv_err_panel)
921 alertpanel_error(_("Authentication failed:\n%s"),
924 alertpanel_error(_("Authentication failed."));
931 static void inc_cancel(IncProgressDialog *dialog)
935 g_return_if_fail(dialog != NULL);
937 if (dialog->queue_list == NULL) {
938 inc_progress_dialog_destroy(dialog);
942 session = dialog->queue_list->data;
944 session->session->state = SESSION_DISCONNECTED;
945 session->inc_state = INC_CANCEL;
947 log_message(_("Incorporation cancelled\n"));
950 gboolean inc_is_active(void)
952 return (inc_dialog_list != NULL);
955 void inc_cancel_all(void)
959 for (cur = inc_dialog_list; cur != NULL; cur = cur->next)
960 inc_cancel((IncProgressDialog *)cur->data);
963 static void inc_cancel_cb(GtkWidget *widget, gpointer data)
965 inc_cancel((IncProgressDialog *)data);
968 static gint inc_dialog_delete_cb(GtkWidget *widget, GdkEventAny *event,
971 IncProgressDialog *dialog = (IncProgressDialog *)data;
973 if (dialog->queue_list == NULL)
974 inc_progress_dialog_destroy(dialog);
979 static gint inc_spool(void)
981 gchar *mbox, *logname;
984 logname = g_get_user_name();
985 mbox = g_strconcat(prefs_common.spool_path
986 ? prefs_common.spool_path : DEFAULT_SPOOL_PATH,
987 G_DIR_SEPARATOR_S, logname, NULL);
988 msgs = get_spool(folder_get_default_inbox(), mbox);
994 static gint inc_spool_account(PrefsAccount *account)
998 if (account->inbox) {
999 inbox = folder_find_item_from_path(account->inbox);
1001 inbox = folder_get_default_inbox();
1003 inbox = folder_get_default_inbox();
1005 return get_spool(inbox, account->local_mbox);
1008 static gint inc_all_spool(void)
1012 gint account_new_msgs = 0;
1014 list = account_get_list();
1015 if (!list) return 0;
1017 for (; list != NULL; list = list->next) {
1018 PrefsAccount *account = list->data;
1020 if ((account->protocol == A_LOCAL) &&
1021 (account->recv_at_getall)) {
1022 account_new_msgs = inc_spool_account(account);
1023 if (account_new_msgs > 0)
1024 new_msgs += account_new_msgs;
1031 static gint get_spool(FolderItem *dest, const gchar *mbox)
1035 gchar tmp_mbox[MAXPATHLEN + 1];
1037 g_return_val_if_fail(dest != NULL, -1);
1038 g_return_val_if_fail(mbox != NULL, -1);
1040 if (!is_file_exist(mbox) || (size = get_file_size(mbox)) == 0) {
1041 debug_print("no messages in local mailbox.\n");
1043 } else if (size < 0)
1046 if ((lockfd = lock_mbox(mbox, LOCK_FLOCK)) < 0)
1049 g_snprintf(tmp_mbox, sizeof(tmp_mbox), "%s%ctmpmbox.%08x",
1050 get_tmp_dir(), G_DIR_SEPARATOR, (gint)mbox);
1052 if (copy_mbox(mbox, tmp_mbox) < 0) {
1053 unlock_mbox(mbox, lockfd, LOCK_FLOCK);
1057 debug_print("Getting new messages from %s into %s...\n",
1060 msgs = proc_mbox(dest, tmp_mbox);
1063 if (msgs >= 0) empty_mbox(mbox);
1064 unlock_mbox(mbox, lockfd, LOCK_FLOCK);
1074 void inc_unlock(void)
1076 if (inc_lock_count > 0)
1080 static guint autocheck_timer = 0;
1081 static gpointer autocheck_data = NULL;
1083 static void inc_notify_cmd(gint new_msgs, gboolean notify)
1088 if (!(new_msgs && notify && prefs_common.newmail_notify_cmd &&
1089 *prefs_common.newmail_notify_cmd))
1091 if ((buf = strchr(prefs_common.newmail_notify_cmd, '%')) &&
1092 buf[1] == 'd' && !strchr(&buf[1], '%'))
1093 buf = g_strdup_printf(prefs_common.newmail_notify_cmd,
1096 buf = g_strdup(prefs_common.newmail_notify_cmd);
1098 execute_command_line(buf, TRUE);
1103 void inc_autocheck_timer_init(MainWindow *mainwin)
1105 autocheck_data = mainwin;
1106 inc_autocheck_timer_set();
1109 static void inc_autocheck_timer_set_interval(guint interval)
1111 inc_autocheck_timer_remove();
1112 /* last test is to avoid re-enabling auto_check after modifying
1113 the common preferences */
1114 if (prefs_common.autochk_newmail && autocheck_data
1115 && prefs_common.work_offline == FALSE) {
1116 autocheck_timer = gtk_timeout_add
1117 (interval, inc_autocheck_func, autocheck_data);
1118 debug_print("added timer = %d\n", autocheck_timer);
1122 void inc_autocheck_timer_set(void)
1124 inc_autocheck_timer_set_interval(prefs_common.autochk_itv * 60000);
1127 void inc_autocheck_timer_remove(void)
1129 if (autocheck_timer) {
1130 debug_print("removed timer = %d\n", autocheck_timer);
1131 gtk_timeout_remove(autocheck_timer);
1132 autocheck_timer = 0;
1136 static gint inc_autocheck_func(gpointer data)
1138 MainWindow *mainwin = (MainWindow *)data;
1140 if (inc_lock_count) {
1141 debug_print("autocheck is locked.\n");
1142 inc_autocheck_timer_set_interval(1000);
1146 inc_all_account_mail(mainwin, prefs_common.newmail_notify_auto);