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"
64 #include "pixmaps/continue.xpm"
65 #include "pixmaps/complete.xpm"
66 #include "pixmaps/error.xpm"
68 GdkPixmap *currentxpm;
69 GdkBitmap *currentxpmmask;
71 GdkBitmap *errorxpmmask;
75 #define MSGBUFSIZE 8192
77 static void inc_finished (MainWindow *mainwin);
78 static void inc_account_mail (PrefsAccount *account,
81 static IncProgressDialog *inc_progress_dialog_create (void);
82 static void inc_progress_dialog_destroy (IncProgressDialog *inc_dialog);
84 static IncSession *inc_session_new (PrefsAccount *account);
85 static void inc_session_destroy (IncSession *session);
86 static Pop3State *inc_pop3_state_new (PrefsAccount *account);
87 static void inc_pop3_state_destroy (Pop3State *state);
88 static void inc_start (IncProgressDialog *inc_dialog);
89 static IncState inc_pop3_session_do (IncSession *session);
90 static gint pop3_automaton_terminate (SockInfo *source,
93 static GHashTable *inc_get_uidl_table (PrefsAccount *ac_prefs);
94 static void inc_write_uidl_list (Pop3State *state);
97 static gint connection_check_cb (Automaton *atm);
100 static void inc_pop3_recv_func (SockInfo *sock,
104 static void inc_put_error (IncState istate);
106 static void inc_cancel (GtkWidget *widget,
109 static gint inc_spool (void);
110 static gint get_spool (FolderItem *dest,
113 static void inc_all_spool(void);
115 static gint inc_autocheck_func (gpointer data);
117 static void inc_finished(MainWindow *mainwin)
121 if (prefs_common.open_inbox_on_inc) {
122 item = cur_account && cur_account->inbox
123 ? folder_find_item_from_path(cur_account->inbox)
124 : folder_get_default_inbox();
125 folderview_unselect(mainwin->folderview);
126 folderview_select(mainwin->folderview, item);
128 item = mainwin->summaryview->folder_item;
129 folderview_unselect(mainwin->folderview);
130 folderview_select(mainwin->folderview, item);
134 void inc_mail(MainWindow *mainwin)
136 inc_autocheck_timer_remove();
137 summary_write_cache(mainwin->summaryview);
139 if (prefs_common.use_extinc && prefs_common.extinc_path) {
142 /* external incorporating program */
143 if ((pid = fork()) < 0) {
145 inc_autocheck_timer_set();
150 execlp(prefs_common.extinc_path,
151 g_basename(prefs_common.extinc_path),
154 /* this will be called when failed */
159 /* wait until child process is terminated */
160 waitpid(pid, NULL, 0);
162 if (prefs_common.inc_local) inc_spool();
165 if (prefs_common.inc_local) inc_spool();
168 inc_account_mail(cur_account, mainwin);
171 inc_finished(mainwin);
172 inc_autocheck_timer_set();
175 static void inc_account_mail(PrefsAccount *account, MainWindow *mainwin)
177 IncProgressDialog *inc_dialog;
181 session = inc_session_new(account);
182 if (!session) return;
184 inc_dialog = inc_progress_dialog_create();
185 inc_dialog->queue_list = g_list_append(inc_dialog->queue_list, session);
186 inc_dialog->mainwin = mainwin;
187 session->data = inc_dialog;
190 text[1] = account->account_name;
191 text[2] = _("Standby");
192 gtk_clist_append(GTK_CLIST(inc_dialog->dialog->clist), text);
194 inc_start(inc_dialog);
197 void inc_all_account_mail(MainWindow *mainwin)
199 GList *list, *queue_list = NULL;
200 IncProgressDialog *inc_dialog;
202 inc_autocheck_timer_remove();
203 summary_write_cache(mainwin->summaryview);
205 if (prefs_common.inc_local) inc_spool();
207 list = account_get_list();
209 inc_autocheck_timer_set();
213 for (; list != NULL; list = list->next) {
215 PrefsAccount *account = list->data;
217 if (account->recv_at_getall) {
218 session = inc_session_new(account);
220 queue_list = g_list_append(queue_list, session);
225 inc_autocheck_timer_set();
229 inc_dialog = inc_progress_dialog_create();
230 inc_dialog->queue_list = queue_list;
231 inc_dialog->mainwin = mainwin;
232 for (list = queue_list; list != NULL; list = list->next) {
233 IncSession *session = list->data;
236 session->data = inc_dialog;
239 text[1] = session->pop3_state->ac_prefs->account_name;
240 text[2] = _("Standby");
241 gtk_clist_append(GTK_CLIST(inc_dialog->dialog->clist), text);
244 inc_start(inc_dialog);
246 inc_finished(mainwin);
247 inc_autocheck_timer_set();
250 static IncProgressDialog *inc_progress_dialog_create(void)
252 IncProgressDialog *dialog;
253 ProgressDialog *progress;
255 dialog = g_new0(IncProgressDialog, 1);
257 progress = progress_dialog_create();
258 gtk_window_set_title(GTK_WINDOW(progress->window),
259 _("Retrieving new messages"));
260 gtk_signal_connect(GTK_OBJECT(progress->cancel_btn), "clicked",
261 GTK_SIGNAL_FUNC(inc_cancel), dialog);
262 gtk_signal_connect(GTK_OBJECT(progress->window), "delete_event",
263 GTK_SIGNAL_FUNC(gtk_true), NULL);
264 manage_window_set_transient(GTK_WINDOW(progress->window));
266 progress_dialog_set_value(progress, 0.0);
268 gtk_widget_show(progress->window);
270 PIXMAP_CREATE(progress->clist, okxpm, okxpmmask, complete_xpm);
271 PIXMAP_CREATE(progress->clist,
272 currentxpm, currentxpmmask, continue_xpm);
273 PIXMAP_CREATE(progress->clist, errorxpm, errorxpmmask, error_xpm);
275 gtk_widget_show_now(progress->window);
277 dialog->dialog = progress;
278 dialog->queue_list = NULL;
283 static void inc_progress_dialog_clear(IncProgressDialog *inc_dialog)
285 progress_dialog_set_value(inc_dialog->dialog, 0.0);
286 progress_dialog_set_label(inc_dialog->dialog, "");
289 static void inc_progress_dialog_destroy(IncProgressDialog *inc_dialog)
291 g_return_if_fail(inc_dialog != NULL);
293 progress_dialog_destroy(inc_dialog->dialog);
298 static IncSession *inc_session_new(PrefsAccount *account)
302 g_return_val_if_fail(account != NULL, NULL);
304 if (account->protocol != A_POP3 && account->protocol != A_APOP)
306 if (!account->recv_server || !account->userid)
309 session = g_new0(IncSession, 1);
310 session->pop3_state = inc_pop3_state_new(account);
311 session->pop3_state->session = session;
316 static void inc_session_destroy(IncSession *session)
318 g_return_if_fail(session != NULL);
320 inc_pop3_state_destroy(session->pop3_state);
324 static Pop3State *inc_pop3_state_new(PrefsAccount *account)
328 state = g_new0(Pop3State, 1);
330 state->ac_prefs = account;
331 state->folder_table = g_hash_table_new(NULL, NULL);
332 state->id_table = inc_get_uidl_table(account);
333 state->id_list = NULL;
334 state->new_id_list = NULL;
335 state->inc_state = INC_SUCCESS;
340 static void inc_pop3_state_destroy(Pop3State *state)
342 g_hash_table_destroy(state->folder_table);
343 g_free(state->sizes);
345 if (state->id_table) {
346 hash_free_strings(state->id_table);
347 g_hash_table_destroy(state->id_table);
349 slist_free_strings(state->id_list);
350 slist_free_strings(state->new_id_list);
351 g_slist_free(state->id_list);
352 g_slist_free(state->new_id_list);
354 g_free(state->greeting);
357 g_free(state->prev_folder);
362 static void inc_start(IncProgressDialog *inc_dialog)
365 GtkCList *clist = GTK_CLIST(inc_dialog->dialog->clist);
366 Pop3State *pop3_state;
370 while (inc_dialog->queue_list != NULL) {
371 session = inc_dialog->queue_list->data;
372 pop3_state = session->pop3_state;
374 inc_progress_dialog_clear(inc_dialog);
376 pop3_state->user = g_strdup(pop3_state->ac_prefs->userid);
377 if (pop3_state->ac_prefs->passwd)
379 g_strdup(pop3_state->ac_prefs->passwd);
380 else if (pop3_state->ac_prefs->tmp_pass)
382 g_strdup(pop3_state->ac_prefs->tmp_pass);
387 message = g_strdup_printf
388 (_("Input password for %s on %s:"),
390 pop3_state->ac_prefs->recv_server);
392 pass = input_dialog_with_invisible(_("Input password"),
395 manage_window_focus_in(inc_dialog->mainwin->window,
398 pop3_state->ac_prefs->tmp_pass = g_strdup(pass);
399 pop3_state->pass = pass;
401 inc_session_destroy(session);
402 inc_dialog->queue_list = g_list_remove
403 (inc_dialog->queue_list, session);
408 gtk_clist_set_pixmap(clist, num, 0, currentxpm, currentxpmmask);
409 gtk_clist_set_text(clist, num, 2, _("Retrieving"));
411 /* begin POP3 session */
412 inc_state = inc_pop3_session_do(session);
414 if (inc_state == INC_SUCCESS || inc_state == INC_CANCEL) {
415 gtk_clist_set_pixmap(clist, num, 0, okxpm, okxpmmask);
416 gtk_clist_set_text(clist, num, 2, _("Done"));
418 gtk_clist_set_pixmap(clist, num, 0, errorxpm, errorxpmmask);
419 gtk_clist_set_text(clist, num, 2, _("Error"));
422 if (pop3_state->error_val == PS_AUTHFAIL) {
423 manage_window_focus_in(inc_dialog->dialog->window, NULL, NULL);
425 (_("Authorization for %s on %s failed"),
427 pop3_state->ac_prefs->recv_server);
431 manage_window_focus_in(inc_dialog->mainwin->window, NULL, NULL);
433 folder_item_scan_foreach(pop3_state->folder_table);
434 folderview_update_item_foreach(pop3_state->folder_table);
436 if (pop3_state->error_val == PS_AUTHFAIL &&
437 pop3_state->ac_prefs->tmp_pass) {
438 g_free(pop3_state->ac_prefs->tmp_pass);
439 pop3_state->ac_prefs->tmp_pass = NULL;
442 inc_write_uidl_list(pop3_state);
444 if (inc_state != INC_SUCCESS) {
445 inc_put_error(inc_state);
449 inc_session_destroy(session);
450 inc_dialog->queue_list =
451 g_list_remove(inc_dialog->queue_list, session);
456 while (inc_dialog->queue_list != NULL) {
457 session = inc_dialog->queue_list->data;
458 inc_session_destroy(session);
459 inc_dialog->queue_list =
460 g_list_remove(inc_dialog->queue_list, session);
463 inc_progress_dialog_destroy(inc_dialog);
467 static IncState inc_pop3_session_do(IncSession *session)
469 Pop3State *pop3_state = session->pop3_state;
470 IncProgressDialog *inc_dialog = (IncProgressDialog *)session->data;
477 static AtmHandler handlers[] = {
479 pop3_getauth_user_send , pop3_getauth_user_recv,
480 pop3_getauth_pass_send , pop3_getauth_pass_recv,
481 pop3_getauth_apop_send , pop3_getauth_apop_recv,
482 pop3_getrange_stat_send , pop3_getrange_stat_recv,
483 pop3_getrange_last_send , pop3_getrange_last_recv,
484 pop3_getrange_uidl_send , pop3_getrange_uidl_recv,
485 pop3_getsize_list_send , pop3_getsize_list_recv,
486 pop3_retr_send , pop3_retr_recv,
487 pop3_delete_send , pop3_delete_recv,
488 pop3_logout_send , pop3_logout_recv
491 debug_print(_("getting new messages of account %s...\n"),
492 pop3_state->ac_prefs->account_name);
494 atm = automaton_create(N_POP3_PHASE);
497 atm->data = pop3_state;
499 buf = g_strdup_printf(_("%s: Retrieving new messages"),
500 pop3_state->ac_prefs->recv_server);
501 gtk_window_set_title(GTK_WINDOW(inc_dialog->dialog->window), buf);
504 for (i = POP3_GREETING_RECV; i < N_POP3_PHASE; i++)
505 atm->state[i].handler = handlers[i];
506 atm->state[POP3_GREETING_RECV].condition = GDK_INPUT_READ;
507 for (i = POP3_GETAUTH_USER_SEND; i < N_POP3_PHASE; ) {
508 atm->state[i++].condition = GDK_INPUT_WRITE;
509 atm->state[i++].condition = GDK_INPUT_READ;
512 atm->terminate = (AtmHandler)pop3_automaton_terminate;
514 atm->num = POP3_GREETING_RECV;
516 server = pop3_state->ac_prefs->recv_server;
517 port = pop3_state->ac_prefs->set_popport ?
518 pop3_state->ac_prefs->popport : 110;
520 buf = g_strdup_printf(_("Connecting to POP3 server: %s ..."), server);
521 log_message("%s\n", buf);
522 progress_dialog_set_label(inc_dialog->dialog, buf);
527 if ((sockinfo = sock_connect_with_thread(server, port)) == NULL) {
529 if ((sockinfo = sock_connect(server, port)) == NULL) {
531 log_warning(_("Can't connect to POP3 server: %s:%d\n"),
533 manage_window_focus_in(inc_dialog->dialog->window, NULL, NULL);
534 alertpanel_error(_("Can't connect to POP3 server: %s:%d"),
536 manage_window_focus_out(inc_dialog->dialog->window, NULL, NULL);
537 pop3_automaton_terminate(NULL, atm);
538 automaton_destroy(atm);
543 /* :WK: Hmmm, with the later sock_gdk_input, we have 2 references
544 * to the sock structure - implement a reference counter?? */
545 pop3_state->sockinfo = sockinfo;
546 atm->help_sock = sockinfo;
548 recv_set_ui_func(inc_pop3_recv_func, session);
551 atm->timeout_tag = gtk_timeout_add
552 (TIMEOUT_ITV, (GtkFunction)connection_check_cb, atm);
554 atm->tag = sock_gdk_input_add(sockinfo,
555 atm->state[atm->num].condition,
556 automaton_input_cb, atm);
561 recv_set_ui_func(NULL, NULL);
564 //pthread_join(sockinfo->connect_thr, NULL);
566 automaton_destroy(atm);
568 return pop3_state->inc_state;
571 static gint pop3_automaton_terminate(SockInfo *source, Automaton *atm)
574 gdk_input_remove(atm->tag);
577 if (atm->timeout_tag > 0) {
578 gtk_timeout_remove(atm->timeout_tag);
579 atm->timeout_tag = 0;
586 atm->terminated = TRUE;
591 static GHashTable *inc_get_uidl_table(PrefsAccount *ac_prefs)
596 gchar buf[IDLEN + 3];
598 path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
599 "uidl-", ac_prefs->recv_server,
600 "-", ac_prefs->userid, NULL);
601 if ((fp = fopen(path, "r")) == NULL) {
602 if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
608 table = g_hash_table_new(g_str_hash, g_str_equal);
610 while (fgets(buf, sizeof(buf), fp) != NULL) {
612 g_hash_table_insert(table, g_strdup(buf), GINT_TO_POINTER(1));
620 static void inc_write_uidl_list(Pop3State *state)
626 if (!state->id_list) return;
628 path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
629 "uidl-", state->ac_prefs->recv_server,
630 "-", state->user, NULL);
631 if ((fp = fopen(path, "w")) == NULL) {
632 FILE_OP_ERROR(path, "fopen");
637 for (cur = state->id_list; cur != NULL; cur = cur->next) {
638 if (fputs((gchar *)cur->data, fp) == EOF) {
639 FILE_OP_ERROR(path, "fputs");
642 if (fputc('\n', fp) == EOF) {
643 FILE_OP_ERROR(path, "fputc");
648 if (fclose(fp) == EOF) FILE_OP_ERROR(path, "fclose");
653 static gint connection_check_cb(Automaton *atm)
655 Pop3State *state = atm->data;
656 IncProgressDialog *inc_dialog = state->session->data;
657 SockInfo *sockinfo = state->sockinfo;
659 //g_print("connection check\n");
661 if (sockinfo->state == CONN_LOOKUPFAILED ||
662 sockinfo->state == CONN_FAILED) {
663 atm->timeout_tag = 0;
664 pop3_automaton_terminate(sockinfo->sock, atm);
665 log_warning(_("Can't connect to POP3 server: %s:%d\n"),
666 sockinfo->hostname, sockinfo->port);
667 manage_window_focus_in(inc_dialog->dialog->window, NULL, NULL);
668 alertpanel_error(_("Can't connect to POP3 server: %s:%d"),
669 sockinfo->hostname, sockinfo->port);
670 manage_window_focus_out(inc_dialog->dialog->window, NULL, NULL);
672 } else if (sockinfo->state == CONN_ESTABLISHED) {
673 atm->timeout_tag = 0;
674 atm->tag = gdk_input_add(sockinfo->sock,
675 atm->state[atm->num].condition,
676 automaton_input_cb, atm);
684 static void inc_pop3_recv_func(SockInfo *sock, gint read_bytes, gpointer data)
686 gchar buf[MSGBUFSIZE];
687 IncSession *session = (IncSession *)data;
688 Pop3State *state = session->pop3_state;
689 IncProgressDialog *inc_dialog = session->data;
690 ProgressDialog *dialog = inc_dialog->dialog;
693 cur_total = state->cur_total_bytes + read_bytes;
694 if (cur_total > state->total_bytes)
695 cur_total = state->total_bytes;
697 g_snprintf(buf, sizeof(buf),
698 _("Retrieving message (%d / %d) (%d / %d bytes)"),
699 state->cur_msg, state->count,
700 cur_total, state->total_bytes);
701 progress_dialog_set_label(dialog, buf);
703 progress_dialog_set_percentage
704 (dialog, (gfloat)cur_total / (gfloat)state->total_bytes);
708 void inc_progress_update(Pop3State *state, Pop3Phase phase)
710 gchar buf[MSGBUFSIZE];
711 IncProgressDialog *inc_dialog = state->session->data;
712 ProgressDialog *dialog = inc_dialog->dialog;
715 case POP3_GREETING_RECV:
717 case POP3_GETAUTH_USER_SEND:
718 case POP3_GETAUTH_USER_RECV:
719 case POP3_GETAUTH_PASS_SEND:
720 case POP3_GETAUTH_PASS_RECV:
721 case POP3_GETAUTH_APOP_SEND:
722 case POP3_GETAUTH_APOP_RECV:
723 progress_dialog_set_label(dialog, _("Authorizing..."));
725 case POP3_GETRANGE_STAT_SEND:
726 case POP3_GETRANGE_STAT_RECV:
727 progress_dialog_set_label
728 (dialog, _("Getting the number of new messages (STAT)..."));
730 case POP3_GETRANGE_LAST_SEND:
731 case POP3_GETRANGE_LAST_RECV:
732 progress_dialog_set_label
733 (dialog, _("Getting the number of new messages (LAST)..."));
735 case POP3_GETRANGE_UIDL_SEND:
736 case POP3_GETRANGE_UIDL_RECV:
737 progress_dialog_set_label
738 (dialog, _("Getting the number of new messages (UIDL)..."));
740 case POP3_GETSIZE_LIST_SEND:
741 case POP3_GETSIZE_LIST_RECV:
742 progress_dialog_set_label
743 (dialog, _("Getting the size of messages (LIST)..."));
747 g_snprintf(buf, sizeof(buf),
748 _("Retrieving message (%d / %d) (%d / %d bytes)"),
749 state->cur_msg, state->count,
750 state->cur_total_bytes, state->total_bytes);
751 progress_dialog_set_label(dialog, buf);
752 progress_dialog_set_percentage
754 (gfloat)(state->cur_total_bytes) /
755 (gfloat)(state->total_bytes));
757 case POP3_DELETE_SEND:
758 case POP3_DELETE_RECV:
759 progress_dialog_set_label(dialog, _("Deleting message"));
761 case POP3_LOGOUT_SEND:
762 case POP3_LOGOUT_RECV:
763 progress_dialog_set_label(dialog, _("Quitting"));
769 gint inc_drop_message(const gchar *file, Pop3State *state)
772 FolderItem *dropfolder;
775 if (state->ac_prefs->inbox) {
776 inbox = folder_find_item_from_path(state->ac_prefs->inbox);
778 inbox = folder_get_default_inbox();
780 inbox = folder_get_default_inbox();
786 if (state->ac_prefs->filter_on_recv) {
788 filter_get_dest_folder(prefs_common.fltlist, file);
789 if (!dropfolder) dropfolder = inbox;
790 else if (!strcmp(dropfolder->path, FILTER_NOT_RECEIVE)) {
791 g_warning(_("a message won't be received\n"));
797 val = GPOINTER_TO_INT(g_hash_table_lookup
798 (state->folder_table, dropfolder));
800 folder_item_scan(dropfolder);
801 g_hash_table_insert(state->folder_table, dropfolder,
805 if (folder_item_add_msg(dropfolder, file) < 0) {
814 static void inc_put_error(IncState istate)
818 alertpanel_error(_("Error occurred while processing mail."));
821 alertpanel_error(_("No disk space left."));
827 static void inc_cancel(GtkWidget *widget, gpointer data)
829 IncProgressDialog *dialog = data;
830 IncSession *session = dialog->queue_list->data;
831 SockInfo *sockinfo = session->pop3_state->sockinfo;
834 if (sockinfo->state == CONN_READY ||
835 sockinfo->state == CONN_LOOKUPSUCCESS) {
836 pthread_cancel(sockinfo->connect_thr);
837 //pthread_kill(sockinfo->connect_thr, SIGINT);
838 g_print("connection was cancelled.\n");
842 session->pop3_state->inc_state = INC_CANCEL;
843 pop3_automaton_terminate(sockinfo, session->atm);
846 static gint inc_spool(void)
848 gchar *mbox, *logname;
851 logname = g_get_user_name();
852 mbox = g_strconcat(prefs_common.spool_path
853 ? prefs_common.spool_path : DEFAULT_SPOOL_PATH,
854 G_DIR_SEPARATOR_S, logname, NULL);
855 msgs = get_spool(folder_get_default_inbox(), mbox);
861 static void inc_spool_account(PrefsAccount *account)
864 FolderItem *dropfolder;
867 if (account->inbox) {
868 inbox = folder_find_item_from_path(account->inbox);
870 inbox = folder_get_default_inbox();
872 inbox = folder_get_default_inbox();
874 get_spool(inbox, account->local_mbox);
877 static void inc_all_spool(void)
881 list = account_get_list();
884 for (; list != NULL; list = list->next) {
886 PrefsAccount *account = list->data;
888 if (account->protocol == A_LOCAL)
889 inc_spool_account(account);
893 static gint get_spool(FolderItem *dest, const gchar *mbox)
897 /* gchar tmp_mbox[256] = "/tmp/tmpmboxXXXXXX"; */
898 gchar tmp_mbox[MAXPATHLEN + 1];
899 GHashTable *folder_table = NULL;
901 g_return_val_if_fail(dest != NULL, -1);
902 g_return_val_if_fail(mbox != NULL, -1);
904 if (!is_file_exist(mbox) || (size = get_file_size(mbox)) == 0) {
905 debug_print(_("no messages in local mailbox.\n"));
910 if ((lockfd = lock_mbox(mbox, LOCK_FLOCK)) < 0)
913 g_snprintf(tmp_mbox, sizeof(tmp_mbox), "%s%ctmpmbox%d",
914 get_rc_dir(), G_DIR_SEPARATOR, (gint)mbox);
916 if (mktemp(tmp_mbox) == NULL)
920 if (copy_mbox(mbox, tmp_mbox) < 0)
923 debug_print(_("Getting new messages from %s into %s...\n"),
926 if (prefs_common.filter_on_inc)
927 folder_table = g_hash_table_new(NULL, NULL);
928 msgs = proc_mbox(dest, tmp_mbox, folder_table);
931 if (msgs >= 0) empty_mbox(mbox);
932 unlock_mbox(mbox, lockfd, LOCK_FLOCK);
935 folder_item_scan_foreach(folder_table);
936 folderview_update_item_foreach(folder_table);
937 g_hash_table_destroy(folder_table);
939 folder_item_scan(dest);
940 folderview_update_item(dest, FALSE);
946 static guint autocheck_timer = 0;
947 static gpointer autocheck_data = NULL;
949 void inc_autocheck_timer_init(MainWindow *mainwin)
951 autocheck_data = mainwin;
952 inc_autocheck_timer_set();
955 void inc_autocheck_timer_set(void)
957 inc_autocheck_timer_remove();
959 if (prefs_common.autochk_newmail && autocheck_data) {
960 autocheck_timer = gtk_timeout_add
961 (prefs_common.autochk_itv * 60000,
967 void inc_autocheck_timer_remove(void)
969 if (autocheck_timer) {
970 gtk_timeout_remove(autocheck_timer);
975 static gint inc_autocheck_func(gpointer data)
977 MainWindow *mainwin = (MainWindow *)data;
979 inc_all_account_mail(mainwin);