2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2022 the Claws Mail team and 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 3 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, see <http://www.gnu.org/licenses/>.
21 #include "claws-features.h"
27 #include <glib/gi18n.h>
35 #include "mainwindow.h"
36 #include "folderview.h"
37 #include "summaryview.h"
38 #include "prefs_common.h"
39 #include "prefs_account.h"
48 #include "file-utils.h"
51 #include "statusbar.h"
53 #include "manage_window.h"
54 #include "stock_pixmap.h"
55 #include "progressdialog.h"
56 #include "inputdialog.h"
57 #include "alertpanel.h"
59 #include "filtering.h"
62 #include "logwindow.h"
63 #include "passwordstore.h"
68 extern SessionStats session_stats
;
70 static GList
*inc_dialog_list
= NULL
;
72 static time_t inc_offline_overridden_yes
= 0;
73 static time_t inc_offline_overridden_no
= 0;
75 guint inc_lock_count
= 0;
77 static GdkPixbuf
*currentpix
;
78 static GdkPixbuf
*errorpix
;
79 static GdkPixbuf
*okpix
;
81 #define MESSAGEBUFSIZE 8192
83 static void inc_update_stats(gint new_msgs
);
84 static void inc_finished (MainWindow
*mainwin
,
85 gboolean new_messages
,
87 static gint
inc_account_mail_real (MainWindow
*mainwin
,
88 PrefsAccount
*account
);
90 static IncProgressDialog
*inc_progress_dialog_create
92 static void inc_progress_dialog_set_list(IncProgressDialog
*inc_dialog
);
93 static void inc_progress_dialog_destroy (IncProgressDialog
*inc_dialog
);
95 static IncSession
*inc_session_new (PrefsAccount
*account
);
96 static void inc_session_destroy (IncSession
*session
);
97 static gint
inc_start (IncProgressDialog
*inc_dialog
);
98 static IncState
inc_pop3_session_do (IncSession
*session
);
100 static void inc_progress_dialog_update (IncProgressDialog
*inc_dialog
,
101 IncSession
*inc_session
);
103 static void inc_progress_dialog_set_label
104 (IncProgressDialog
*inc_dialog
,
105 IncSession
*inc_session
);
106 static void inc_progress_dialog_set_progress
107 (IncProgressDialog
*inc_dialog
,
108 IncSession
*inc_session
);
110 static void inc_progress_dialog_update_periodic
111 (IncProgressDialog
*inc_dialog
,
112 IncSession
*inc_session
);
114 static gint
inc_recv_data_progressive (Session
*session
,
118 static gint
inc_recv_data_finished (Session
*session
,
121 static gint
inc_recv_message (Session
*session
,
124 static gint
inc_drop_message (Pop3Session
*session
,
127 static void inc_put_error (IncState istate
,
128 Pop3Session
*session
);
130 static void inc_showlog_cb (GtkWidget
*widget
,
132 static void inc_cancel_cb (GtkWidget
*widget
,
134 static gint
inc_dialog_delete_cb (GtkWidget
*widget
,
138 static gint
get_spool (FolderItem
*dest
,
140 PrefsAccount
*account
);
142 static gint
inc_spool_account(PrefsAccount
*account
);
143 static void inc_autocheck_timer_set_interval (guint interval
);
144 static gint
inc_autocheck_func (gpointer data
);
146 static void inc_notify_cmd (gint new_msgs
,
149 static void inc_update_stats(gint new_msgs
)
151 /* update session statistics */
152 session_stats
.received
+= new_msgs
;
157 * @mainwin: Main window.
158 * @new_messages: TRUE if some messages have been received.
160 * Update the folder view and the summary view after receiving
161 * messages. If @new_messages is FALSE, this function avoids unneeded
164 static void inc_finished(MainWindow
*mainwin
, gboolean new_messages
, gboolean autocheck
)
166 if (prefs_common
.scan_all_after_inc
)
167 folderview_check_new(NULL
);
169 if (!autocheck
&& new_messages
&& prefs_common
.open_inbox_on_inc
) {
170 FolderItem
*item
= NULL
;
172 if (cur_account
&& cur_account
->inbox
)
173 item
= folder_find_item_from_identifier(cur_account
->inbox
);
174 if (item
== NULL
&& cur_account
&& cur_account
->folder
)
175 item
= cur_account
->folder
->inbox
;
177 item
= folder_get_default_inbox();
179 folderview_unselect(mainwin
->folderview
);
180 folderview_select(mainwin
->folderview
, item
);
182 statusbar_progress_all(0,0,0);
185 void inc_mail(MainWindow
*mainwin
, gboolean notify
)
188 gint account_new_msgs
= 0;
190 if (inc_lock_count
) return;
192 if (prefs_common
.work_offline
&&
193 !inc_offline_should_override(TRUE
,
194 _("Claws Mail needs network access in order "
199 inc_autocheck_timer_remove();
200 main_window_lock(mainwin
);
202 if (prefs_common
.use_extinc
&& prefs_common
.extinc_cmd
) {
203 /* external incorporating program */
204 if (execute_command_line(prefs_common
.extinc_cmd
, FALSE
, NULL
) < 0) {
205 main_window_unlock(mainwin
);
206 inc_autocheck_timer_set();
211 account_new_msgs
= inc_account_mail_real(mainwin
, cur_account
);
212 if (account_new_msgs
> 0)
213 new_msgs
+= account_new_msgs
;
216 inc_update_stats(new_msgs
);
217 inc_finished(mainwin
, new_msgs
> 0, FALSE
);
218 main_window_unlock(mainwin
);
219 inc_notify_cmd(new_msgs
, notify
);
220 inc_autocheck_timer_set();
224 void inc_pop_before_smtp(PrefsAccount
*acc
)
226 IncProgressDialog
*inc_dialog
;
230 mainwin
= mainwindow_get_mainwindow();
232 session
= inc_session_new(acc
);
233 if (!session
) return;
234 POP3_SESSION(session
->session
)->pop_before_smtp
= TRUE
;
236 inc_dialog
= inc_progress_dialog_create(FALSE
);
237 inc_dialog
->queue_list
= g_list_append(inc_dialog
->queue_list
,
239 /* FIXME: assumes to attach to first main window */
240 inc_dialog
->mainwin
= mainwin
;
241 inc_progress_dialog_set_list(inc_dialog
);
244 toolbar_main_set_sensitive(mainwin
);
245 main_window_set_menu_sensitive(mainwin
);
248 inc_start(inc_dialog
);
251 static gint
inc_account_mail_real(MainWindow
*mainwin
, PrefsAccount
*account
)
253 IncProgressDialog
*inc_dialog
;
256 switch (account
->protocol
) {
260 * FIXME: it should return foldeview_check_new() value.
261 * TODO: do it when bug [19] is fixed (IMAP folder sets
262 * an incorrect new message count)
264 folderview_check_new(FOLDER(account
->folder
));
267 session
= inc_session_new(account
);
268 if (!session
) return 0;
270 inc_dialog
= inc_progress_dialog_create(FALSE
);
271 inc_dialog
->queue_list
= g_list_append(inc_dialog
->queue_list
,
273 inc_dialog
->mainwin
= mainwin
;
274 inc_progress_dialog_set_list(inc_dialog
);
277 toolbar_main_set_sensitive(mainwin
);
278 main_window_set_menu_sensitive(mainwin
);
281 return inc_start(inc_dialog
);
284 return inc_spool_account(account
);
292 gint
inc_account_mail(MainWindow
*mainwin
, PrefsAccount
*account
)
296 if (inc_lock_count
) return 0;
298 if (account
->receive_in_progress
) return 0;
300 if (prefs_common
.work_offline
&&
301 !inc_offline_should_override(TRUE
,
302 _("Claws Mail needs network access in order "
306 inc_autocheck_timer_remove();
307 main_window_lock(mainwin
);
309 new_msgs
= inc_account_mail_real(mainwin
, account
);
311 inc_update_stats(new_msgs
);
312 inc_finished(mainwin
, new_msgs
> 0, FALSE
);
313 main_window_unlock(mainwin
);
314 inc_autocheck_timer_set();
319 void inc_account_list_mail(MainWindow
*mainwin
, GList
*account_list
, gboolean autocheck
,
322 GList
*list
, *queue_list
= NULL
;
323 IncProgressDialog
*inc_dialog
;
324 gint new_msgs
= 0, num
;
326 if (prefs_common
.work_offline
&&
327 !inc_offline_should_override( (autocheck
== FALSE
),
328 _("Claws Mail needs network access in order "
332 if (inc_lock_count
) return;
334 main_window_lock(mainwin
);
337 inc_update_stats(new_msgs
);
338 inc_finished(mainwin
, new_msgs
> 0, autocheck
);
339 main_window_unlock(mainwin
);
340 inc_notify_cmd(new_msgs
, notify
);
344 if (prefs_common
.use_extinc
&& prefs_common
.extinc_cmd
) {
345 /* external incorporating program */
346 if (execute_command_line(prefs_common
.extinc_cmd
, FALSE
, NULL
) < 0) {
347 log_error(LOG_PROTOCOL
, _("%s failed\n"), prefs_common
.extinc_cmd
);
349 main_window_unlock(mainwin
);
354 /* Check all accounts in the list, one by one. */
355 for (list
= account_list
; list
!= NULL
; list
= list
->next
) {
356 PrefsAccount
*account
= list
->data
;
358 if (account
== NULL
) {
359 debug_print("INC: Huh? inc_account_list_mail() got a NULL account, this should not happen!\n");
363 debug_print("INC: checking account %d\n", account
->account_id
);
364 switch (account
->protocol
) {
366 if (!(account
->receive_in_progress
)) {
367 IncSession
*session
= inc_session_new(account
);
369 if (session
!= NULL
) {
370 debug_print("INC: adding POP3 account %d to inc queue\n",
371 account
->account_id
);
372 queue_list
= g_list_append(queue_list
, session
);
379 new_msgs
+= folderview_check_new(FOLDER(account
->folder
));
383 num
= inc_spool_account(account
);
389 /* Nothing to do here, it's a SMTP-only account. */
393 debug_print("INC: encountered account %d with unknown protocol %d, ignoring\n",
394 account
->account_id
, account
->protocol
);
402 inc_dialog
= inc_progress_dialog_create(autocheck
);
403 inc_dialog
->queue_list
= queue_list
;
404 inc_dialog
->mainwin
= mainwin
;
405 inc_progress_dialog_set_list(inc_dialog
);
407 toolbar_main_set_sensitive(mainwin
);
408 main_window_set_menu_sensitive(mainwin
);
409 new_msgs
+= inc_start(inc_dialog
);
412 inc_update_stats(new_msgs
);
413 inc_finished(mainwin
, new_msgs
> 0, autocheck
);
414 main_window_unlock(mainwin
);
415 inc_notify_cmd(new_msgs
, notify
);
418 void inc_all_account_mail(MainWindow
*mainwin
, gboolean autocheck
,
419 gboolean check_at_startup
, gboolean notify
)
421 GList
*list
, *list2
= NULL
;
422 gboolean condition
= FALSE
;
423 gboolean hide_dialog
= FALSE
;
425 debug_print("INC: inc_all_account_mail(), autocheck: %s\n",
426 autocheck
? "YES" : "NO");
428 /* Collect list of accounts which use the global autocheck interval. */
429 for (list
= account_get_list(); list
!= NULL
; list
= list
->next
) {
430 PrefsAccount
*account
= list
->data
;
432 /* Nothing to do for SMTP-only accounts. */
433 if (account
->protocol
== A_NONE
)
436 /* Set up condition which decides whether or not to check
437 * this account, based on whether we're doing global autocheck
438 * or a check at startup or a manual 'Get all' check. */
440 condition
= prefs_common_get_prefs()->autochk_newmail
441 && account
->autochk_use_default
;
442 else if (check_at_startup
|| (!check_at_startup
&& !autocheck
))
443 condition
= account
->recv_at_getall
;
446 debug_print("INC: will check account %d\n", account
->account_id
);
447 list2
= g_list_append(list2
, account
);
451 /* Do the check on the collected accounts. */
453 if (autocheck
|| check_at_startup
)
455 inc_account_list_mail(mainwin
, list2
, hide_dialog
, notify
);
460 static void inc_progress_dialog_size_allocate_cb(GtkWidget
*widget
,
461 GtkAllocation
*allocation
)
463 cm_return_if_fail(allocation
!= NULL
);
465 gtk_window_get_size(GTK_WINDOW(widget
),
466 &prefs_common
.receivewin_width
, &prefs_common
.receivewin_height
);
469 static IncProgressDialog
*inc_progress_dialog_create(gboolean autocheck
)
471 IncProgressDialog
*dialog
;
472 ProgressDialog
*progress
;
473 static GdkGeometry geometry
;
475 dialog
= g_new0(IncProgressDialog
, 1);
477 progress
= progress_dialog_create();
478 gtk_window_set_title(GTK_WINDOW(progress
->window
),
479 _("Retrieving new messages"));
480 g_signal_connect(G_OBJECT(progress
->showlog_btn
), "clicked",
481 G_CALLBACK(inc_showlog_cb
), dialog
);
482 g_signal_connect(G_OBJECT(progress
->cancel_btn
), "clicked",
483 G_CALLBACK(inc_cancel_cb
), dialog
);
484 g_signal_connect(G_OBJECT(progress
->window
), "delete_event",
485 G_CALLBACK(inc_dialog_delete_cb
), dialog
);
486 g_signal_connect(G_OBJECT(progress
->window
), "size_allocate",
487 G_CALLBACK(inc_progress_dialog_size_allocate_cb
), NULL
);
488 /* manage_window_set_transient(GTK_WINDOW(progress->window)); */
490 progress_dialog_get_fraction(progress
);
492 stock_pixbuf_gdk(STOCK_PIXMAP_COMPLETE
, &okpix
);
493 stock_pixbuf_gdk(STOCK_PIXMAP_CONTINUE
, ¤tpix
);
494 stock_pixbuf_gdk(STOCK_PIXMAP_ERROR
, &errorpix
);
496 if (!geometry
.min_height
) {
497 geometry
.min_width
= 460;
498 geometry
.min_height
= 250;
501 gtk_window_set_geometry_hints(GTK_WINDOW(progress
->window
), NULL
, &geometry
,
503 gtk_widget_set_size_request(progress
->window
, prefs_common
.receivewin_width
,
504 prefs_common
.receivewin_height
);
506 if (prefs_common
.recv_dialog_mode
== RECV_DIALOG_ALWAYS
||
507 (prefs_common
.recv_dialog_mode
== RECV_DIALOG_MANUAL
&&
509 dialog
->show_dialog
= TRUE
;
510 gtk_widget_show_now(progress
->window
);
513 dialog
->dialog
= progress
;
514 dialog
->progress_tv
= g_date_time_new_now_local();
515 dialog
->folder_tv
= g_date_time_new_now_local();
516 dialog
->queue_list
= NULL
;
519 inc_dialog_list
= g_list_append(inc_dialog_list
, dialog
);
524 static void inc_progress_dialog_set_list(IncProgressDialog
*inc_dialog
)
528 for (list
= inc_dialog
->queue_list
; list
!= NULL
; list
= list
->next
) {
529 IncSession
*session
= list
->data
;
530 Pop3Session
*pop3_session
= POP3_SESSION(session
->session
);
532 session
->data
= inc_dialog
;
534 progress_dialog_list_set(inc_dialog
->dialog
,
536 pop3_session
->ac_prefs
->account_name
,
541 static void inc_progress_dialog_clear(IncProgressDialog
*inc_dialog
)
543 progress_dialog_get_fraction(inc_dialog
->dialog
);
544 progress_dialog_set_label(inc_dialog
->dialog
, "");
545 if (inc_dialog
->mainwin
)
546 main_window_progress_off(inc_dialog
->mainwin
);
549 static void inc_progress_dialog_destroy(IncProgressDialog
*inc_dialog
)
551 cm_return_if_fail(inc_dialog
!= NULL
);
553 inc_dialog_list
= g_list_remove(inc_dialog_list
, inc_dialog
);
555 if (inc_dialog
->mainwin
)
556 main_window_progress_off(inc_dialog
->mainwin
);
557 progress_dialog_destroy(inc_dialog
->dialog
);
559 g_date_time_unref(inc_dialog
->progress_tv
);
560 g_date_time_unref(inc_dialog
->folder_tv
);
565 static IncSession
*inc_session_new(PrefsAccount
*account
)
569 cm_return_val_if_fail(account
!= NULL
, NULL
);
571 if (account
->protocol
!= A_POP3
)
573 if (!account
->recv_server
|| !account
->userid
)
576 session
= g_new0(IncSession
, 1);
578 session
->session
= pop3_session_new(account
);
579 session
->session
->data
= session
;
580 POP3_SESSION(session
->session
)->drop_message
= inc_drop_message
;
581 session_set_recv_message_notify(session
->session
,
582 inc_recv_message
, session
);
583 session_set_recv_data_progressive_notify(session
->session
,
584 inc_recv_data_progressive
,
586 session_set_recv_data_notify(session
->session
,
587 inc_recv_data_finished
, session
);
592 static void inc_session_destroy(IncSession
*session
)
594 cm_return_if_fail(session
!= NULL
);
596 session_destroy(session
->session
);
600 static gint
pop3_get_port(Pop3Session
*pop3_session
)
603 return pop3_session
->ac_prefs
->set_popport
?
604 pop3_session
->ac_prefs
->popport
:
605 pop3_session
->ac_prefs
->ssl_pop
== SSL_TUNNEL
? 995 : 110;
607 return pop3_session
->ac_prefs
->set_popport
?
608 pop3_session
->ac_prefs
->popport
: 110;
612 static gint
inc_start(IncProgressDialog
*inc_dialog
)
616 Pop3Session
*pop3_session
;
622 FolderItem
*processing
, *inbox
;
623 GSList
*msglist
, *msglist_element
;
624 gboolean cancelled
= FALSE
;
626 qlist
= inc_dialog
->queue_list
;
627 while (qlist
!= NULL
) {
628 GList
*next
= qlist
->next
;
630 session
= qlist
->data
;
631 pop3_session
= POP3_SESSION(session
->session
);
632 pop3_session
->user
= g_strdup(pop3_session
->ac_prefs
->userid
);
634 if (inc_dialog
->show_dialog
)
635 manage_window_focus_in
636 (inc_dialog
->dialog
->window
,
639 if(pop3_session
->ac_prefs
->use_pop_auth
&&
640 pop3_session
->ac_prefs
->pop_auth_type
== POPAUTH_OAUTH2
)
641 oauth2_check_passwds (pop3_session
->ac_prefs
);
644 if (password_get(pop3_session
->user
,
645 pop3_session
->ac_prefs
->recv_server
,
646 "pop3", pop3_get_port(pop3_session
),
647 &(pop3_session
->pass
))) {
649 } else if ((pop3_session
->pass
= passwd_store_get_account(
650 pop3_session
->ac_prefs
->account_id
, PWS_ACCOUNT_RECV
)) == NULL
) {
653 pass
= input_dialog_query_password_keep
654 (pop3_session
->ac_prefs
->recv_server
,
656 &(pop3_session
->ac_prefs
->session_passwd
));
659 pop3_session
->pass
= pass
;
663 if (inc_dialog
->show_dialog
)
664 manage_window_focus_out
665 (inc_dialog
->dialog
->window
,
671 #define SET_PIXMAP_AND_TEXT(pix, str) \
673 progress_dialog_list_set(inc_dialog->dialog, \
674 inc_dialog->cur_row, \
680 for (; inc_dialog
->queue_list
!= NULL
&& !cancelled
; inc_dialog
->cur_row
++) {
681 session
= inc_dialog
->queue_list
->data
;
682 pop3_session
= POP3_SESSION(session
->session
);
683 GSList
*filtered
, *unfiltered
;
685 if (pop3_session
->pass
== NULL
) {
686 SET_PIXMAP_AND_TEXT(okpix
, _("Cancelled"));
687 inc_dialog
->queue_list
=
688 g_list_remove(inc_dialog
->queue_list
, session
);
689 inc_session_destroy(session
);
693 inc_progress_dialog_clear(inc_dialog
);
694 progress_dialog_scroll_to_row(inc_dialog
->dialog
,
695 inc_dialog
->cur_row
);
697 SET_PIXMAP_AND_TEXT(currentpix
, _("Retrieving"));
699 /* begin POP3 session */
700 inc_state
= inc_pop3_session_do(session
);
704 if (pop3_session
->cur_total_num
> 0)
705 msg
= g_strdup_printf(
706 ngettext("Done (%d message (%s) received)",
707 "Done (%d messages (%s) received)",
708 pop3_session
->cur_total_num
),
709 pop3_session
->cur_total_num
,
710 to_human_readable((goffset
)pop3_session
->cur_total_recv_bytes
));
712 msg
= g_strdup_printf(_("Done (no new messages)"));
713 SET_PIXMAP_AND_TEXT(okpix
, msg
);
716 case INC_CONNECT_ERROR
:
717 SET_PIXMAP_AND_TEXT(errorpix
, _("Connection failed"));
719 case INC_AUTH_FAILED
:
720 SET_PIXMAP_AND_TEXT(errorpix
, _("Auth failed"));
721 if (pop3_session
->ac_prefs
->session_passwd
) {
722 g_free(pop3_session
->ac_prefs
->session_passwd
);
723 pop3_session
->ac_prefs
->session_passwd
= NULL
;
727 SET_PIXMAP_AND_TEXT(errorpix
, _("Locked"));
732 case INC_SOCKET_ERROR
:
734 SET_PIXMAP_AND_TEXT(errorpix
, _("Error"));
737 SET_PIXMAP_AND_TEXT(errorpix
, _("Timeout"));
740 SET_PIXMAP_AND_TEXT(okpix
, _("Cancelled"));
741 if (!inc_dialog
->show_dialog
)
748 if (pop3_session
->error_val
== PS_AUTHFAIL
) {
749 if(!prefs_common
.no_recv_err_panel
) {
750 if((prefs_common
.recv_dialog_mode
== RECV_DIALOG_ALWAYS
) ||
751 ((prefs_common
.recv_dialog_mode
== RECV_DIALOG_MANUAL
) && focus_window
))
752 manage_window_focus_in(inc_dialog
->dialog
->window
, NULL
, NULL
);
756 /* CLAWS: perform filtering actions on dropped message */
757 /* CLAWS: get default inbox (perhaps per account) */
758 if (pop3_session
->ac_prefs
->inbox
) {
759 /* CLAWS: get destination folder / mailbox */
760 inbox
= folder_find_item_from_identifier(pop3_session
->ac_prefs
->inbox
);
762 inbox
= folder_get_default_inbox();
764 inbox
= folder_get_default_inbox();
766 /* get list of messages in processing */
767 processing
= folder_get_default_processing(pop3_session
->ac_prefs
->account_id
);
768 folder_item_scan(processing
);
769 msglist
= folder_item_get_msg_list(processing
);
771 /* process messages */
772 folder_item_update_freeze();
774 procmsg_msglist_filter(msglist
, pop3_session
->ac_prefs
,
775 &filtered
, &unfiltered
,
776 pop3_session
->ac_prefs
->filter_on_recv
);
778 filtering_move_and_copy_msgs(msglist
);
779 if (unfiltered
!= NULL
)
780 folder_item_move_msgs(inbox
, unfiltered
);
782 for(msglist_element
= msglist
; msglist_element
!= NULL
;
783 msglist_element
= msglist_element
->next
) {
784 procmsg_msginfo_free((MsgInfo
**)&(msglist_element
->data
));
786 folder_item_update_thaw();
788 g_slist_free(msglist
);
789 g_slist_free(filtered
);
790 g_slist_free(unfiltered
);
794 new_msgs
+= pop3_session
->cur_total_num
;
796 pop3_write_uidl_list(pop3_session
);
798 if (inc_state
!= INC_SUCCESS
&& inc_state
!= INC_CANCEL
) {
800 if (inc_dialog
->show_dialog
)
801 manage_window_focus_in
802 (inc_dialog
->dialog
->window
,
804 inc_put_error(inc_state
, pop3_session
);
805 if (inc_dialog
->show_dialog
)
806 manage_window_focus_out
807 (inc_dialog
->dialog
->window
,
809 if (inc_state
== INC_NO_SPACE
||
810 inc_state
== INC_IO_ERROR
)
813 folder_item_free_cache(processing
, TRUE
);
815 inc_session_destroy(session
);
816 inc_dialog
->queue_list
=
817 g_list_remove(inc_dialog
->queue_list
, session
);
820 #undef SET_PIXMAP_AND_TEXT
823 fin_msg
= g_strdup_printf(ngettext("Finished (%d new message)",
824 "Finished (%d new messages)",
825 new_msgs
), new_msgs
);
827 fin_msg
= g_strdup_printf(_("Finished (no new messages)"));
829 progress_dialog_set_label(inc_dialog
->dialog
, fin_msg
);
831 while (inc_dialog
->queue_list
!= NULL
) {
832 session
= inc_dialog
->queue_list
->data
;
833 inc_session_destroy(session
);
834 inc_dialog
->queue_list
=
835 g_list_remove(inc_dialog
->queue_list
, session
);
838 if (prefs_common
.close_recv_dialog
|| !inc_dialog
->show_dialog
)
839 inc_progress_dialog_destroy(inc_dialog
);
841 gtk_window_set_title(GTK_WINDOW(inc_dialog
->dialog
->window
),
843 gtk_button_set_label(GTK_BUTTON(inc_dialog
->dialog
->cancel_btn
),
845 gtk_button_set_image(GTK_BUTTON(inc_dialog
->dialog
->cancel_btn
),
846 gtk_image_new_from_icon_name("window-close", GTK_ICON_SIZE_BUTTON
));
854 static IncState
inc_pop3_session_do(IncSession
*session
)
856 Pop3Session
*pop3_session
= POP3_SESSION(session
->session
);
857 IncProgressDialog
*inc_dialog
= (IncProgressDialog
*)session
->data
;
858 PrefsAccount
*ac
= pop3_session
->ac_prefs
;
863 ProxyInfo
*proxy_info
= NULL
;
865 debug_print("getting new messages of account %s...\n",
868 ac
->last_pop_login_time
= time(NULL
);
870 buf
= g_strdup_printf(_("%s: Retrieving new messages"),
872 gtk_window_set_title(GTK_WINDOW(inc_dialog
->dialog
->window
), buf
);
875 server
= ac
->recv_server
;
876 account_name
= ac
->account_name
;
877 port
= pop3_get_port(pop3_session
);
880 SESSION(pop3_session
)->ssl_type
= ac
->ssl_pop
;
881 if (ac
->ssl_pop
!= SSL_NONE
)
882 SESSION(pop3_session
)->nonblocking
=
883 ac
->use_nonblocking_ssl
;
885 if (ac
->ssl_pop
!= SSL_NONE
) {
886 if (alertpanel_full(_("Insecure connection"),
887 _("This connection is configured to be secured "
888 "using TLS, but TLS is not available "
889 "in this build of Claws Mail. \n\n"
890 "Do you want to continue connecting to this "
891 "server? The communication would not be "
893 NULL
, _("_Cancel"), NULL
, _("Con_tinue connecting"), NULL
, NULL
,
894 ALERTFOCUS_FIRST
, FALSE
, NULL
, ALERT_WARNING
) != G_ALERTALTERNATE
)
899 buf
= g_strdup_printf(_("Account '%s': Connecting to POP3 server: %s:%d..."),
900 account_name
, server
, port
);
901 statusbar_print_all("%s", buf
);
902 log_message(LOG_PROTOCOL
, "%s\n", buf
);
904 progress_dialog_set_label(inc_dialog
->dialog
, buf
);
907 if (ac
->use_default_proxy
) {
908 proxy_info
= (ProxyInfo
*)&(prefs_common
.proxy_info
);
909 if (proxy_info
->use_proxy_auth
)
910 proxy_info
->proxy_pass
= passwd_store_get(PWS_CORE
, PWS_CORE_PROXY
,
911 PWS_CORE_PROXY_PASS
);
913 proxy_info
= (ProxyInfo
*)&(ac
->proxy_info
);
914 if (proxy_info
->use_proxy_auth
)
915 proxy_info
->proxy_pass
= passwd_store_get_account(ac
->account_id
,
916 PWS_ACCOUNT_PROXY_PASS
);
919 SESSION(pop3_session
)->proxy_info
= proxy_info
;
924 session_set_timeout(SESSION(pop3_session
),
925 prefs_common
.io_timeout_secs
* 1000);
927 if (session_connect(SESSION(pop3_session
), server
, port
) < 0) {
928 if(!prefs_common
.no_recv_err_panel
) {
929 if((prefs_common
.recv_dialog_mode
== RECV_DIALOG_ALWAYS
) ||
930 ((prefs_common
.recv_dialog_mode
== RECV_DIALOG_MANUAL
) && focus_window
)) {
931 manage_window_focus_in(inc_dialog
->dialog
->window
, NULL
, NULL
);
933 alertpanel_error(_("Can't connect to POP3 server: %s:%d"),
935 manage_window_focus_out(inc_dialog
->dialog
->window
, NULL
, NULL
);
937 log_error(LOG_PROTOCOL
, _("Can't connect to POP3 server: %s:%d\n"),
940 session
->inc_state
= INC_CONNECT_ERROR
;
942 return INC_CONNECT_ERROR
;
945 while (session_is_running(SESSION(pop3_session
)) &&
946 session
->inc_state
!= INC_CANCEL
)
947 gtk_main_iteration();
949 if (session
->inc_state
== INC_SUCCESS
) {
950 switch (pop3_session
->error_val
) {
952 switch (SESSION(pop3_session
)->state
) {
954 if (pop3_session
->state
== POP3_READY
)
955 session
->inc_state
= INC_CONNECT_ERROR
;
957 session
->inc_state
= INC_ERROR
;
960 session
->inc_state
= INC_EOF
;
962 case SESSION_TIMEOUT
:
963 session
->inc_state
= INC_TIMEOUT
;
966 session
->inc_state
= INC_SUCCESS
;
971 session
->inc_state
= INC_AUTH_FAILED
;
974 session
->inc_state
= INC_IO_ERROR
;
977 session
->inc_state
= INC_SOCKET_ERROR
;
980 session
->inc_state
= INC_LOCKED
;
983 session
->inc_state
= INC_ERROR
;
988 session_disconnect(SESSION(pop3_session
));
991 return session
->inc_state
;
994 static void inc_progress_dialog_update(IncProgressDialog
*inc_dialog
,
995 IncSession
*inc_session
)
997 inc_progress_dialog_set_label(inc_dialog
, inc_session
);
998 inc_progress_dialog_set_progress(inc_dialog
, inc_session
);
1001 static void inc_progress_dialog_set_label(IncProgressDialog
*inc_dialog
,
1002 IncSession
*inc_session
)
1004 ProgressDialog
*dialog
= inc_dialog
->dialog
;
1005 Pop3Session
*session
;
1007 cm_return_if_fail(inc_session
!= NULL
);
1009 session
= POP3_SESSION(inc_session
->session
);
1011 switch (session
->state
) {
1014 case POP3_GETAUTH_USER
:
1015 case POP3_GETAUTH_PASS
:
1016 case POP3_GETAUTH_APOP
:
1017 progress_dialog_set_label(dialog
, _("Authenticating..."));
1018 statusbar_pop_all();
1019 statusbar_print_all(_("Retrieving messages from %s (%s)..."),
1020 SESSION(session
)->server
,
1021 session
->ac_prefs
->account_name
);
1023 case POP3_GETRANGE_STAT
:
1024 progress_dialog_set_label
1025 (dialog
, _("Getting the number of new messages (STAT)..."));
1027 case POP3_GETRANGE_LAST
:
1028 progress_dialog_set_label
1029 (dialog
, _("Getting the number of new messages (LAST)..."));
1031 case POP3_GETRANGE_UIDL
:
1032 progress_dialog_set_label
1033 (dialog
, _("Getting the number of new messages (UIDL)..."));
1035 case POP3_GETSIZE_LIST
:
1036 progress_dialog_set_label
1037 (dialog
, _("Getting the size of messages (LIST)..."));
1040 case POP3_RETR_RECV
:
1044 progress_dialog_set_label(dialog
, _("Quitting"));
1051 static void inc_progress_dialog_set_progress(IncProgressDialog
*inc_dialog
,
1052 IncSession
*inc_session
)
1054 gchar buf
[MESSAGEBUFSIZE
];
1055 Pop3Session
*pop3_session
= POP3_SESSION(inc_session
->session
);
1056 gchar
*total_size_str
;
1060 if (!pop3_session
->new_msg_exist
) return;
1062 cur_total
= inc_session
->cur_total_bytes
;
1063 total
= pop3_session
->total_bytes
;
1064 if (pop3_session
->state
== POP3_RETR
||
1065 pop3_session
->state
== POP3_RETR_RECV
||
1066 pop3_session
->state
== POP3_DELETE
) {
1067 Xstrdup_a(total_size_str
, to_human_readable((goffset
)total
), return);
1068 g_snprintf(buf
, sizeof(buf
),
1069 _("Retrieving message (%d / %d) (%s / %s)"),
1070 pop3_session
->cur_msg
, pop3_session
->count
,
1071 to_human_readable((goffset
)cur_total
), total_size_str
);
1072 progress_dialog_set_label(inc_dialog
->dialog
, buf
);
1075 progress_dialog_set_fraction
1076 (inc_dialog
->dialog
, (total
== 0) ? 0: (gfloat
)cur_total
/ (gfloat
)total
);
1078 statusbar_progress_all(pop3_session
->cur_msg
, pop3_session
->count
, 1);
1080 if (pop3_session
->cur_total_num
> 0) {
1081 g_snprintf(buf
, sizeof(buf
),
1082 ngettext("Retrieving (%d message (%s) received)",
1083 "Retrieving (%d messages (%s) received)",
1084 pop3_session
->cur_total_num
),
1085 pop3_session
->cur_total_num
,
1087 ((goffset
)pop3_session
->cur_total_recv_bytes
));
1088 progress_dialog_list_set_status(inc_dialog
->dialog
,
1089 inc_dialog
->cur_row
,
1094 static void inc_progress_dialog_update_periodic(IncProgressDialog
*inc_dialog
,
1095 IncSession
*inc_session
)
1097 GDateTime
*tv_cur
= g_date_time_new_now_local();
1098 GTimeSpan tv_result
;
1100 tv_result
= g_date_time_difference(tv_cur
, inc_dialog
->progress_tv
);
1101 g_date_time_unref(tv_cur
);
1102 if (tv_result
< 0) {
1103 tv_result
+= G_USEC_PER_SEC
;
1106 if (tv_result
> PROGRESS_UPDATE_INTERVAL
) {
1107 inc_progress_dialog_update(inc_dialog
, inc_session
);
1108 tv_cur
= g_date_time_add(inc_dialog
->progress_tv
, tv_result
);
1109 g_date_time_unref(inc_dialog
->progress_tv
);
1110 inc_dialog
->progress_tv
= tv_cur
;
1114 static gint
inc_recv_data_progressive(Session
*session
, guint cur_len
,
1115 guint total_len
, gpointer data
)
1117 IncSession
*inc_session
= (IncSession
*)data
;
1118 Pop3Session
*pop3_session
= POP3_SESSION(session
);
1119 IncProgressDialog
*inc_dialog
;
1122 cm_return_val_if_fail(inc_session
!= NULL
, -1);
1124 if (pop3_session
->state
!= POP3_RETR
&&
1125 pop3_session
->state
!= POP3_RETR_RECV
&&
1126 pop3_session
->state
!= POP3_DELETE
&&
1127 pop3_session
->state
!= POP3_LOGOUT
) return 0;
1129 if (!pop3_session
->new_msg_exist
) return 0;
1131 cur_total
= pop3_session
->cur_total_bytes
+ cur_len
;
1132 if (cur_total
> pop3_session
->total_bytes
)
1133 cur_total
= pop3_session
->total_bytes
;
1134 inc_session
->cur_total_bytes
= cur_total
;
1136 inc_dialog
= (IncProgressDialog
*)inc_session
->data
;
1137 inc_progress_dialog_update_periodic(inc_dialog
, inc_session
);
1142 static gint
inc_recv_data_finished(Session
*session
, guint len
, gpointer data
)
1144 IncSession
*inc_session
= (IncSession
*)data
;
1145 IncProgressDialog
*inc_dialog
;
1147 cm_return_val_if_fail(inc_session
!= NULL
, -1);
1149 inc_dialog
= (IncProgressDialog
*)inc_session
->data
;
1151 inc_recv_data_progressive(session
, 0, 0, inc_session
);
1153 if (POP3_SESSION(session
)->state
== POP3_LOGOUT
) {
1154 inc_progress_dialog_update(inc_dialog
, inc_session
);
1160 static gint
inc_recv_message(Session
*session
, const gchar
*msg
, gpointer data
)
1162 IncSession
*inc_session
= (IncSession
*)data
;
1163 IncProgressDialog
*inc_dialog
;
1165 cm_return_val_if_fail(inc_session
!= NULL
, -1);
1167 inc_dialog
= (IncProgressDialog
*)inc_session
->data
;
1169 switch (POP3_SESSION(session
)->state
) {
1170 case POP3_GETAUTH_USER
:
1171 case POP3_GETAUTH_PASS
:
1172 case POP3_GETAUTH_APOP
:
1173 case POP3_GETRANGE_STAT
:
1174 case POP3_GETRANGE_LAST
:
1175 case POP3_GETRANGE_UIDL
:
1176 case POP3_GETSIZE_LIST
:
1177 inc_progress_dialog_update(inc_dialog
, inc_session
);
1180 inc_recv_data_progressive(session
, 0, 0, inc_session
);
1183 inc_progress_dialog_update(inc_dialog
, inc_session
);
1192 static gint
inc_drop_message(Pop3Session
*session
, const gchar
*file
)
1195 FolderItem
*dropfolder
;
1196 IncSession
*inc_session
= (IncSession
*)(SESSION(session
)->data
);
1199 cm_return_val_if_fail(inc_session
!= NULL
, -1);
1201 if (session
->ac_prefs
->inbox
) {
1202 inbox
= folder_find_item_from_identifier
1203 (session
->ac_prefs
->inbox
);
1205 inbox
= folder_get_default_inbox();
1207 inbox
= folder_get_default_inbox();
1213 /* CLAWS: claws uses a global .processing folder for the filtering. */
1214 dropfolder
= folder_get_default_processing(session
->ac_prefs
->account_id
);
1216 /* add msg file to drop folder */
1217 if ((msgnum
= folder_item_add_msg(
1218 dropfolder
, file
, NULL
, TRUE
)) < 0) {
1226 static void inc_put_error(IncState istate
, Pop3Session
*session
)
1228 gchar
*log_msg
= NULL
;
1229 gchar
*err_msg
= NULL
;
1230 gboolean fatal_error
= FALSE
;
1233 case INC_CONNECT_ERROR
:
1235 if (prefs_common
.no_recv_err_panel
)
1237 err_msg
= g_strdup_printf(_("Connection to %s:%d failed."),
1238 SESSION(session
)->server
,
1239 SESSION(session
)->port
);
1242 log_msg
= _("Error occurred while processing mail.");
1244 if (prefs_common
.no_recv_err_panel
)
1246 if (session
->error_msg
)
1247 err_msg
= g_strdup_printf
1248 (_("Error occurred while processing mail:\n%s"),
1249 session
->error_msg
);
1251 err_msg
= g_strdup(log_msg
);
1254 log_msg
= _("No disk space left.");
1255 err_msg
= g_strdup(log_msg
);
1259 log_msg
= _("Can't write file.");
1260 err_msg
= g_strdup(log_msg
);
1263 case INC_SOCKET_ERROR
:
1264 log_msg
= _("Socket error.");
1265 if (prefs_common
.no_recv_err_panel
)
1267 err_msg
= g_strdup_printf(_("Socket error on connection to %s:%d."),
1268 SESSION(session
)->server
,
1269 SESSION(session
)->port
);
1272 log_msg
= _("Connection closed by the remote host.");
1273 if (prefs_common
.no_recv_err_panel
)
1275 err_msg
= g_strdup_printf(_("Connection to %s:%d closed by the remote host."),
1276 SESSION(session
)->server
,
1277 SESSION(session
)->port
);
1280 log_msg
= _("Mailbox is locked.");
1281 if (prefs_common
.no_recv_err_panel
)
1283 if (session
->error_msg
)
1284 err_msg
= g_strdup_printf(_("Mailbox is locked:\n%s"),
1285 session
->error_msg
);
1287 err_msg
= g_strdup(log_msg
);
1289 case INC_AUTH_FAILED
:
1290 log_msg
= _("Authentication failed.");
1292 if (prefs_common
.no_recv_err_panel
)
1294 if (session
->error_msg
)
1295 err_msg
= g_strdup_printf
1296 (_("Authentication failed:\n%s"), session
->error_msg
);
1298 err_msg
= g_strdup(log_msg
);
1301 log_msg
= _("Session timed out. You may be able to "
1302 "recover by increasing the timeout value in "
1303 "Preferences/Other/Miscellaneous.");
1304 if (prefs_common
.no_recv_err_panel
)
1306 err_msg
= g_strdup_printf(_("Connection to %s:%d timed out."),
1307 SESSION(session
)->server
,
1308 SESSION(session
)->port
);
1316 log_error(LOG_PROTOCOL
, "%s\n", log_msg
);
1318 log_warning(LOG_PROTOCOL
, "%s\n", log_msg
);
1320 if (prefs_common
.no_recv_err_panel
&& fatal_error
)
1321 mainwindow_show_error();
1324 alertpanel_error_log("%s", err_msg
);
1329 static void inc_cancel(IncProgressDialog
*dialog
)
1331 IncSession
*session
;
1333 cm_return_if_fail(dialog
!= NULL
);
1335 if (dialog
->queue_list
== NULL
) {
1336 inc_progress_dialog_destroy(dialog
);
1340 session
= dialog
->queue_list
->data
;
1342 session
->inc_state
= INC_CANCEL
;
1344 log_message(LOG_PROTOCOL
, _("Incorporation cancelled\n"));
1347 gboolean
inc_is_active(void)
1349 return (inc_dialog_list
!= NULL
);
1352 void inc_cancel_all(void)
1356 for (cur
= inc_dialog_list
; cur
!= NULL
; cur
= cur
->next
)
1357 inc_cancel((IncProgressDialog
*)cur
->data
);
1360 static void inc_showlog_cb(GtkWidget
*widget
, gpointer data
)
1362 MainWindow
*mainwin
= mainwindow_get_mainwindow();
1364 log_window_show(mainwin
->logwin
);
1367 static void inc_cancel_cb(GtkWidget
*widget
, gpointer data
)
1369 inc_cancel((IncProgressDialog
*)data
);
1372 static gint
inc_dialog_delete_cb(GtkWidget
*widget
, GdkEventAny
*event
,
1375 IncProgressDialog
*dialog
= (IncProgressDialog
*)data
;
1377 if (dialog
->queue_list
== NULL
)
1378 inc_progress_dialog_destroy(dialog
);
1383 static gint
inc_spool_account(PrefsAccount
*account
)
1389 if (account
->local_inbox
) {
1390 inbox
= folder_find_item_from_identifier(account
->local_inbox
);
1392 inbox
= folder_get_default_inbox();
1394 inbox
= folder_get_default_inbox();
1396 if (account
->local_mbox
) {
1397 if (is_file_exist(account
->local_mbox
))
1398 mbox
= g_strdup(account
->local_mbox
);
1399 else if (is_dir_exist(account
->local_mbox
))
1400 mbox
= g_strconcat(account
->local_mbox
, G_DIR_SEPARATOR_S
,
1401 g_get_user_name(), NULL
);
1403 debug_print("%s: local mailbox not found.\n",
1404 account
->local_mbox
);
1408 debug_print("local mailbox not set in account info.\n");
1412 result
= get_spool(inbox
, mbox
, account
);
1415 statusbar_pop_all();
1420 static gint
get_spool(FolderItem
*dest
, const gchar
*mbox
, PrefsAccount
*account
)
1424 gchar tmp_mbox
[MAXPATHLEN
+ 1];
1426 cm_return_val_if_fail(dest
!= NULL
, -1);
1427 cm_return_val_if_fail(mbox
!= NULL
, -1);
1428 cm_return_val_if_fail(account
!= NULL
, -1);
1430 if (!is_file_exist(mbox
) || (size
= get_file_size(mbox
)) == 0) {
1431 debug_print("%s: no messages in local mailbox.\n", mbox
);
1433 } else if (size
< 0)
1436 if ((lockfd
= lock_mbox(mbox
, LOCK_FLOCK
)) < 0)
1439 g_snprintf(tmp_mbox
, sizeof(tmp_mbox
), "%s%ctmpmbox.%p",
1440 get_tmp_dir(), G_DIR_SEPARATOR
, mbox
);
1442 if (copy_mbox(lockfd
, tmp_mbox
) < 0) {
1443 unlock_mbox(mbox
, lockfd
, LOCK_FLOCK
);
1447 debug_print("Getting new messages from %s into %s...\n",
1450 msgs
= proc_mbox(dest
, tmp_mbox
, account
->filter_on_recv
, account
);
1452 claws_unlink(tmp_mbox
);
1453 if (msgs
>= 0) empty_mbox(mbox
);
1454 unlock_mbox(mbox
, lockfd
, LOCK_FLOCK
);
1459 void inc_lock_real(void)
1464 void inc_unlock_real(void)
1466 if (inc_lock_count
> 0)
1470 static guint autocheck_timer
= 0;
1471 static gpointer autocheck_data
= NULL
;
1473 static void inc_notify_cmd(gint new_msgs
, gboolean notify
)
1475 gchar
*buf
, *numpos
, *ret_str
;
1476 gssize by_read
= 0, by_written
= 0;
1478 if (!(new_msgs
&& notify
&& prefs_common
.newmail_notify_cmd
&&
1479 *prefs_common
.newmail_notify_cmd
))
1482 buf
= g_strdup(prefs_common
.newmail_notify_cmd
);
1483 if ((numpos
= strstr(buf
, "%d")) != NULL
) {
1487 buf2
= g_strdup_printf("%s%d%s", buf
, new_msgs
, numpos
+ 2);
1492 ret_str
= g_locale_from_utf8(buf
, strlen(buf
), &by_read
, &by_written
,
1501 debug_print("executing new mail notification command: %s\n", buf
);
1502 execute_command_line(buf
, TRUE
, NULL
);
1507 void inc_autocheck_timer_init(MainWindow
*mainwin
)
1509 autocheck_data
= mainwin
;
1510 inc_autocheck_timer_set();
1513 static void inc_autocheck_timer_set_interval(guint _interval
)
1515 guint interval
= _interval
;
1517 /* Convert the interval to seconds if needed. */
1518 if (_interval
% 1000 == 0)
1521 inc_autocheck_timer_remove();
1522 /* last test is to avoid re-enabling auto_check after modifying
1523 the common preferences */
1524 if (prefs_common
.autochk_newmail
&& autocheck_data
1525 && prefs_common
.work_offline
== FALSE
) {
1527 g_timeout_add_seconds(interval
, inc_autocheck_func
, autocheck_data
);
1528 debug_print("added global inc timer %d at %u seconds\n",
1529 autocheck_timer
, interval
);
1533 void inc_autocheck_timer_set(void)
1535 inc_autocheck_timer_set_interval(prefs_common
.autochk_itv
* 1000);
1538 void inc_autocheck_timer_remove(void)
1540 if (autocheck_timer
) {
1541 debug_print("removed global inc timer %d\n", autocheck_timer
);
1542 g_source_remove(autocheck_timer
);
1543 autocheck_timer
= 0;
1547 static gint
inc_autocheck_func(gpointer data
)
1549 MainWindow
*mainwin
= (MainWindow
*)data
;
1551 if (inc_lock_count
) {
1552 debug_print("global inc: autocheck is locked.\n");
1553 inc_autocheck_timer_set_interval(1000);
1557 inc_all_account_mail(mainwin
, TRUE
, FALSE
, prefs_common
.newmail_notify_auto
);
1558 inc_autocheck_timer_set();
1563 static gboolean
inc_account_autocheck_func(gpointer data
)
1565 PrefsAccount
*account
= (PrefsAccount
*)data
;
1568 cm_return_val_if_fail(account
!= NULL
, FALSE
);
1570 debug_print("account %d: inc_account_autocheck_func\n",
1571 account
->account_id
);
1573 list
= g_list_append(list
, account
);
1574 inc_account_list_mail(mainwindow_get_mainwindow(),
1575 list
, TRUE
, prefs_common
.newmail_notify_auto
);
1578 inc_account_autocheck_timer_set_interval(account
);
1583 void inc_account_autocheck_timer_remove(PrefsAccount
*account
)
1585 cm_return_if_fail(account
!= NULL
);
1587 if (account
->autocheck_timer
!= 0) {
1588 g_source_remove(account
->autocheck_timer
);
1589 debug_print("INC: account %d: removed inc timer %d\n", account
->account_id
,
1590 account
->autocheck_timer
);
1591 account
->autocheck_timer
= 0;
1595 void inc_account_autocheck_timer_set_interval(PrefsAccount
*account
)
1597 cm_return_if_fail(account
!= NULL
);
1599 inc_account_autocheck_timer_remove(account
);
1601 if (account
->autochk_use_default
1602 || !account
->autochk_use_custom
1603 || account
->autochk_itv
== 0)
1606 account
->autocheck_timer
= g_timeout_add_seconds(
1607 account
->autochk_itv
, inc_account_autocheck_func
, account
);
1608 debug_print("INC: account %d: added inc timer %d at %u seconds\n",
1609 account
->account_id
, account
->autocheck_timer
, account
->autochk_itv
);
1612 gboolean
inc_offline_should_override(gboolean force_ask
, const gchar
*msg
)
1614 gint length
= 10; /* seconds */
1615 gint answer
= G_ALERTDEFAULT
;
1617 #ifdef HAVE_NETWORKMANAGER_SUPPORT
1618 /* If no network connection is available, override is not possible */
1619 if(!networkmanager_is_online(NULL
))
1623 if (prefs_common
.autochk_newmail
)
1624 length
= prefs_common
.autochk_itv
; /* seconds */
1627 inc_offline_overridden_no
= (time_t)0;
1630 if (prefs_common
.work_offline
) {
1633 if (time(NULL
) - inc_offline_overridden_yes
< length
* 60) /* seconds */
1635 else if (time(NULL
) - inc_offline_overridden_no
< length
* 60) /* seconds */
1639 gchar
*unit
= _("seconds");
1641 /* show the offline override time (length) using the must appropriate unit:
1642 the biggest unit possible (hours, minutes, seconds), provided that there
1643 is not inferior unit involved: 1 hour, 150 minutes, 25 minutes, 90 minutes,
1644 30 seconds, 90 seconds. */
1645 if ((length
/ 3600) > 0) { /* hours? */
1646 if (((length
% 3600) % 60) == 0) { /* no seconds left? */
1647 if ((length
% 3600) > 0) { /* minutes left? */
1648 length
= length
/ 60;
1649 unit
= ngettext("minute", "minutes", length
);
1651 length
= length
/ 3600;
1652 unit
= ngettext("hour", "hours", length
);
1654 } /* else: seconds */
1656 if ((length
/ 60) > 0) { /* minutes left? */
1657 if ((length
% 60) == 0) {
1658 length
= length
/ 60;
1659 unit
= ngettext("minute", "minutes", length
);
1661 } /* else: seconds */
1663 tmp
= g_strdup_printf(
1664 _("%s%sYou're working offline. Override for %d %s?"),
1669 tmp
= g_strdup_printf(
1670 _("%s%sYou're working offline. Override?"),
1674 answer
= alertpanel(_("Offline warning"),
1676 NULL
, _("_No"), NULL
, _("_Yes"),
1677 NULL
, !force_ask
? _("On_ly once"):NULL
, ALERTFOCUS_SECOND
);
1679 if (answer
== G_ALERTALTERNATE
) {
1680 inc_offline_overridden_yes
= time(NULL
);
1682 } else if (answer
== G_ALERTDEFAULT
) {
1684 inc_offline_overridden_no
= time(NULL
);
1687 inc_reset_offline_override_timers();
1694 void inc_reset_offline_override_timers()
1696 debug_print("resetting offline override timers\n");
1697 inc_offline_overridden_yes
= (time_t)0;
1698 inc_offline_overridden_no
= (time_t)0;