2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2001 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>
33 #include <sys/types.h>
42 #include "mainwindow.h"
43 #include "folderview.h"
44 #include "summaryview.h"
45 #include "prefs_common.h"
46 #include "prefs_account.h"
55 #include "statusbar.h"
56 #include "manage_window.h"
57 #include "progressdialog.h"
58 #include "inputdialog.h"
59 #include "alertpanel.h"
61 #include "automaton.h"
63 #include "filtering.h"
65 #include "pixmaps/continue.xpm"
66 #include "pixmaps/complete.xpm"
67 #include "pixmaps/error.xpm"
69 GdkPixmap *currentxpm;
70 GdkBitmap *currentxpmmask;
72 GdkBitmap *errorxpmmask;
76 #define MSGBUFSIZE 8192
78 static void inc_finished (MainWindow *mainwin);
79 static void inc_account_mail (PrefsAccount *account,
82 static IncProgressDialog *inc_progress_dialog_create (void);
83 static void inc_progress_dialog_destroy (IncProgressDialog *inc_dialog);
85 static IncSession *inc_session_new (PrefsAccount *account);
86 static void inc_session_destroy (IncSession *session);
87 static Pop3State *inc_pop3_state_new (PrefsAccount *account);
88 static void inc_pop3_state_destroy (Pop3State *state);
89 static void inc_start (IncProgressDialog *inc_dialog);
90 static IncState inc_pop3_session_do (IncSession *session);
91 static gint pop3_automaton_terminate (SockInfo *source,
94 static GHashTable *inc_get_uidl_table (PrefsAccount *ac_prefs);
95 static void inc_write_uidl_list (Pop3State *state);
98 static gint connection_check_cb (Automaton *atm);
101 static void inc_pop3_recv_func (SockInfo *sock,
105 static void inc_put_error (IncState istate);
107 static void inc_cancel (GtkWidget *widget,
110 static gint inc_spool (void);
111 static gint get_spool (FolderItem *dest,
114 static void inc_all_spool(void);
116 static gint inc_autocheck_func (gpointer data);
118 static void inc_finished(MainWindow *mainwin)
122 if (prefs_common.open_inbox_on_inc) {
123 item = cur_account && cur_account->inbox
124 ? folder_find_item_from_path(cur_account->inbox)
125 : folder_get_default_inbox();
126 folderview_unselect(mainwin->folderview);
127 folderview_select(mainwin->folderview, item);
129 item = mainwin->summaryview->folder_item;
130 folderview_unselect(mainwin->folderview);
131 folderview_select(mainwin->folderview, item);
135 void inc_mail(MainWindow *mainwin)
137 inc_autocheck_timer_remove();
138 summary_write_cache(mainwin->summaryview);
140 if (prefs_common.use_extinc && prefs_common.extinc_path) {
143 /* external incorporating program */
144 if ((pid = fork()) < 0) {
146 inc_autocheck_timer_set();
151 execlp(prefs_common.extinc_path,
152 g_basename(prefs_common.extinc_path),
155 /* this will be called when failed */
160 /* wait until child process is terminated */
161 waitpid(pid, NULL, 0);
163 if (prefs_common.inc_local) inc_spool();
166 if (prefs_common.inc_local) inc_spool();
169 inc_account_mail(cur_account, mainwin);
172 inc_finished(mainwin);
173 inc_autocheck_timer_set();
176 static void inc_account_mail(PrefsAccount *account, MainWindow *mainwin)
178 IncProgressDialog *inc_dialog;
182 session = inc_session_new(account);
183 if (!session) return;
185 inc_dialog = inc_progress_dialog_create();
186 inc_dialog->queue_list = g_list_append(inc_dialog->queue_list, session);
187 inc_dialog->mainwin = mainwin;
188 session->data = inc_dialog;
191 text[1] = account->account_name;
192 text[2] = _("Standby");
193 gtk_clist_append(GTK_CLIST(inc_dialog->dialog->clist), text);
195 inc_start(inc_dialog);
198 void inc_all_account_mail(MainWindow *mainwin)
200 GList *list, *queue_list = NULL;
201 IncProgressDialog *inc_dialog;
203 inc_autocheck_timer_remove();
204 summary_write_cache(mainwin->summaryview);
206 if (prefs_common.inc_local) inc_spool();
208 list = account_get_list();
210 inc_autocheck_timer_set();
214 for (; list != NULL; list = list->next) {
216 PrefsAccount *account = list->data;
218 if (account->recv_at_getall) {
219 session = inc_session_new(account);
221 queue_list = g_list_append(queue_list, session);
226 inc_autocheck_timer_set();
230 inc_dialog = inc_progress_dialog_create();
231 inc_dialog->queue_list = queue_list;
232 inc_dialog->mainwin = mainwin;
233 for (list = queue_list; list != NULL; list = list->next) {
234 IncSession *session = list->data;
237 session->data = inc_dialog;
240 text[1] = session->pop3_state->ac_prefs->account_name;
241 text[2] = _("Standby");
242 gtk_clist_append(GTK_CLIST(inc_dialog->dialog->clist), text);
245 inc_start(inc_dialog);
247 inc_finished(mainwin);
248 inc_autocheck_timer_set();
251 static IncProgressDialog *inc_progress_dialog_create(void)
253 IncProgressDialog *dialog;
254 ProgressDialog *progress;
256 dialog = g_new0(IncProgressDialog, 1);
258 progress = progress_dialog_create();
259 gtk_window_set_title(GTK_WINDOW(progress->window),
260 _("Retrieving new messages"));
261 gtk_signal_connect(GTK_OBJECT(progress->cancel_btn), "clicked",
262 GTK_SIGNAL_FUNC(inc_cancel), dialog);
263 gtk_signal_connect(GTK_OBJECT(progress->window), "delete_event",
264 GTK_SIGNAL_FUNC(gtk_true), NULL);
265 manage_window_set_transient(GTK_WINDOW(progress->window));
267 progress_dialog_set_value(progress, 0.0);
269 if((prefs_common.receive_dialog == RECVDIALOG_ALWAYS) ||
270 ((prefs_common.receive_dialog == RECVDIALOG_WINDOW_ACTIVE) && focus_window)) {
271 gtk_widget_show(progress->window);
274 PIXMAP_CREATE(progress->clist, okxpm, okxpmmask, complete_xpm);
275 PIXMAP_CREATE(progress->clist,
276 currentxpm, currentxpmmask, continue_xpm);
277 PIXMAP_CREATE(progress->clist, errorxpm, errorxpmmask, error_xpm);
279 if((prefs_common.receive_dialog == RECVDIALOG_ALWAYS) ||
280 ((prefs_common.receive_dialog == RECVDIALOG_WINDOW_ACTIVE) && focus_window)) {
281 gtk_widget_show_now(progress->window);
284 dialog->dialog = progress;
285 dialog->queue_list = NULL;
290 static void inc_progress_dialog_clear(IncProgressDialog *inc_dialog)
292 progress_dialog_set_value(inc_dialog->dialog, 0.0);
293 progress_dialog_set_label(inc_dialog->dialog, "");
296 static void inc_progress_dialog_destroy(IncProgressDialog *inc_dialog)
298 g_return_if_fail(inc_dialog != NULL);
300 progress_dialog_destroy(inc_dialog->dialog);
305 static IncSession *inc_session_new(PrefsAccount *account)
309 g_return_val_if_fail(account != NULL, NULL);
311 if (account->protocol != A_POP3 && account->protocol != A_APOP)
313 if (!account->recv_server || !account->userid)
316 session = g_new0(IncSession, 1);
317 session->pop3_state = inc_pop3_state_new(account);
318 session->pop3_state->session = session;
323 static void inc_session_destroy(IncSession *session)
325 g_return_if_fail(session != NULL);
327 inc_pop3_state_destroy(session->pop3_state);
331 static Pop3State *inc_pop3_state_new(PrefsAccount *account)
335 state = g_new0(Pop3State, 1);
337 state->ac_prefs = account;
338 state->folder_table = g_hash_table_new(NULL, NULL);
339 state->id_table = inc_get_uidl_table(account);
340 state->id_list = NULL;
341 state->new_id_list = NULL;
342 state->inc_state = INC_SUCCESS;
347 static void inc_pop3_state_destroy(Pop3State *state)
349 g_hash_table_destroy(state->folder_table);
350 g_free(state->sizes);
352 if (state->id_table) {
353 hash_free_strings(state->id_table);
354 g_hash_table_destroy(state->id_table);
356 slist_free_strings(state->id_list);
357 slist_free_strings(state->new_id_list);
358 g_slist_free(state->id_list);
359 g_slist_free(state->new_id_list);
361 g_free(state->greeting);
364 g_free(state->prev_folder);
369 static void inc_start(IncProgressDialog *inc_dialog)
372 GtkCList *clist = GTK_CLIST(inc_dialog->dialog->clist);
373 Pop3State *pop3_state;
377 while (inc_dialog->queue_list != NULL) {
378 session = inc_dialog->queue_list->data;
379 pop3_state = session->pop3_state;
381 inc_progress_dialog_clear(inc_dialog);
383 gtk_clist_moveto(clist, num, 0, 1.0, 0.0);
385 pop3_state->user = g_strdup(pop3_state->ac_prefs->userid);
386 if (pop3_state->ac_prefs->passwd)
388 g_strdup(pop3_state->ac_prefs->passwd);
389 else if (pop3_state->ac_prefs->tmp_pass)
391 g_strdup(pop3_state->ac_prefs->tmp_pass);
396 message = g_strdup_printf
397 (_("Input password for %s on %s:"),
399 pop3_state->ac_prefs->recv_server);
401 pass = input_dialog_with_invisible(_("Input password"),
404 manage_window_focus_in(inc_dialog->mainwin->window,
407 pop3_state->ac_prefs->tmp_pass = g_strdup(pass);
408 pop3_state->pass = pass;
410 inc_session_destroy(session);
411 inc_dialog->queue_list = g_list_remove
412 (inc_dialog->queue_list, session);
417 gtk_clist_set_pixmap(clist, num, 0, currentxpm, currentxpmmask);
418 gtk_clist_set_text(clist, num, 2, _("Retrieving"));
420 /* begin POP3 session */
421 inc_state = inc_pop3_session_do(session);
423 if (inc_state == INC_SUCCESS || inc_state == INC_CANCEL) {
424 gtk_clist_set_pixmap(clist, num, 0, okxpm, okxpmmask);
425 gtk_clist_set_text(clist, num, 2, _("Done"));
427 gtk_clist_set_pixmap(clist, num, 0, errorxpm, errorxpmmask);
428 gtk_clist_set_text(clist, num, 2, _("Error"));
431 if (pop3_state->error_val == PS_AUTHFAIL) {
432 if(!prefs_common.noerrorpanel) {
433 manage_window_focus_in(inc_dialog->dialog->window, NULL, NULL);
435 (_("Authorization for %s on %s failed"),
437 pop3_state->ac_prefs->recv_server);
442 manage_window_focus_in(inc_dialog->mainwin->window, NULL, NULL);
444 folder_item_scan_foreach(pop3_state->folder_table);
445 folderview_update_item_foreach(pop3_state->folder_table);
447 if (pop3_state->error_val == PS_AUTHFAIL &&
448 pop3_state->ac_prefs->tmp_pass) {
449 g_free(pop3_state->ac_prefs->tmp_pass);
450 pop3_state->ac_prefs->tmp_pass = NULL;
453 inc_write_uidl_list(pop3_state);
455 if (inc_state != INC_SUCCESS) {
456 inc_put_error(inc_state);
460 inc_session_destroy(session);
461 inc_dialog->queue_list =
462 g_list_remove(inc_dialog->queue_list, session);
467 while (inc_dialog->queue_list != NULL) {
468 session = inc_dialog->queue_list->data;
469 inc_session_destroy(session);
470 inc_dialog->queue_list =
471 g_list_remove(inc_dialog->queue_list, session);
474 inc_progress_dialog_destroy(inc_dialog);
478 static IncState inc_pop3_session_do(IncSession *session)
480 Pop3State *pop3_state = session->pop3_state;
481 IncProgressDialog *inc_dialog = (IncProgressDialog *)session->data;
488 static AtmHandler handlers[] = {
490 pop3_getauth_user_send , pop3_getauth_user_recv,
491 pop3_getauth_pass_send , pop3_getauth_pass_recv,
492 pop3_getauth_apop_send , pop3_getauth_apop_recv,
493 pop3_getrange_stat_send , pop3_getrange_stat_recv,
494 pop3_getrange_last_send , pop3_getrange_last_recv,
495 pop3_getrange_uidl_send , pop3_getrange_uidl_recv,
496 pop3_getsize_list_send , pop3_getsize_list_recv,
497 pop3_retr_send , pop3_retr_recv,
498 pop3_delete_send , pop3_delete_recv,
499 pop3_logout_send , pop3_logout_recv
502 debug_print(_("getting new messages of account %s...\n"),
503 pop3_state->ac_prefs->account_name);
505 atm = automaton_create(N_POP3_PHASE);
508 atm->data = pop3_state;
510 buf = g_strdup_printf(_("%s: Retrieving new messages"),
511 pop3_state->ac_prefs->recv_server);
512 gtk_window_set_title(GTK_WINDOW(inc_dialog->dialog->window), buf);
515 for (i = POP3_GREETING_RECV; i < N_POP3_PHASE; i++)
516 atm->state[i].handler = handlers[i];
517 atm->state[POP3_GREETING_RECV].condition = GDK_INPUT_READ;
518 for (i = POP3_GETAUTH_USER_SEND; i < N_POP3_PHASE; ) {
519 atm->state[i++].condition = GDK_INPUT_WRITE;
520 atm->state[i++].condition = GDK_INPUT_READ;
523 atm->terminate = (AtmHandler)pop3_automaton_terminate;
525 atm->num = POP3_GREETING_RECV;
527 server = pop3_state->ac_prefs->recv_server;
528 port = pop3_state->ac_prefs->set_popport ?
529 pop3_state->ac_prefs->popport : 110;
531 buf = g_strdup_printf(_("Connecting to POP3 server: %s ..."), server);
532 log_message("%s\n", buf);
533 progress_dialog_set_label(inc_dialog->dialog, buf);
538 if ((sockinfo = sock_connect_with_thread(server, port)) == NULL) {
540 if ((sockinfo = sock_connect(server, port)) == NULL) {
542 log_warning(_("Can't connect to POP3 server: %s:%d\n"),
544 if(!prefs_common.noerrorpanel) {
545 manage_window_focus_in(inc_dialog->dialog->window, NULL, NULL);
546 alertpanel_error(_("Can't connect to POP3 server: %s:%d"),
548 manage_window_focus_out(inc_dialog->dialog->window, NULL, NULL);
550 pop3_automaton_terminate(NULL, atm);
551 automaton_destroy(atm);
556 /* :WK: Hmmm, with the later sock_gdk_input, we have 2 references
557 * to the sock structure - implement a reference counter?? */
558 pop3_state->sockinfo = sockinfo;
559 atm->help_sock = sockinfo;
561 recv_set_ui_func(inc_pop3_recv_func, session);
564 atm->timeout_tag = gtk_timeout_add
565 (TIMEOUT_ITV, (GtkFunction)connection_check_cb, atm);
567 atm->tag = sock_gdk_input_add(sockinfo,
568 atm->state[atm->num].condition,
569 automaton_input_cb, atm);
574 recv_set_ui_func(NULL, NULL);
578 pthread_join(sockinfo->connect_thr, NULL);
581 automaton_destroy(atm);
583 return pop3_state->inc_state;
586 static gint pop3_automaton_terminate(SockInfo *source, Automaton *atm)
589 gdk_input_remove(atm->tag);
592 if (atm->timeout_tag > 0) {
593 gtk_timeout_remove(atm->timeout_tag);
594 atm->timeout_tag = 0;
601 atm->terminated = TRUE;
606 static GHashTable *inc_get_uidl_table(PrefsAccount *ac_prefs)
611 gchar buf[IDLEN + 3];
613 path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
614 "uidl-", ac_prefs->recv_server,
615 "-", ac_prefs->userid, NULL);
616 if ((fp = fopen(path, "r")) == NULL) {
617 if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
623 table = g_hash_table_new(g_str_hash, g_str_equal);
625 while (fgets(buf, sizeof(buf), fp) != NULL) {
627 g_hash_table_insert(table, g_strdup(buf), GINT_TO_POINTER(1));
635 static void inc_write_uidl_list(Pop3State *state)
641 if (!state->id_list) return;
643 path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
644 "uidl-", state->ac_prefs->recv_server,
645 "-", state->user, NULL);
646 if ((fp = fopen(path, "w")) == NULL) {
647 FILE_OP_ERROR(path, "fopen");
652 for (cur = state->id_list; cur != NULL; cur = cur->next) {
653 if (fputs((gchar *)cur->data, fp) == EOF) {
654 FILE_OP_ERROR(path, "fputs");
657 if (fputc('\n', fp) == EOF) {
658 FILE_OP_ERROR(path, "fputc");
663 if (fclose(fp) == EOF) FILE_OP_ERROR(path, "fclose");
668 static gint connection_check_cb(Automaton *atm)
670 Pop3State *state = atm->data;
671 IncProgressDialog *inc_dialog = state->session->data;
672 SockInfo *sockinfo = state->sockinfo;
674 /* g_print("connection check\n"); */
676 if (sockinfo->state == CONN_LOOKUPFAILED ||
677 sockinfo->state == CONN_FAILED) {
678 atm->timeout_tag = 0;
679 log_warning(_("Can't connect to POP3 server: %s:%d\n"),
680 sockinfo->hostname, sockinfo->port);
681 if(!prefs_common.noerrorpanel) {
682 manage_window_focus_in(inc_dialog->dialog->window, NULL, NULL);
683 alertpanel_error(_("Can't connect to POP3 server: %s:%d"),
684 sockinfo->hostname, sockinfo->port);
685 manage_window_focus_out(inc_dialog->dialog->window, NULL, NULL);
687 pop3_automaton_terminate(sockinfo, atm);
689 } else if (sockinfo->state == CONN_ESTABLISHED) {
690 atm->timeout_tag = 0;
691 atm->tag = sock_gdk_input_add(sockinfo,
692 atm->state[atm->num].condition,
693 automaton_input_cb, atm);
701 static void inc_pop3_recv_func(SockInfo *sock, gint read_bytes, gpointer data)
703 gchar buf[MSGBUFSIZE];
704 IncSession *session = (IncSession *)data;
705 Pop3State *state = session->pop3_state;
706 IncProgressDialog *inc_dialog = session->data;
707 ProgressDialog *dialog = inc_dialog->dialog;
710 cur_total = state->cur_total_bytes + read_bytes;
711 if (cur_total > state->total_bytes)
712 cur_total = state->total_bytes;
714 g_snprintf(buf, sizeof(buf),
715 _("Retrieving message (%d / %d) (%d / %d bytes)"),
716 state->cur_msg, state->count,
717 cur_total, state->total_bytes);
718 progress_dialog_set_label(dialog, buf);
720 progress_dialog_set_percentage
721 (dialog, (gfloat)cur_total / (gfloat)state->total_bytes);
725 void inc_progress_update(Pop3State *state, Pop3Phase phase)
727 gchar buf[MSGBUFSIZE];
728 IncProgressDialog *inc_dialog = state->session->data;
729 ProgressDialog *dialog = inc_dialog->dialog;
732 case POP3_GREETING_RECV:
734 case POP3_GETAUTH_USER_SEND:
735 case POP3_GETAUTH_USER_RECV:
736 case POP3_GETAUTH_PASS_SEND:
737 case POP3_GETAUTH_PASS_RECV:
738 case POP3_GETAUTH_APOP_SEND:
739 case POP3_GETAUTH_APOP_RECV:
740 progress_dialog_set_label(dialog, _("Authorizing..."));
742 case POP3_GETRANGE_STAT_SEND:
743 case POP3_GETRANGE_STAT_RECV:
744 progress_dialog_set_label
745 (dialog, _("Getting the number of new messages (STAT)..."));
747 case POP3_GETRANGE_LAST_SEND:
748 case POP3_GETRANGE_LAST_RECV:
749 progress_dialog_set_label
750 (dialog, _("Getting the number of new messages (LAST)..."));
752 case POP3_GETRANGE_UIDL_SEND:
753 case POP3_GETRANGE_UIDL_RECV:
754 progress_dialog_set_label
755 (dialog, _("Getting the number of new messages (UIDL)..."));
757 case POP3_GETSIZE_LIST_SEND:
758 case POP3_GETSIZE_LIST_RECV:
759 progress_dialog_set_label
760 (dialog, _("Getting the size of messages (LIST)..."));
764 g_snprintf(buf, sizeof(buf),
765 _("Retrieving message (%d / %d) (%d / %d bytes)"),
766 state->cur_msg, state->count,
767 state->cur_total_bytes, state->total_bytes);
768 progress_dialog_set_label(dialog, buf);
769 progress_dialog_set_percentage
771 (gfloat)(state->cur_total_bytes) /
772 (gfloat)(state->total_bytes));
774 case POP3_DELETE_SEND:
775 case POP3_DELETE_RECV:
776 progress_dialog_set_label(dialog, _("Deleting message"));
778 case POP3_LOGOUT_SEND:
779 case POP3_LOGOUT_RECV:
780 progress_dialog_set_label(dialog, _("Quitting"));
787 gint inc_drop_message(const gchar *file, Pop3State *state)
790 FolderItem *dropfolder;
794 if (state->ac_prefs->inbox) {
795 inbox = folder_find_item_from_path(state->ac_prefs->inbox);
797 inbox = folder_get_default_inbox();
799 inbox = folder_get_default_inbox();
805 if (prefs_filtering == NULL) {
807 if (state->ac_prefs->filter_on_recv) {
809 filter_get_dest_folder(prefs_common.fltlist, file);
810 if (!dropfolder) dropfolder = inbox;
811 else if (!strcmp(dropfolder->path, FILTER_NOT_RECEIVE)) {
812 g_warning(_("a message won't be received\n"));
822 val = GPOINTER_TO_INT(g_hash_table_lookup
823 (state->folder_table, dropfolder));
825 folder_item_scan(dropfolder);
826 g_hash_table_insert(state->folder_table, dropfolder,
830 if ((msgnum = folder_item_add_msg(dropfolder, file, TRUE)) < 0) {
835 if (prefs_filtering != NULL) {
837 if (state->ac_prefs->filter_on_recv) {
838 filter_message(prefs_filtering, dropfolder, msgnum,
839 state->folder_table);
846 static void inc_put_error(IncState istate)
850 if(!prefs_common.noerrorpanel) {
851 alertpanel_error(_("Error occurred while processing mail."));
855 alertpanel_error(_("No disk space left."));
862 static void inc_cancel(GtkWidget *widget, gpointer data)
864 IncProgressDialog *dialog = data;
865 IncSession *session = dialog->queue_list->data;
866 SockInfo *sockinfo = session->pop3_state->sockinfo;
869 if (sockinfo->state == CONN_READY ||
870 sockinfo->state == CONN_LOOKUPSUCCESS) {
871 pthread_cancel(sockinfo->connect_thr);
872 /* pthread_kill(sockinfo->connect_thr, SIGINT); */
873 g_print("connection was cancelled.\n");
877 session->pop3_state->inc_state = INC_CANCEL;
878 pop3_automaton_terminate(sockinfo, session->atm);
881 static gint inc_spool(void)
883 gchar *mbox, *logname;
886 logname = g_get_user_name();
887 mbox = g_strconcat(prefs_common.spool_path
888 ? prefs_common.spool_path : DEFAULT_SPOOL_PATH,
889 G_DIR_SEPARATOR_S, logname, NULL);
890 msgs = get_spool(folder_get_default_inbox(), mbox);
896 static void inc_spool_account(PrefsAccount *account)
899 FolderItem *dropfolder;
902 if (account->inbox) {
903 inbox = folder_find_item_from_path(account->inbox);
905 inbox = folder_get_default_inbox();
907 inbox = folder_get_default_inbox();
909 get_spool(inbox, account->local_mbox);
912 static void inc_all_spool(void)
916 list = account_get_list();
919 for (; list != NULL; list = list->next) {
921 PrefsAccount *account = list->data;
923 if (account->protocol == A_LOCAL)
924 inc_spool_account(account);
928 static gint get_spool(FolderItem *dest, const gchar *mbox)
932 gchar tmp_mbox[MAXPATHLEN + 1];
933 GHashTable *folder_table = NULL;
935 g_return_val_if_fail(dest != NULL, -1);
936 g_return_val_if_fail(mbox != NULL, -1);
938 if (!is_file_exist(mbox) || (size = get_file_size(mbox)) == 0) {
939 debug_print(_("no messages in local mailbox.\n"));
944 if ((lockfd = lock_mbox(mbox, LOCK_FLOCK)) < 0)
947 g_snprintf(tmp_mbox, sizeof(tmp_mbox), "%s%ctmpmbox%d",
948 get_rc_dir(), G_DIR_SEPARATOR, (gint)mbox);
950 if (copy_mbox(mbox, tmp_mbox) < 0)
953 debug_print(_("Getting new messages from %s into %s...\n"),
956 if (prefs_common.filter_on_inc)
957 folder_table = g_hash_table_new(NULL, NULL);
958 msgs = proc_mbox(dest, tmp_mbox, folder_table);
961 if (msgs >= 0) empty_mbox(mbox);
962 unlock_mbox(mbox, lockfd, LOCK_FLOCK);
965 folder_item_scan_foreach(folder_table);
966 folderview_update_item_foreach(folder_table);
967 g_hash_table_destroy(folder_table);
969 folder_item_scan(dest);
970 folderview_update_item(dest, FALSE);
976 static guint autocheck_timer = 0;
977 static gpointer autocheck_data = NULL;
979 void inc_autocheck_timer_init(MainWindow *mainwin)
981 autocheck_data = mainwin;
982 inc_autocheck_timer_set();
985 void inc_autocheck_timer_set(void)
987 inc_autocheck_timer_remove();
989 if (prefs_common.autochk_newmail && autocheck_data) {
990 autocheck_timer = gtk_timeout_add
991 (prefs_common.autochk_itv * 60000,
997 void inc_autocheck_timer_remove(void)
999 if (autocheck_timer) {
1000 gtk_timeout_remove(autocheck_timer);
1001 autocheck_timer = 0;
1005 static gint inc_autocheck_func(gpointer data)
1007 MainWindow *mainwin = (MainWindow *)data;
1009 inc_all_account_mail(mainwin);