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 gtk_widget_show(progress->window);
271 PIXMAP_CREATE(progress->clist, okxpm, okxpmmask, complete_xpm);
272 PIXMAP_CREATE(progress->clist,
273 currentxpm, currentxpmmask, continue_xpm);
274 PIXMAP_CREATE(progress->clist, errorxpm, errorxpmmask, error_xpm);
276 gtk_widget_show_now(progress->window);
278 dialog->dialog = progress;
279 dialog->queue_list = NULL;
284 static void inc_progress_dialog_clear(IncProgressDialog *inc_dialog)
286 progress_dialog_set_value(inc_dialog->dialog, 0.0);
287 progress_dialog_set_label(inc_dialog->dialog, "");
290 static void inc_progress_dialog_destroy(IncProgressDialog *inc_dialog)
292 g_return_if_fail(inc_dialog != NULL);
294 progress_dialog_destroy(inc_dialog->dialog);
299 static IncSession *inc_session_new(PrefsAccount *account)
303 g_return_val_if_fail(account != NULL, NULL);
305 if (account->protocol != A_POP3 && account->protocol != A_APOP)
307 if (!account->recv_server || !account->userid)
310 session = g_new0(IncSession, 1);
311 session->pop3_state = inc_pop3_state_new(account);
312 session->pop3_state->session = session;
317 static void inc_session_destroy(IncSession *session)
319 g_return_if_fail(session != NULL);
321 inc_pop3_state_destroy(session->pop3_state);
325 static Pop3State *inc_pop3_state_new(PrefsAccount *account)
329 state = g_new0(Pop3State, 1);
331 state->ac_prefs = account;
332 state->folder_table = g_hash_table_new(NULL, NULL);
333 state->id_table = inc_get_uidl_table(account);
334 state->id_list = NULL;
335 state->new_id_list = NULL;
336 state->inc_state = INC_SUCCESS;
341 static void inc_pop3_state_destroy(Pop3State *state)
343 g_hash_table_destroy(state->folder_table);
344 g_free(state->sizes);
346 if (state->id_table) {
347 hash_free_strings(state->id_table);
348 g_hash_table_destroy(state->id_table);
350 slist_free_strings(state->id_list);
351 slist_free_strings(state->new_id_list);
352 g_slist_free(state->id_list);
353 g_slist_free(state->new_id_list);
355 g_free(state->greeting);
358 g_free(state->prev_folder);
363 static void inc_start(IncProgressDialog *inc_dialog)
366 GtkCList *clist = GTK_CLIST(inc_dialog->dialog->clist);
367 Pop3State *pop3_state;
371 while (inc_dialog->queue_list != NULL) {
372 session = inc_dialog->queue_list->data;
373 pop3_state = session->pop3_state;
375 inc_progress_dialog_clear(inc_dialog);
377 gtk_clist_moveto(clist, num, 0, 1.0, 0.0);
379 pop3_state->user = g_strdup(pop3_state->ac_prefs->userid);
380 if (pop3_state->ac_prefs->passwd)
382 g_strdup(pop3_state->ac_prefs->passwd);
383 else if (pop3_state->ac_prefs->tmp_pass)
385 g_strdup(pop3_state->ac_prefs->tmp_pass);
390 message = g_strdup_printf
391 (_("Input password for %s on %s:"),
393 pop3_state->ac_prefs->recv_server);
395 pass = input_dialog_with_invisible(_("Input password"),
398 manage_window_focus_in(inc_dialog->mainwin->window,
401 pop3_state->ac_prefs->tmp_pass = g_strdup(pass);
402 pop3_state->pass = pass;
404 inc_session_destroy(session);
405 inc_dialog->queue_list = g_list_remove
406 (inc_dialog->queue_list, session);
411 gtk_clist_set_pixmap(clist, num, 0, currentxpm, currentxpmmask);
412 gtk_clist_set_text(clist, num, 2, _("Retrieving"));
414 /* begin POP3 session */
415 inc_state = inc_pop3_session_do(session);
417 if (inc_state == INC_SUCCESS || inc_state == INC_CANCEL) {
418 gtk_clist_set_pixmap(clist, num, 0, okxpm, okxpmmask);
419 gtk_clist_set_text(clist, num, 2, _("Done"));
421 gtk_clist_set_pixmap(clist, num, 0, errorxpm, errorxpmmask);
422 gtk_clist_set_text(clist, num, 2, _("Error"));
425 if (pop3_state->error_val == PS_AUTHFAIL) {
426 if(!prefs_common.noerrorpanel) {
427 manage_window_focus_in(inc_dialog->dialog->window, NULL, NULL);
429 (_("Authorization for %s on %s failed"),
431 pop3_state->ac_prefs->recv_server);
436 manage_window_focus_in(inc_dialog->mainwin->window, NULL, NULL);
438 folder_item_scan_foreach(pop3_state->folder_table);
439 folderview_update_item_foreach(pop3_state->folder_table);
441 if (pop3_state->error_val == PS_AUTHFAIL &&
442 pop3_state->ac_prefs->tmp_pass) {
443 g_free(pop3_state->ac_prefs->tmp_pass);
444 pop3_state->ac_prefs->tmp_pass = NULL;
447 inc_write_uidl_list(pop3_state);
449 if (inc_state != INC_SUCCESS) {
450 inc_put_error(inc_state);
454 inc_session_destroy(session);
455 inc_dialog->queue_list =
456 g_list_remove(inc_dialog->queue_list, session);
461 while (inc_dialog->queue_list != NULL) {
462 session = inc_dialog->queue_list->data;
463 inc_session_destroy(session);
464 inc_dialog->queue_list =
465 g_list_remove(inc_dialog->queue_list, session);
468 inc_progress_dialog_destroy(inc_dialog);
472 static IncState inc_pop3_session_do(IncSession *session)
474 Pop3State *pop3_state = session->pop3_state;
475 IncProgressDialog *inc_dialog = (IncProgressDialog *)session->data;
482 static AtmHandler handlers[] = {
484 pop3_getauth_user_send , pop3_getauth_user_recv,
485 pop3_getauth_pass_send , pop3_getauth_pass_recv,
486 pop3_getauth_apop_send , pop3_getauth_apop_recv,
487 pop3_getrange_stat_send , pop3_getrange_stat_recv,
488 pop3_getrange_last_send , pop3_getrange_last_recv,
489 pop3_getrange_uidl_send , pop3_getrange_uidl_recv,
490 pop3_getsize_list_send , pop3_getsize_list_recv,
491 pop3_retr_send , pop3_retr_recv,
492 pop3_delete_send , pop3_delete_recv,
493 pop3_logout_send , pop3_logout_recv
496 debug_print(_("getting new messages of account %s...\n"),
497 pop3_state->ac_prefs->account_name);
499 atm = automaton_create(N_POP3_PHASE);
502 atm->data = pop3_state;
504 buf = g_strdup_printf(_("%s: Retrieving new messages"),
505 pop3_state->ac_prefs->recv_server);
506 gtk_window_set_title(GTK_WINDOW(inc_dialog->dialog->window), buf);
509 for (i = POP3_GREETING_RECV; i < N_POP3_PHASE; i++)
510 atm->state[i].handler = handlers[i];
511 atm->state[POP3_GREETING_RECV].condition = GDK_INPUT_READ;
512 for (i = POP3_GETAUTH_USER_SEND; i < N_POP3_PHASE; ) {
513 atm->state[i++].condition = GDK_INPUT_WRITE;
514 atm->state[i++].condition = GDK_INPUT_READ;
517 atm->terminate = (AtmHandler)pop3_automaton_terminate;
519 atm->num = POP3_GREETING_RECV;
521 server = pop3_state->ac_prefs->recv_server;
522 port = pop3_state->ac_prefs->set_popport ?
523 pop3_state->ac_prefs->popport : 110;
525 buf = g_strdup_printf(_("Connecting to POP3 server: %s ..."), server);
526 log_message("%s\n", buf);
527 progress_dialog_set_label(inc_dialog->dialog, buf);
532 if ((sockinfo = sock_connect_with_thread(server, port)) == NULL) {
534 if ((sockinfo = sock_connect(server, port)) == NULL) {
536 log_warning(_("Can't connect to POP3 server: %s:%d\n"),
538 if(!prefs_common.noerrorpanel) {
539 manage_window_focus_in(inc_dialog->dialog->window, NULL, NULL);
540 alertpanel_error(_("Can't connect to POP3 server: %s:%d"),
542 manage_window_focus_out(inc_dialog->dialog->window, NULL, NULL);
544 pop3_automaton_terminate(NULL, atm);
545 automaton_destroy(atm);
550 /* :WK: Hmmm, with the later sock_gdk_input, we have 2 references
551 * to the sock structure - implement a reference counter?? */
552 pop3_state->sockinfo = sockinfo;
553 atm->help_sock = sockinfo;
555 recv_set_ui_func(inc_pop3_recv_func, session);
558 atm->timeout_tag = gtk_timeout_add
559 (TIMEOUT_ITV, (GtkFunction)connection_check_cb, atm);
561 atm->tag = sock_gdk_input_add(sockinfo,
562 atm->state[atm->num].condition,
563 automaton_input_cb, atm);
568 recv_set_ui_func(NULL, NULL);
571 //pthread_join(sockinfo->connect_thr, NULL);
573 automaton_destroy(atm);
575 return pop3_state->inc_state;
578 static gint pop3_automaton_terminate(SockInfo *source, Automaton *atm)
581 gdk_input_remove(atm->tag);
584 if (atm->timeout_tag > 0) {
585 gtk_timeout_remove(atm->timeout_tag);
586 atm->timeout_tag = 0;
593 atm->terminated = TRUE;
598 static GHashTable *inc_get_uidl_table(PrefsAccount *ac_prefs)
603 gchar buf[IDLEN + 3];
605 path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
606 "uidl-", ac_prefs->recv_server,
607 "-", ac_prefs->userid, NULL);
608 if ((fp = fopen(path, "r")) == NULL) {
609 if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
615 table = g_hash_table_new(g_str_hash, g_str_equal);
617 while (fgets(buf, sizeof(buf), fp) != NULL) {
619 g_hash_table_insert(table, g_strdup(buf), GINT_TO_POINTER(1));
627 static void inc_write_uidl_list(Pop3State *state)
633 if (!state->id_list) return;
635 path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
636 "uidl-", state->ac_prefs->recv_server,
637 "-", state->user, NULL);
638 if ((fp = fopen(path, "w")) == NULL) {
639 FILE_OP_ERROR(path, "fopen");
644 for (cur = state->id_list; cur != NULL; cur = cur->next) {
645 if (fputs((gchar *)cur->data, fp) == EOF) {
646 FILE_OP_ERROR(path, "fputs");
649 if (fputc('\n', fp) == EOF) {
650 FILE_OP_ERROR(path, "fputc");
655 if (fclose(fp) == EOF) FILE_OP_ERROR(path, "fclose");
660 static gint connection_check_cb(Automaton *atm)
662 Pop3State *state = atm->data;
663 IncProgressDialog *inc_dialog = state->session->data;
664 SockInfo *sockinfo = state->sockinfo;
666 //g_print("connection check\n");
668 if (sockinfo->state == CONN_LOOKUPFAILED ||
669 sockinfo->state == CONN_FAILED) {
670 atm->timeout_tag = 0;
671 log_warning(_("Can't connect to POP3 server: %s:%d\n"),
672 sockinfo->hostname, sockinfo->port);
673 if(!prefs_common.noerrorpanel) {
674 manage_window_focus_in(inc_dialog->dialog->window, NULL, NULL);
675 alertpanel_error(_("Can't connect to POP3 server: %s:%d"),
676 sockinfo->hostname, sockinfo->port);
677 manage_window_focus_out(inc_dialog->dialog->window, NULL, NULL);
679 pop3_automaton_terminate(sockinfo, atm);
681 } else if (sockinfo->state == CONN_ESTABLISHED) {
682 atm->timeout_tag = 0;
683 atm->tag = sock_gdk_input_add(sockinfo,
684 atm->state[atm->num].condition,
685 automaton_input_cb, atm);
693 static void inc_pop3_recv_func(SockInfo *sock, gint read_bytes, gpointer data)
695 gchar buf[MSGBUFSIZE];
696 IncSession *session = (IncSession *)data;
697 Pop3State *state = session->pop3_state;
698 IncProgressDialog *inc_dialog = session->data;
699 ProgressDialog *dialog = inc_dialog->dialog;
702 cur_total = state->cur_total_bytes + read_bytes;
703 if (cur_total > state->total_bytes)
704 cur_total = state->total_bytes;
706 g_snprintf(buf, sizeof(buf),
707 _("Retrieving message (%d / %d) (%d / %d bytes)"),
708 state->cur_msg, state->count,
709 cur_total, state->total_bytes);
710 progress_dialog_set_label(dialog, buf);
712 progress_dialog_set_percentage
713 (dialog, (gfloat)cur_total / (gfloat)state->total_bytes);
717 void inc_progress_update(Pop3State *state, Pop3Phase phase)
719 gchar buf[MSGBUFSIZE];
720 IncProgressDialog *inc_dialog = state->session->data;
721 ProgressDialog *dialog = inc_dialog->dialog;
724 case POP3_GREETING_RECV:
726 case POP3_GETAUTH_USER_SEND:
727 case POP3_GETAUTH_USER_RECV:
728 case POP3_GETAUTH_PASS_SEND:
729 case POP3_GETAUTH_PASS_RECV:
730 case POP3_GETAUTH_APOP_SEND:
731 case POP3_GETAUTH_APOP_RECV:
732 progress_dialog_set_label(dialog, _("Authorizing..."));
734 case POP3_GETRANGE_STAT_SEND:
735 case POP3_GETRANGE_STAT_RECV:
736 progress_dialog_set_label
737 (dialog, _("Getting the number of new messages (STAT)..."));
739 case POP3_GETRANGE_LAST_SEND:
740 case POP3_GETRANGE_LAST_RECV:
741 progress_dialog_set_label
742 (dialog, _("Getting the number of new messages (LAST)..."));
744 case POP3_GETRANGE_UIDL_SEND:
745 case POP3_GETRANGE_UIDL_RECV:
746 progress_dialog_set_label
747 (dialog, _("Getting the number of new messages (UIDL)..."));
749 case POP3_GETSIZE_LIST_SEND:
750 case POP3_GETSIZE_LIST_RECV:
751 progress_dialog_set_label
752 (dialog, _("Getting the size of messages (LIST)..."));
756 g_snprintf(buf, sizeof(buf),
757 _("Retrieving message (%d / %d) (%d / %d bytes)"),
758 state->cur_msg, state->count,
759 state->cur_total_bytes, state->total_bytes);
760 progress_dialog_set_label(dialog, buf);
761 progress_dialog_set_percentage
763 (gfloat)(state->cur_total_bytes) /
764 (gfloat)(state->total_bytes));
766 case POP3_DELETE_SEND:
767 case POP3_DELETE_RECV:
768 progress_dialog_set_label(dialog, _("Deleting message"));
770 case POP3_LOGOUT_SEND:
771 case POP3_LOGOUT_RECV:
772 progress_dialog_set_label(dialog, _("Quitting"));
778 gint inc_drop_message(const gchar *file, Pop3State *state)
781 FolderItem *dropfolder;
785 if (state->ac_prefs->inbox) {
786 inbox = folder_find_item_from_path(state->ac_prefs->inbox);
788 inbox = folder_get_default_inbox();
790 inbox = folder_get_default_inbox();
796 if (prefs_filtering == NULL) {
798 if (state->ac_prefs->filter_on_recv) {
800 filter_get_dest_folder(prefs_common.fltlist, file);
801 if (!dropfolder) dropfolder = inbox;
802 else if (!strcmp(dropfolder->path, FILTER_NOT_RECEIVE)) {
803 g_warning(_("a message won't be received\n"));
813 val = GPOINTER_TO_INT(g_hash_table_lookup
814 (state->folder_table, dropfolder));
816 folder_item_scan(dropfolder);
817 g_hash_table_insert(state->folder_table, dropfolder,
821 if ((msgnum = folder_item_add_msg(dropfolder, file, TRUE)) < 0) {
826 if (prefs_filtering != NULL) {
828 if (state->ac_prefs->filter_on_recv) {
829 filter_message(prefs_filtering, dropfolder, msgnum,
830 state->folder_table);
837 static void inc_put_error(IncState istate)
841 if(!prefs_common.noerrorpanel) {
842 alertpanel_error(_("Error occurred while processing mail."));
846 alertpanel_error(_("No disk space left."));
852 static void inc_cancel(GtkWidget *widget, gpointer data)
854 IncProgressDialog *dialog = data;
855 IncSession *session = dialog->queue_list->data;
856 SockInfo *sockinfo = session->pop3_state->sockinfo;
859 if (sockinfo->state == CONN_READY ||
860 sockinfo->state == CONN_LOOKUPSUCCESS) {
861 pthread_cancel(sockinfo->connect_thr);
862 //pthread_kill(sockinfo->connect_thr, SIGINT);
863 g_print("connection was cancelled.\n");
867 session->pop3_state->inc_state = INC_CANCEL;
868 pop3_automaton_terminate(sockinfo, session->atm);
871 static gint inc_spool(void)
873 gchar *mbox, *logname;
876 logname = g_get_user_name();
877 mbox = g_strconcat(prefs_common.spool_path
878 ? prefs_common.spool_path : DEFAULT_SPOOL_PATH,
879 G_DIR_SEPARATOR_S, logname, NULL);
880 msgs = get_spool(folder_get_default_inbox(), mbox);
886 static void inc_spool_account(PrefsAccount *account)
889 FolderItem *dropfolder;
892 if (account->inbox) {
893 inbox = folder_find_item_from_path(account->inbox);
895 inbox = folder_get_default_inbox();
897 inbox = folder_get_default_inbox();
899 get_spool(inbox, account->local_mbox);
902 static void inc_all_spool(void)
906 list = account_get_list();
909 for (; list != NULL; list = list->next) {
911 PrefsAccount *account = list->data;
913 if (account->protocol == A_LOCAL)
914 inc_spool_account(account);
918 static gint get_spool(FolderItem *dest, const gchar *mbox)
922 gchar tmp_mbox[MAXPATHLEN + 1];
923 GHashTable *folder_table = NULL;
925 g_return_val_if_fail(dest != NULL, -1);
926 g_return_val_if_fail(mbox != NULL, -1);
928 if (!is_file_exist(mbox) || (size = get_file_size(mbox)) == 0) {
929 debug_print(_("no messages in local mailbox.\n"));
934 if ((lockfd = lock_mbox(mbox, LOCK_FLOCK)) < 0)
937 g_snprintf(tmp_mbox, sizeof(tmp_mbox), "%s%ctmpmbox%d",
938 get_rc_dir(), G_DIR_SEPARATOR, (gint)mbox);
940 if (copy_mbox(mbox, tmp_mbox) < 0)
943 debug_print(_("Getting new messages from %s into %s...\n"),
946 if (prefs_common.filter_on_inc)
947 folder_table = g_hash_table_new(NULL, NULL);
948 msgs = proc_mbox(dest, tmp_mbox, folder_table);
951 if (msgs >= 0) empty_mbox(mbox);
952 unlock_mbox(mbox, lockfd, LOCK_FLOCK);
955 folder_item_scan_foreach(folder_table);
956 folderview_update_item_foreach(folder_table);
957 g_hash_table_destroy(folder_table);
959 folder_item_scan(dest);
960 folderview_update_item(dest, FALSE);
966 static guint autocheck_timer = 0;
967 static gpointer autocheck_data = NULL;
969 void inc_autocheck_timer_init(MainWindow *mainwin)
971 autocheck_data = mainwin;
972 inc_autocheck_timer_set();
975 void inc_autocheck_timer_set(void)
977 inc_autocheck_timer_remove();
979 if (prefs_common.autochk_newmail && autocheck_data) {
980 autocheck_timer = gtk_timeout_add
981 (prefs_common.autochk_itv * 60000,
987 void inc_autocheck_timer_remove(void)
989 if (autocheck_timer) {
990 gtk_timeout_remove(autocheck_timer);
995 static gint inc_autocheck_func(gpointer data)
997 MainWindow *mainwin = (MainWindow *)data;
999 inc_all_account_mail(mainwin);