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,
106 static void inc_put_error (IncState istate);
108 static void inc_cancel (GtkWidget *widget,
111 static gint inc_spool (void);
112 static gint get_spool (FolderItem *dest,
115 static void inc_all_spool(void);
117 static gint inc_autocheck_func (gpointer data);
119 static void inc_finished(MainWindow *mainwin)
123 /* XXX: major problems right here. if we change marks after
124 * incorporation of mail, folderview_select() rewrites it
125 * right under our nose. folderview_select() eventually
126 * calls summary_show(), which rewrites the cache twice:
127 * one for the previously selected FolderItem*, and one
128 * for the newly selected FolderItem*
130 * since filtering also allows changing mark files,
131 * i've solved this by using a global variable (in
132 * SummmaryView*). a better solution is to use the folder
133 * hash table, and see whether the newly and currently
134 * selected FolderItem* where updated by the filtering. */
136 mainwin->summaryview->filtering_happened = TRUE;
138 /* XXX: filtering_happened is reset by summary_show() */
140 if (prefs_common.open_inbox_on_inc) {
141 item = cur_account && cur_account->inbox
142 ? folder_find_item_from_path(cur_account->inbox)
143 : folder_get_default_inbox();
144 folderview_unselect(mainwin->folderview);
145 folderview_select(mainwin->folderview, item);
147 item = mainwin->summaryview->folder_item;
148 folderview_unselect(mainwin->folderview);
149 folderview_select(mainwin->folderview, item);
153 void inc_mail(MainWindow *mainwin)
155 inc_autocheck_timer_remove();
156 summary_write_cache(mainwin->summaryview);
158 if (prefs_common.use_extinc && prefs_common.extinc_path) {
161 /* external incorporating program */
162 if ((pid = fork()) < 0) {
164 inc_autocheck_timer_set();
169 execlp(prefs_common.extinc_path,
170 g_basename(prefs_common.extinc_path),
173 /* this will be called when failed */
178 /* wait until child process is terminated */
179 waitpid(pid, NULL, 0);
181 if (prefs_common.inc_local) inc_spool();
184 if (prefs_common.inc_local) inc_spool();
187 inc_account_mail(cur_account, mainwin);
190 inc_finished(mainwin);
191 inc_autocheck_timer_set();
194 static void inc_account_mail(PrefsAccount *account, MainWindow *mainwin)
196 IncProgressDialog *inc_dialog;
200 session = inc_session_new(account);
201 if (!session) return;
203 inc_dialog = inc_progress_dialog_create();
204 inc_dialog->queue_list = g_list_append(inc_dialog->queue_list, session);
205 inc_dialog->mainwin = mainwin;
206 session->data = inc_dialog;
209 text[1] = account->account_name;
210 text[2] = _("Standby");
211 gtk_clist_append(GTK_CLIST(inc_dialog->dialog->clist), text);
213 inc_start(inc_dialog);
216 void inc_all_account_mail(MainWindow *mainwin)
218 GList *list, *queue_list = NULL;
219 IncProgressDialog *inc_dialog;
221 inc_autocheck_timer_remove();
222 summary_write_cache(mainwin->summaryview);
224 if (prefs_common.inc_local) inc_spool();
226 list = account_get_list();
228 inc_autocheck_timer_set();
232 for (; list != NULL; list = list->next) {
234 PrefsAccount *account = list->data;
236 if (account->recv_at_getall) {
237 session = inc_session_new(account);
239 queue_list = g_list_append(queue_list, session);
244 inc_autocheck_timer_set();
248 inc_dialog = inc_progress_dialog_create();
249 inc_dialog->queue_list = queue_list;
250 inc_dialog->mainwin = mainwin;
251 for (list = queue_list; list != NULL; list = list->next) {
252 IncSession *session = list->data;
255 session->data = inc_dialog;
258 text[1] = session->pop3_state->ac_prefs->account_name;
259 text[2] = _("Standby");
260 gtk_clist_append(GTK_CLIST(inc_dialog->dialog->clist), text);
263 inc_start(inc_dialog);
265 inc_finished(mainwin);
266 inc_autocheck_timer_set();
269 static IncProgressDialog *inc_progress_dialog_create(void)
271 IncProgressDialog *dialog;
272 ProgressDialog *progress;
274 dialog = g_new0(IncProgressDialog, 1);
276 progress = progress_dialog_create();
277 gtk_window_set_title(GTK_WINDOW(progress->window),
278 _("Retrieving new messages"));
279 gtk_signal_connect(GTK_OBJECT(progress->cancel_btn), "clicked",
280 GTK_SIGNAL_FUNC(inc_cancel), dialog);
281 gtk_signal_connect(GTK_OBJECT(progress->window), "delete_event",
282 GTK_SIGNAL_FUNC(gtk_true), NULL);
283 if((prefs_common.receive_dialog == RECVDIALOG_ALWAYS) ||
284 ((prefs_common.receive_dialog == RECVDIALOG_WINDOW_ACTIVE) && focus_window)) {
285 manage_window_set_transient(GTK_WINDOW(progress->window));
288 progress_dialog_set_value(progress, 0.0);
290 if((prefs_common.receive_dialog == RECVDIALOG_ALWAYS) ||
291 ((prefs_common.receive_dialog == RECVDIALOG_WINDOW_ACTIVE) && focus_window)) {
292 gtk_widget_show(progress->window);
295 PIXMAP_CREATE(progress->clist, okxpm, okxpmmask, complete_xpm);
296 PIXMAP_CREATE(progress->clist,
297 currentxpm, currentxpmmask, continue_xpm);
298 PIXMAP_CREATE(progress->clist, errorxpm, errorxpmmask, error_xpm);
300 if((prefs_common.receive_dialog == RECVDIALOG_ALWAYS) ||
301 ((prefs_common.receive_dialog == RECVDIALOG_WINDOW_ACTIVE) && focus_window)) {
302 gtk_widget_show_now(progress->window);
305 dialog->dialog = progress;
306 dialog->queue_list = NULL;
311 static void inc_progress_dialog_clear(IncProgressDialog *inc_dialog)
313 progress_dialog_set_value(inc_dialog->dialog, 0.0);
314 progress_dialog_set_label(inc_dialog->dialog, "");
317 static void inc_progress_dialog_destroy(IncProgressDialog *inc_dialog)
319 g_return_if_fail(inc_dialog != NULL);
321 progress_dialog_destroy(inc_dialog->dialog);
326 static IncSession *inc_session_new(PrefsAccount *account)
330 g_return_val_if_fail(account != NULL, NULL);
332 if (account->protocol != A_POP3 && account->protocol != A_APOP)
334 if (!account->recv_server || !account->userid)
337 session = g_new0(IncSession, 1);
338 session->pop3_state = inc_pop3_state_new(account);
339 session->pop3_state->session = session;
344 static void inc_session_destroy(IncSession *session)
346 g_return_if_fail(session != NULL);
348 inc_pop3_state_destroy(session->pop3_state);
352 static Pop3State *inc_pop3_state_new(PrefsAccount *account)
356 state = g_new0(Pop3State, 1);
358 state->ac_prefs = account;
359 state->folder_table = g_hash_table_new(NULL, NULL);
360 state->id_table = inc_get_uidl_table(account);
361 state->id_list = NULL;
362 state->new_id_list = NULL;
363 state->inc_state = INC_SUCCESS;
368 static void inc_pop3_state_destroy(Pop3State *state)
370 g_hash_table_destroy(state->folder_table);
371 g_free(state->sizes);
373 if (state->id_table) {
374 hash_free_strings(state->id_table);
375 g_hash_table_destroy(state->id_table);
377 slist_free_strings(state->id_list);
378 slist_free_strings(state->new_id_list);
379 g_slist_free(state->id_list);
380 g_slist_free(state->new_id_list);
382 g_free(state->greeting);
385 g_free(state->prev_folder);
390 static void inc_start(IncProgressDialog *inc_dialog)
393 GtkCList *clist = GTK_CLIST(inc_dialog->dialog->clist);
394 Pop3State *pop3_state;
399 while (inc_dialog->queue_list != NULL) {
400 session = inc_dialog->queue_list->data;
401 pop3_state = session->pop3_state;
403 inc_progress_dialog_clear(inc_dialog);
405 gtk_clist_moveto(clist, num, 0, 1.0, 0.0);
407 pop3_state->user = g_strdup(pop3_state->ac_prefs->userid);
408 if (pop3_state->ac_prefs->passwd)
410 g_strdup(pop3_state->ac_prefs->passwd);
411 else if (pop3_state->ac_prefs->tmp_pass)
413 g_strdup(pop3_state->ac_prefs->tmp_pass);
418 message = g_strdup_printf
419 (_("Input password for %s on %s:"),
421 pop3_state->ac_prefs->recv_server);
423 pass = input_dialog_with_invisible(_("Input password"),
426 if((prefs_common.receive_dialog == RECVDIALOG_ALWAYS) ||
427 ((prefs_common.receive_dialog == RECVDIALOG_WINDOW_ACTIVE) && focus_window)) {
428 manage_window_focus_in(inc_dialog->mainwin->window,
432 pop3_state->ac_prefs->tmp_pass = g_strdup(pass);
433 pop3_state->pass = pass;
435 inc_session_destroy(session);
436 inc_dialog->queue_list = g_list_remove
437 (inc_dialog->queue_list, session);
442 gtk_clist_set_pixmap(clist, num, 0, currentxpm, currentxpmmask);
443 gtk_clist_set_text(clist, num, 2, _("Retrieving"));
445 /* begin POP3 session */
446 inc_state = inc_pop3_session_do(session);
448 if (inc_state == INC_SUCCESS || inc_state == INC_CANCEL) {
449 gtk_clist_set_pixmap(clist, num, 0, okxpm, okxpmmask);
450 gtk_clist_set_text(clist, num, 2, _("Done"));
452 gtk_clist_set_pixmap(clist, num, 0, errorxpm, errorxpmmask);
453 gtk_clist_set_text(clist, num, 2, _("Error"));
456 if (pop3_state->error_val == PS_AUTHFAIL) {
457 if(!prefs_common.noerrorpanel) {
458 if((prefs_common.receive_dialog == RECVDIALOG_ALWAYS) ||
459 ((prefs_common.receive_dialog == RECVDIALOG_WINDOW_ACTIVE) && focus_window)) {
460 manage_window_focus_in(inc_dialog->dialog->window, NULL, NULL);
463 (_("Authorization for %s on %s failed"),
465 pop3_state->ac_prefs->recv_server);
470 if((prefs_common.receive_dialog == RECVDIALOG_ALWAYS) ||
471 ((prefs_common.receive_dialog == RECVDIALOG_WINDOW_ACTIVE) && focus_window)) {
472 manage_window_focus_in(inc_dialog->mainwin->window, NULL, NULL);
475 folder_item_scan_foreach(pop3_state->folder_table);
476 folderview_update_item_foreach(pop3_state->folder_table);
478 if (pop3_state->error_val == PS_AUTHFAIL &&
479 pop3_state->ac_prefs->tmp_pass) {
480 g_free(pop3_state->ac_prefs->tmp_pass);
481 pop3_state->ac_prefs->tmp_pass = NULL;
484 inc_write_uidl_list(pop3_state);
486 if (inc_state != INC_SUCCESS) {
487 inc_put_error(inc_state);
489 if (inc_state == INC_NOSPACE) break;
492 inc_session_destroy(session);
493 inc_dialog->queue_list =
494 g_list_remove(inc_dialog->queue_list, session);
500 alertpanel_error(_("Some errors occured while getting mail."));
502 while (inc_dialog->queue_list != NULL) {
503 session = inc_dialog->queue_list->data;
504 inc_session_destroy(session);
505 inc_dialog->queue_list =
506 g_list_remove(inc_dialog->queue_list, session);
509 inc_progress_dialog_destroy(inc_dialog);
513 static IncState inc_pop3_session_do(IncSession *session)
515 Pop3State *pop3_state = session->pop3_state;
516 IncProgressDialog *inc_dialog = (IncProgressDialog *)session->data;
523 static AtmHandler handlers[] = {
525 pop3_getauth_user_send , pop3_getauth_user_recv,
526 pop3_getauth_pass_send , pop3_getauth_pass_recv,
527 pop3_getauth_apop_send , pop3_getauth_apop_recv,
528 pop3_getrange_stat_send , pop3_getrange_stat_recv,
529 pop3_getrange_last_send , pop3_getrange_last_recv,
530 pop3_getrange_uidl_send , pop3_getrange_uidl_recv,
531 pop3_getsize_list_send , pop3_getsize_list_recv,
532 pop3_retr_send , pop3_retr_recv,
533 pop3_delete_send , pop3_delete_recv,
534 pop3_logout_send , pop3_logout_recv
537 debug_print(_("getting new messages of account %s...\n"),
538 pop3_state->ac_prefs->account_name);
540 atm = automaton_create(N_POP3_PHASE);
543 atm->data = pop3_state;
545 buf = g_strdup_printf(_("%s: Retrieving new messages"),
546 pop3_state->ac_prefs->recv_server);
547 gtk_window_set_title(GTK_WINDOW(inc_dialog->dialog->window), buf);
550 for (i = POP3_GREETING_RECV; i < N_POP3_PHASE; i++)
551 atm->state[i].handler = handlers[i];
552 atm->state[POP3_GREETING_RECV].condition = GDK_INPUT_READ;
553 for (i = POP3_GETAUTH_USER_SEND; i < N_POP3_PHASE; ) {
554 atm->state[i++].condition = GDK_INPUT_WRITE;
555 atm->state[i++].condition = GDK_INPUT_READ;
558 atm->terminate = (AtmHandler)pop3_automaton_terminate;
560 atm->num = POP3_GREETING_RECV;
562 server = pop3_state->ac_prefs->recv_server;
564 port = pop3_state->ac_prefs->set_popport ?
565 pop3_state->ac_prefs->popport : (pop3_state->ac_prefs->pop_ssl ? 995 : 110);
567 port = pop3_state->ac_prefs->set_popport ?
568 pop3_state->ac_prefs->popport : 110;
571 buf = g_strdup_printf(_("Connecting to POP3 server: %s ..."), server);
572 log_message("%s\n", buf);
573 progress_dialog_set_label(inc_dialog->dialog, buf);
578 if ((sockinfo = sock_connect_with_thread(server, port)) == NULL) {
580 if ((sockinfo = sock_connect(server, port)) == NULL) {
582 log_warning(_("Can't connect to POP3 server: %s:%d\n"),
584 if(!prefs_common.noerrorpanel) {
585 if((prefs_common.receive_dialog == RECVDIALOG_ALWAYS) ||
586 ((prefs_common.receive_dialog == RECVDIALOG_WINDOW_ACTIVE) && focus_window)) {
587 manage_window_focus_in(inc_dialog->dialog->window, NULL, NULL);
589 alertpanel_error(_("Can't connect to POP3 server: %s:%d"),
591 manage_window_focus_out(inc_dialog->dialog->window, NULL, NULL);
593 pop3_automaton_terminate(NULL, atm);
594 automaton_destroy(atm);
599 /* :WK: Hmmm, with the later sock_gdk_input, we have 2 references
600 * to the sock structure - implement a reference counter?? */
601 pop3_state->sockinfo = sockinfo;
602 atm->help_sock = sockinfo;
605 if(pop3_state->ac_prefs->pop_ssl) {
606 if(!ssl_init_socket(sockinfo)) {
607 pop3_automaton_terminate(NULL, atm);
608 automaton_destroy(atm);
613 sockinfo->ssl = NULL;
617 recv_set_ui_func(inc_pop3_recv_func, session);
620 atm->timeout_tag = gtk_timeout_add
621 (TIMEOUT_ITV, (GtkFunction)connection_check_cb, atm);
623 atm->tag = sock_gdk_input_add(sockinfo,
624 atm->state[atm->num].condition,
625 automaton_input_cb, atm);
630 recv_set_ui_func(NULL, NULL);
634 pthread_join(sockinfo->connect_thr, NULL);
639 ssl_done_socket(sockinfo);
641 automaton_destroy(atm);
643 return pop3_state->inc_state;
646 static gint pop3_automaton_terminate(SockInfo *source, Automaton *atm)
649 gdk_input_remove(atm->tag);
652 if (atm->timeout_tag > 0) {
653 gtk_timeout_remove(atm->timeout_tag);
654 atm->timeout_tag = 0;
661 atm->terminated = TRUE;
666 static GHashTable *inc_get_uidl_table(PrefsAccount *ac_prefs)
671 gchar buf[IDLEN + 3];
673 path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
674 "uidl-", ac_prefs->recv_server,
675 "-", ac_prefs->userid, NULL);
676 if ((fp = fopen(path, "r")) == NULL) {
677 if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
683 table = g_hash_table_new(g_str_hash, g_str_equal);
685 while (fgets(buf, sizeof(buf), fp) != NULL) {
687 g_hash_table_insert(table, g_strdup(buf), GINT_TO_POINTER(1));
695 static void inc_write_uidl_list(Pop3State *state)
701 if (!state->id_list) return;
703 path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
704 "uidl-", state->ac_prefs->recv_server,
705 "-", state->user, NULL);
706 if ((fp = fopen(path, "w")) == NULL) {
707 FILE_OP_ERROR(path, "fopen");
712 for (cur = state->id_list; cur != NULL; cur = cur->next) {
713 if (fputs((gchar *)cur->data, fp) == EOF) {
714 FILE_OP_ERROR(path, "fputs");
717 if (fputc('\n', fp) == EOF) {
718 FILE_OP_ERROR(path, "fputc");
723 if (fclose(fp) == EOF) FILE_OP_ERROR(path, "fclose");
728 static gint connection_check_cb(Automaton *atm)
730 Pop3State *state = atm->data;
731 IncProgressDialog *inc_dialog = state->session->data;
732 SockInfo *sockinfo = state->sockinfo;
734 /* g_print("connection check\n"); */
736 if (sockinfo->state == CONN_LOOKUPFAILED ||
737 sockinfo->state == CONN_FAILED) {
738 atm->timeout_tag = 0;
739 log_warning(_("Can't connect to POP3 server: %s:%d\n"),
740 sockinfo->hostname, sockinfo->port);
741 if(!prefs_common.noerrorpanel) {
742 if((prefs_common.receive_dialog == RECVDIALOG_ALWAYS) ||
743 ((prefs_common.receive_dialog == RECVDIALOG_WINDOW_ACTIVE) && focus_window)) {
744 manage_window_focus_in(inc_dialog->dialog->window, NULL, NULL);
746 alertpanel_error(_("Can't connect to POP3 server: %s:%d"),
747 sockinfo->hostname, sockinfo->port);
748 manage_window_focus_out(inc_dialog->dialog->window, NULL, NULL);
750 pop3_automaton_terminate(sockinfo, atm);
752 } else if (sockinfo->state == CONN_ESTABLISHED) {
753 atm->timeout_tag = 0;
754 atm->tag = sock_gdk_input_add(sockinfo,
755 atm->state[atm->num].condition,
756 automaton_input_cb, atm);
764 static void inc_pop3_recv_func(SockInfo *sock, gint count, gint read_bytes,
767 gchar buf[MSGBUFSIZE];
768 IncSession *session = (IncSession *)data;
769 Pop3State *state = session->pop3_state;
770 IncProgressDialog *inc_dialog = session->data;
771 ProgressDialog *dialog = inc_dialog->dialog;
775 cur_total = state->cur_total_bytes + read_bytes;
776 if (cur_total > state->total_bytes)
777 cur_total = state->total_bytes;
779 Xstrdup_a(total_size, to_human_readable(state->total_bytes), return);
780 g_snprintf(buf, sizeof(buf),
781 _("Retrieving message (%d / %d) (%s / %s)"),
782 state->cur_msg, state->count,
783 to_human_readable(cur_total), total_size);
784 progress_dialog_set_label(dialog, buf);
786 progress_dialog_set_percentage
787 (dialog, (gfloat)cur_total / (gfloat)state->total_bytes);
791 void inc_progress_update(Pop3State *state, Pop3Phase phase)
793 gchar buf[MSGBUFSIZE];
794 IncProgressDialog *inc_dialog = state->session->data;
795 ProgressDialog *dialog = inc_dialog->dialog;
799 case POP3_GREETING_RECV:
801 case POP3_GETAUTH_USER_SEND:
802 case POP3_GETAUTH_USER_RECV:
803 case POP3_GETAUTH_PASS_SEND:
804 case POP3_GETAUTH_PASS_RECV:
805 case POP3_GETAUTH_APOP_SEND:
806 case POP3_GETAUTH_APOP_RECV:
807 progress_dialog_set_label(dialog, _("Authorizing..."));
809 case POP3_GETRANGE_STAT_SEND:
810 case POP3_GETRANGE_STAT_RECV:
811 progress_dialog_set_label
812 (dialog, _("Getting the number of new messages (STAT)..."));
814 case POP3_GETRANGE_LAST_SEND:
815 case POP3_GETRANGE_LAST_RECV:
816 progress_dialog_set_label
817 (dialog, _("Getting the number of new messages (LAST)..."));
819 case POP3_GETRANGE_UIDL_SEND:
820 case POP3_GETRANGE_UIDL_RECV:
821 progress_dialog_set_label
822 (dialog, _("Getting the number of new messages (UIDL)..."));
824 case POP3_GETSIZE_LIST_SEND:
825 case POP3_GETSIZE_LIST_RECV:
826 progress_dialog_set_label
827 (dialog, _("Getting the size of messages (LIST)..."));
831 Xstrdup_a(total_size, to_human_readable(state->total_bytes), return);
832 g_snprintf(buf, sizeof(buf),
833 _("Retrieving message (%d / %d) (%s / %s)"),
834 state->cur_msg, state->count,
835 to_human_readable(state->cur_total_bytes),
837 progress_dialog_set_label(dialog, buf);
838 progress_dialog_set_percentage
840 (gfloat)(state->cur_total_bytes) /
841 (gfloat)(state->total_bytes));
843 case POP3_DELETE_SEND:
844 case POP3_DELETE_RECV:
845 progress_dialog_set_label(dialog, _("Deleting message"));
847 case POP3_LOGOUT_SEND:
848 case POP3_LOGOUT_RECV:
849 progress_dialog_set_label(dialog, _("Quitting"));
856 gint inc_drop_message(const gchar *file, Pop3State *state)
859 FolderItem *dropfolder;
863 if (state->ac_prefs->inbox) {
864 inbox = folder_find_item_from_path(state->ac_prefs->inbox);
866 inbox = folder_get_default_inbox();
868 inbox = folder_get_default_inbox();
874 if (prefs_filtering == NULL) {
876 if (state->ac_prefs->filter_on_recv) {
878 filter_get_dest_folder(prefs_common.fltlist, file);
879 if (!dropfolder) dropfolder = inbox;
880 else if (!strcmp(dropfolder->path, FILTER_NOT_RECEIVE)) {
881 g_warning(_("a message won't be received\n"));
891 val = GPOINTER_TO_INT(g_hash_table_lookup
892 (state->folder_table, dropfolder));
894 folder_item_scan(dropfolder);
895 g_hash_table_insert(state->folder_table, dropfolder,
899 if (prefs_filtering == NULL || !state->ac_prefs->filter_on_recv) {
900 if ((msgnum = folder_item_add_msg(dropfolder, file, TRUE)) < 0) {
906 filter_incoming_message(dropfolder, file, state->folder_table);
912 static void inc_put_error(IncState istate)
916 if(!prefs_common.noerrorpanel) {
917 alertpanel_error(_("Error occurred while processing mail."));
921 alertpanel_error(_("No disk space left."));
928 static void inc_cancel(GtkWidget *widget, gpointer data)
930 IncProgressDialog *dialog = data;
931 IncSession *session = dialog->queue_list->data;
932 SockInfo *sockinfo = session->pop3_state->sockinfo;
935 if (sockinfo->state == CONN_READY ||
936 sockinfo->state == CONN_LOOKUPSUCCESS) {
937 pthread_cancel(sockinfo->connect_thr);
938 /* pthread_kill(sockinfo->connect_thr, SIGINT); */
939 g_print("connection was cancelled.\n");
943 session->pop3_state->inc_state = INC_CANCEL;
944 pop3_automaton_terminate(sockinfo, session->atm);
947 static gint inc_spool(void)
949 gchar *mbox, *logname;
952 logname = g_get_user_name();
953 mbox = g_strconcat(prefs_common.spool_path
954 ? prefs_common.spool_path : DEFAULT_SPOOL_PATH,
955 G_DIR_SEPARATOR_S, logname, NULL);
956 msgs = get_spool(folder_get_default_inbox(), mbox);
962 static void inc_spool_account(PrefsAccount *account)
965 FolderItem *dropfolder;
968 if (account->inbox) {
969 inbox = folder_find_item_from_path(account->inbox);
971 inbox = folder_get_default_inbox();
973 inbox = folder_get_default_inbox();
975 get_spool(inbox, account->local_mbox);
978 static void inc_all_spool(void)
982 list = account_get_list();
985 for (; list != NULL; list = list->next) {
987 PrefsAccount *account = list->data;
989 if (account->protocol == A_LOCAL)
990 inc_spool_account(account);
994 static gint get_spool(FolderItem *dest, const gchar *mbox)
998 gchar tmp_mbox[MAXPATHLEN + 1];
999 GHashTable *folder_table = NULL;
1001 g_return_val_if_fail(dest != NULL, -1);
1002 g_return_val_if_fail(mbox != NULL, -1);
1004 if (!is_file_exist(mbox) || (size = get_file_size(mbox)) == 0) {
1005 debug_print(_("no messages in local mailbox.\n"));
1007 } else if (size < 0)
1010 if ((lockfd = lock_mbox(mbox, LOCK_FLOCK)) < 0)
1013 g_snprintf(tmp_mbox, sizeof(tmp_mbox), "%s%ctmpmbox%d",
1014 get_rc_dir(), G_DIR_SEPARATOR, (gint)mbox);
1016 if (copy_mbox(mbox, tmp_mbox) < 0)
1019 debug_print(_("Getting new messages from %s into %s...\n"),
1022 if (prefs_common.filter_on_inc)
1023 folder_table = g_hash_table_new(NULL, NULL);
1024 msgs = proc_mbox(dest, tmp_mbox, folder_table);
1027 if (msgs >= 0) empty_mbox(mbox);
1028 unlock_mbox(mbox, lockfd, LOCK_FLOCK);
1031 g_hash_table_insert(folder_table, dest,
1032 GINT_TO_POINTER(1));
1033 folder_item_scan_foreach(folder_table);
1034 folderview_update_item_foreach(folder_table);
1035 g_hash_table_destroy(folder_table);
1037 folder_item_scan(dest);
1038 folderview_update_item(dest, FALSE);
1044 static guint autocheck_timer = 0;
1045 static gpointer autocheck_data = NULL;
1047 void inc_autocheck_timer_init(MainWindow *mainwin)
1049 autocheck_data = mainwin;
1050 inc_autocheck_timer_set();
1053 void inc_autocheck_timer_set(void)
1055 inc_autocheck_timer_remove();
1057 if (prefs_common.autochk_newmail && autocheck_data) {
1058 autocheck_timer = gtk_timeout_add
1059 (prefs_common.autochk_itv * 60000,
1065 void inc_autocheck_timer_remove(void)
1067 if (autocheck_timer) {
1068 gtk_timeout_remove(autocheck_timer);
1069 autocheck_timer = 0;
1073 static gint inc_autocheck_func(gpointer data)
1075 MainWindow *mainwin = (MainWindow *)data;
1077 inc_all_account_mail(mainwin);