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"
66 extern SessionStats session_stats
;
68 static GList
*inc_dialog_list
= NULL
;
70 static time_t inc_offline_overridden_yes
= 0;
71 static time_t inc_offline_overridden_no
= 0;
73 guint inc_lock_count
= 0;
75 static GdkPixbuf
*currentpix
;
76 static GdkPixbuf
*errorpix
;
77 static GdkPixbuf
*okpix
;
79 #define MESSAGEBUFSIZE 8192
81 static void inc_update_stats(gint new_msgs
);
82 static void inc_finished (MainWindow
*mainwin
,
83 gboolean new_messages
,
85 static gint
inc_account_mail_real (MainWindow
*mainwin
,
86 PrefsAccount
*account
);
88 static IncProgressDialog
*inc_progress_dialog_create
90 static void inc_progress_dialog_set_list(IncProgressDialog
*inc_dialog
);
91 static void inc_progress_dialog_destroy (IncProgressDialog
*inc_dialog
);
93 static IncSession
*inc_session_new (PrefsAccount
*account
);
94 static void inc_session_destroy (IncSession
*session
);
95 static gint
inc_start (IncProgressDialog
*inc_dialog
);
96 static IncState
inc_pop3_session_do (IncSession
*session
);
98 static void inc_progress_dialog_update (IncProgressDialog
*inc_dialog
,
99 IncSession
*inc_session
);
101 static void inc_progress_dialog_set_label
102 (IncProgressDialog
*inc_dialog
,
103 IncSession
*inc_session
);
104 static void inc_progress_dialog_set_progress
105 (IncProgressDialog
*inc_dialog
,
106 IncSession
*inc_session
);
108 static void inc_progress_dialog_update_periodic
109 (IncProgressDialog
*inc_dialog
,
110 IncSession
*inc_session
);
112 static gint
inc_recv_data_progressive (Session
*session
,
116 static gint
inc_recv_data_finished (Session
*session
,
119 static gint
inc_recv_message (Session
*session
,
122 static gint
inc_drop_message (Pop3Session
*session
,
125 static void inc_put_error (IncState istate
,
126 Pop3Session
*session
);
128 static void inc_showlog_cb (GtkWidget
*widget
,
130 static void inc_cancel_cb (GtkWidget
*widget
,
132 static gint
inc_dialog_delete_cb (GtkWidget
*widget
,
136 static gint
get_spool (FolderItem
*dest
,
138 PrefsAccount
*account
);
140 static gint
inc_spool_account(PrefsAccount
*account
);
141 static void inc_autocheck_timer_set_interval (guint interval
);
142 static gint
inc_autocheck_func (gpointer data
);
144 static void inc_notify_cmd (gint new_msgs
,
147 static void inc_update_stats(gint new_msgs
)
149 /* update session statistics */
150 session_stats
.received
+= new_msgs
;
155 * @mainwin: Main window.
156 * @new_messages: TRUE if some messages have been received.
158 * Update the folder view and the summary view after receiving
159 * messages. If @new_messages is FALSE, this function avoids unneeded
162 static void inc_finished(MainWindow
*mainwin
, gboolean new_messages
, gboolean autocheck
)
164 if (prefs_common
.scan_all_after_inc
)
165 folderview_check_new(NULL
);
167 if (!autocheck
&& new_messages
&& prefs_common
.open_inbox_on_inc
) {
168 FolderItem
*item
= NULL
;
170 if (cur_account
&& cur_account
->inbox
)
171 item
= folder_find_item_from_identifier(cur_account
->inbox
);
172 if (item
== NULL
&& cur_account
&& cur_account
->folder
)
173 item
= cur_account
->folder
->inbox
;
175 item
= folder_get_default_inbox();
177 folderview_unselect(mainwin
->folderview
);
178 folderview_select(mainwin
->folderview
, item
);
180 statusbar_progress_all(0,0,0);
183 void inc_mail(MainWindow
*mainwin
, gboolean notify
)
186 gint account_new_msgs
= 0;
188 if (inc_lock_count
) return;
190 if (prefs_common
.work_offline
&&
191 !inc_offline_should_override(TRUE
,
192 _("Claws Mail needs network access in order "
197 inc_autocheck_timer_remove();
198 main_window_lock(mainwin
);
200 if (prefs_common
.use_extinc
&& prefs_common
.extinc_cmd
) {
201 /* external incorporating program */
202 if (execute_command_line(prefs_common
.extinc_cmd
, FALSE
, NULL
) < 0) {
203 main_window_unlock(mainwin
);
204 inc_autocheck_timer_set();
209 account_new_msgs
= inc_account_mail_real(mainwin
, cur_account
);
210 if (account_new_msgs
> 0)
211 new_msgs
+= account_new_msgs
;
214 inc_update_stats(new_msgs
);
215 inc_finished(mainwin
, new_msgs
> 0, FALSE
);
216 main_window_unlock(mainwin
);
217 inc_notify_cmd(new_msgs
, notify
);
218 inc_autocheck_timer_set();
222 void inc_pop_before_smtp(PrefsAccount
*acc
)
224 IncProgressDialog
*inc_dialog
;
228 mainwin
= mainwindow_get_mainwindow();
230 session
= inc_session_new(acc
);
231 if (!session
) return;
232 POP3_SESSION(session
->session
)->pop_before_smtp
= TRUE
;
234 inc_dialog
= inc_progress_dialog_create(FALSE
);
235 inc_dialog
->queue_list
= g_list_append(inc_dialog
->queue_list
,
237 /* FIXME: assumes to attach to first main window */
238 inc_dialog
->mainwin
= mainwin
;
239 inc_progress_dialog_set_list(inc_dialog
);
242 toolbar_main_set_sensitive(mainwin
);
243 main_window_set_menu_sensitive(mainwin
);
246 inc_start(inc_dialog
);
249 static gint
inc_account_mail_real(MainWindow
*mainwin
, PrefsAccount
*account
)
251 IncProgressDialog
*inc_dialog
;
254 switch (account
->protocol
) {
258 * FIXME: it should return foldeview_check_new() value.
259 * TODO: do it when bug [19] is fixed (IMAP folder sets
260 * an incorrect new message count)
262 folderview_check_new(FOLDER(account
->folder
));
265 session
= inc_session_new(account
);
266 if (!session
) return 0;
268 inc_dialog
= inc_progress_dialog_create(FALSE
);
269 inc_dialog
->queue_list
= g_list_append(inc_dialog
->queue_list
,
271 inc_dialog
->mainwin
= mainwin
;
272 inc_progress_dialog_set_list(inc_dialog
);
275 toolbar_main_set_sensitive(mainwin
);
276 main_window_set_menu_sensitive(mainwin
);
279 return inc_start(inc_dialog
);
282 return inc_spool_account(account
);
290 gint
inc_account_mail(MainWindow
*mainwin
, PrefsAccount
*account
)
294 if (inc_lock_count
) return 0;
296 if (account
->receive_in_progress
) return 0;
298 if (prefs_common
.work_offline
&&
299 !inc_offline_should_override(TRUE
,
300 _("Claws Mail needs network access in order "
304 inc_autocheck_timer_remove();
305 main_window_lock(mainwin
);
307 new_msgs
= inc_account_mail_real(mainwin
, account
);
309 inc_update_stats(new_msgs
);
310 inc_finished(mainwin
, new_msgs
> 0, FALSE
);
311 main_window_unlock(mainwin
);
312 inc_autocheck_timer_set();
317 void inc_account_list_mail(MainWindow
*mainwin
, GList
*account_list
, gboolean autocheck
,
320 GList
*list
, *queue_list
= NULL
;
321 IncProgressDialog
*inc_dialog
;
322 gint new_msgs
= 0, num
;
324 if (prefs_common
.work_offline
&&
325 !inc_offline_should_override( (autocheck
== FALSE
),
326 _("Claws Mail needs network access in order "
330 if (inc_lock_count
) return;
332 main_window_lock(mainwin
);
335 inc_update_stats(new_msgs
);
336 inc_finished(mainwin
, new_msgs
> 0, autocheck
);
337 main_window_unlock(mainwin
);
338 inc_notify_cmd(new_msgs
, notify
);
342 if (prefs_common
.use_extinc
&& prefs_common
.extinc_cmd
) {
343 /* external incorporating program */
344 if (execute_command_line(prefs_common
.extinc_cmd
, FALSE
, NULL
) < 0) {
345 log_error(LOG_PROTOCOL
, _("%s failed\n"), prefs_common
.extinc_cmd
);
347 main_window_unlock(mainwin
);
352 /* Check all accounts in the list, one by one. */
353 for (list
= account_list
; list
!= NULL
; list
= list
->next
) {
354 PrefsAccount
*account
= list
->data
;
356 if (account
== NULL
) {
357 debug_print("INC: Huh? inc_account_list_mail() got a NULL account, this should not happen!\n");
361 debug_print("INC: checking account %d\n", account
->account_id
);
362 switch (account
->protocol
) {
364 if (!(account
->receive_in_progress
)) {
365 IncSession
*session
= inc_session_new(account
);
367 if (session
!= NULL
) {
368 debug_print("INC: adding POP3 account %d to inc queue\n",
369 account
->account_id
);
370 queue_list
= g_list_append(queue_list
, session
);
377 new_msgs
+= folderview_check_new(FOLDER(account
->folder
));
381 num
= inc_spool_account(account
);
387 /* Nothing to do here, it's a SMTP-only account. */
391 debug_print("INC: encountered account %d with unknown protocol %d, ignoring\n",
392 account
->account_id
, account
->protocol
);
400 inc_dialog
= inc_progress_dialog_create(autocheck
);
401 inc_dialog
->queue_list
= queue_list
;
402 inc_dialog
->mainwin
= mainwin
;
403 inc_progress_dialog_set_list(inc_dialog
);
405 toolbar_main_set_sensitive(mainwin
);
406 main_window_set_menu_sensitive(mainwin
);
407 new_msgs
+= inc_start(inc_dialog
);
410 inc_update_stats(new_msgs
);
411 inc_finished(mainwin
, new_msgs
> 0, autocheck
);
412 main_window_unlock(mainwin
);
413 inc_notify_cmd(new_msgs
, notify
);
416 void inc_all_account_mail(MainWindow
*mainwin
, gboolean autocheck
,
417 gboolean check_at_startup
, gboolean notify
)
419 GList
*list
, *list2
= NULL
;
420 gboolean condition
= FALSE
;
421 gboolean hide_dialog
= FALSE
;
423 debug_print("INC: inc_all_account_mail(), autocheck: %s\n",
424 autocheck
? "YES" : "NO");
426 /* Collect list of accounts which use the global autocheck interval. */
427 for (list
= account_get_list(); list
!= NULL
; list
= list
->next
) {
428 PrefsAccount
*account
= list
->data
;
430 /* Nothing to do for SMTP-only accounts. */
431 if (account
->protocol
== A_NONE
)
434 /* Set up condition which decides whether or not to check
435 * this account, based on whether we're doing global autocheck
436 * or a check at startup or a manual 'Get all' check. */
438 condition
= prefs_common_get_prefs()->autochk_newmail
439 && account
->autochk_use_default
;
440 else if (check_at_startup
|| (!check_at_startup
&& !autocheck
))
441 condition
= account
->recv_at_getall
;
444 debug_print("INC: will check account %d\n", account
->account_id
);
445 list2
= g_list_append(list2
, account
);
449 /* Do the check on the collected accounts. */
451 if (autocheck
|| check_at_startup
)
453 inc_account_list_mail(mainwin
, list2
, hide_dialog
, notify
);
458 static void inc_progress_dialog_size_allocate_cb(GtkWidget
*widget
,
459 GtkAllocation
*allocation
)
461 cm_return_if_fail(allocation
!= NULL
);
463 gtk_window_get_size(GTK_WINDOW(widget
),
464 &prefs_common
.receivewin_width
, &prefs_common
.receivewin_height
);
467 static IncProgressDialog
*inc_progress_dialog_create(gboolean autocheck
)
469 IncProgressDialog
*dialog
;
470 ProgressDialog
*progress
;
471 static GdkGeometry geometry
;
473 dialog
= g_new0(IncProgressDialog
, 1);
475 progress
= progress_dialog_create();
476 gtk_window_set_title(GTK_WINDOW(progress
->window
),
477 _("Retrieving new messages"));
478 g_signal_connect(G_OBJECT(progress
->showlog_btn
), "clicked",
479 G_CALLBACK(inc_showlog_cb
), dialog
);
480 g_signal_connect(G_OBJECT(progress
->cancel_btn
), "clicked",
481 G_CALLBACK(inc_cancel_cb
), dialog
);
482 g_signal_connect(G_OBJECT(progress
->window
), "delete_event",
483 G_CALLBACK(inc_dialog_delete_cb
), dialog
);
484 g_signal_connect(G_OBJECT(progress
->window
), "size_allocate",
485 G_CALLBACK(inc_progress_dialog_size_allocate_cb
), NULL
);
486 /* manage_window_set_transient(GTK_WINDOW(progress->window)); */
488 progress_dialog_get_fraction(progress
);
490 stock_pixbuf_gdk(STOCK_PIXMAP_COMPLETE
, &okpix
);
491 stock_pixbuf_gdk(STOCK_PIXMAP_CONTINUE
, ¤tpix
);
492 stock_pixbuf_gdk(STOCK_PIXMAP_ERROR
, &errorpix
);
494 if (!geometry
.min_height
) {
495 geometry
.min_width
= 460;
496 geometry
.min_height
= 250;
499 gtk_window_set_geometry_hints(GTK_WINDOW(progress
->window
), NULL
, &geometry
,
501 gtk_widget_set_size_request(progress
->window
, prefs_common
.receivewin_width
,
502 prefs_common
.receivewin_height
);
504 if (prefs_common
.recv_dialog_mode
== RECV_DIALOG_ALWAYS
||
505 (prefs_common
.recv_dialog_mode
== RECV_DIALOG_MANUAL
&&
507 dialog
->show_dialog
= TRUE
;
508 gtk_widget_show_now(progress
->window
);
511 dialog
->dialog
= progress
;
512 dialog
->progress_tv
= g_date_time_new_now_local();
513 dialog
->folder_tv
= g_date_time_new_now_local();
514 dialog
->queue_list
= NULL
;
517 inc_dialog_list
= g_list_append(inc_dialog_list
, dialog
);
522 static void inc_progress_dialog_set_list(IncProgressDialog
*inc_dialog
)
526 for (list
= inc_dialog
->queue_list
; list
!= NULL
; list
= list
->next
) {
527 IncSession
*session
= list
->data
;
528 Pop3Session
*pop3_session
= POP3_SESSION(session
->session
);
530 session
->data
= inc_dialog
;
532 progress_dialog_list_set(inc_dialog
->dialog
,
534 pop3_session
->ac_prefs
->account_name
,
539 static void inc_progress_dialog_clear(IncProgressDialog
*inc_dialog
)
541 progress_dialog_get_fraction(inc_dialog
->dialog
);
542 progress_dialog_set_label(inc_dialog
->dialog
, "");
543 if (inc_dialog
->mainwin
)
544 main_window_progress_off(inc_dialog
->mainwin
);
547 static void inc_progress_dialog_destroy(IncProgressDialog
*inc_dialog
)
549 cm_return_if_fail(inc_dialog
!= NULL
);
551 inc_dialog_list
= g_list_remove(inc_dialog_list
, inc_dialog
);
553 if (inc_dialog
->mainwin
)
554 main_window_progress_off(inc_dialog
->mainwin
);
555 progress_dialog_destroy(inc_dialog
->dialog
);
557 g_date_time_unref(inc_dialog
->progress_tv
);
558 g_date_time_unref(inc_dialog
->folder_tv
);
563 static IncSession
*inc_session_new(PrefsAccount
*account
)
567 cm_return_val_if_fail(account
!= NULL
, NULL
);
569 if (account
->protocol
!= A_POP3
)
571 if (!account
->recv_server
|| !account
->userid
)
574 session
= g_new0(IncSession
, 1);
576 session
->session
= pop3_session_new(account
);
577 session
->session
->data
= session
;
578 POP3_SESSION(session
->session
)->drop_message
= inc_drop_message
;
579 session_set_recv_message_notify(session
->session
,
580 inc_recv_message
, session
);
581 session_set_recv_data_progressive_notify(session
->session
,
582 inc_recv_data_progressive
,
584 session_set_recv_data_notify(session
->session
,
585 inc_recv_data_finished
, session
);
590 static void inc_session_destroy(IncSession
*session
)
592 cm_return_if_fail(session
!= NULL
);
594 session_destroy(session
->session
);
598 static gint
pop3_get_port(Pop3Session
*pop3_session
)
601 return pop3_session
->ac_prefs
->set_popport
?
602 pop3_session
->ac_prefs
->popport
:
603 pop3_session
->ac_prefs
->ssl_pop
== SSL_TUNNEL
? 995 : 110;
605 return pop3_session
->ac_prefs
->set_popport
?
606 pop3_session
->ac_prefs
->popport
: 110;
610 static gint
inc_start(IncProgressDialog
*inc_dialog
)
614 Pop3Session
*pop3_session
;
620 FolderItem
*processing
, *inbox
;
621 GSList
*msglist
, *msglist_element
;
622 gboolean cancelled
= FALSE
;
624 qlist
= inc_dialog
->queue_list
;
625 while (qlist
!= NULL
) {
626 GList
*next
= qlist
->next
;
628 session
= qlist
->data
;
629 pop3_session
= POP3_SESSION(session
->session
);
630 pop3_session
->user
= g_strdup(pop3_session
->ac_prefs
->userid
);
632 if (inc_dialog
->show_dialog
)
633 manage_window_focus_in
634 (inc_dialog
->dialog
->window
,
637 if(pop3_session
->ac_prefs
->use_pop_auth
&&
638 pop3_session
->ac_prefs
->pop_auth_type
== POPAUTH_OAUTH2
)
639 oauth2_check_passwds (pop3_session
->ac_prefs
);
641 if (password_get(pop3_session
->user
,
642 pop3_session
->ac_prefs
->recv_server
,
643 "pop3", pop3_get_port(pop3_session
),
644 &(pop3_session
->pass
))) {
646 } else if ((pop3_session
->pass
= passwd_store_get_account(
647 pop3_session
->ac_prefs
->account_id
, PWS_ACCOUNT_RECV
)) == NULL
) {
650 pass
= input_dialog_query_password_keep
651 (pop3_session
->ac_prefs
->recv_server
,
653 &(pop3_session
->ac_prefs
->session_passwd
));
656 pop3_session
->pass
= pass
;
660 if (inc_dialog
->show_dialog
)
661 manage_window_focus_out
662 (inc_dialog
->dialog
->window
,
668 #define SET_PIXMAP_AND_TEXT(pix, str) \
670 progress_dialog_list_set(inc_dialog->dialog, \
671 inc_dialog->cur_row, \
677 for (; inc_dialog
->queue_list
!= NULL
&& !cancelled
; inc_dialog
->cur_row
++) {
678 session
= inc_dialog
->queue_list
->data
;
679 pop3_session
= POP3_SESSION(session
->session
);
680 GSList
*filtered
, *unfiltered
;
682 if (pop3_session
->pass
== NULL
) {
683 SET_PIXMAP_AND_TEXT(okpix
, _("Cancelled"));
684 inc_dialog
->queue_list
=
685 g_list_remove(inc_dialog
->queue_list
, session
);
686 inc_session_destroy(session
);
690 inc_progress_dialog_clear(inc_dialog
);
691 progress_dialog_scroll_to_row(inc_dialog
->dialog
,
692 inc_dialog
->cur_row
);
694 SET_PIXMAP_AND_TEXT(currentpix
, _("Retrieving"));
696 /* begin POP3 session */
697 inc_state
= inc_pop3_session_do(session
);
701 if (pop3_session
->cur_total_num
> 0)
702 msg
= g_strdup_printf(
703 ngettext("Done (%d message (%s) received)",
704 "Done (%d messages (%s) received)",
705 pop3_session
->cur_total_num
),
706 pop3_session
->cur_total_num
,
707 to_human_readable((goffset
)pop3_session
->cur_total_recv_bytes
));
709 msg
= g_strdup_printf(_("Done (no new messages)"));
710 SET_PIXMAP_AND_TEXT(okpix
, msg
);
713 case INC_CONNECT_ERROR
:
714 SET_PIXMAP_AND_TEXT(errorpix
, _("Connection failed"));
716 case INC_AUTH_FAILED
:
717 SET_PIXMAP_AND_TEXT(errorpix
, _("Auth failed"));
718 if (pop3_session
->ac_prefs
->session_passwd
) {
719 g_free(pop3_session
->ac_prefs
->session_passwd
);
720 pop3_session
->ac_prefs
->session_passwd
= NULL
;
724 SET_PIXMAP_AND_TEXT(errorpix
, _("Locked"));
729 case INC_SOCKET_ERROR
:
731 SET_PIXMAP_AND_TEXT(errorpix
, _("Error"));
734 SET_PIXMAP_AND_TEXT(errorpix
, _("Timeout"));
737 SET_PIXMAP_AND_TEXT(okpix
, _("Cancelled"));
738 if (!inc_dialog
->show_dialog
)
745 if (pop3_session
->error_val
== PS_AUTHFAIL
) {
746 if(!prefs_common
.no_recv_err_panel
) {
747 if((prefs_common
.recv_dialog_mode
== RECV_DIALOG_ALWAYS
) ||
748 ((prefs_common
.recv_dialog_mode
== RECV_DIALOG_MANUAL
) && focus_window
))
749 manage_window_focus_in(inc_dialog
->dialog
->window
, NULL
, NULL
);
753 /* CLAWS: perform filtering actions on dropped message */
754 /* CLAWS: get default inbox (perhaps per account) */
755 if (pop3_session
->ac_prefs
->inbox
) {
756 /* CLAWS: get destination folder / mailbox */
757 inbox
= folder_find_item_from_identifier(pop3_session
->ac_prefs
->inbox
);
759 inbox
= folder_get_default_inbox();
761 inbox
= folder_get_default_inbox();
763 /* get list of messages in processing */
764 processing
= folder_get_default_processing(pop3_session
->ac_prefs
->account_id
);
765 folder_item_scan(processing
);
766 msglist
= folder_item_get_msg_list(processing
);
768 /* process messages */
769 folder_item_update_freeze();
771 procmsg_msglist_filter(msglist
, pop3_session
->ac_prefs
,
772 &filtered
, &unfiltered
,
773 pop3_session
->ac_prefs
->filter_on_recv
);
775 filtering_move_and_copy_msgs(msglist
);
776 if (unfiltered
!= NULL
)
777 folder_item_move_msgs(inbox
, unfiltered
);
779 for(msglist_element
= msglist
; msglist_element
!= NULL
;
780 msglist_element
= msglist_element
->next
) {
781 procmsg_msginfo_free((MsgInfo
**)&(msglist_element
->data
));
783 folder_item_update_thaw();
785 g_slist_free(msglist
);
786 g_slist_free(filtered
);
787 g_slist_free(unfiltered
);
791 new_msgs
+= pop3_session
->cur_total_num
;
793 pop3_write_uidl_list(pop3_session
);
795 if (inc_state
!= INC_SUCCESS
&& inc_state
!= INC_CANCEL
) {
797 if (inc_dialog
->show_dialog
)
798 manage_window_focus_in
799 (inc_dialog
->dialog
->window
,
801 inc_put_error(inc_state
, pop3_session
);
802 if (inc_dialog
->show_dialog
)
803 manage_window_focus_out
804 (inc_dialog
->dialog
->window
,
806 if (inc_state
== INC_NO_SPACE
||
807 inc_state
== INC_IO_ERROR
)
810 folder_item_free_cache(processing
, TRUE
);
812 inc_session_destroy(session
);
813 inc_dialog
->queue_list
=
814 g_list_remove(inc_dialog
->queue_list
, session
);
817 #undef SET_PIXMAP_AND_TEXT
820 fin_msg
= g_strdup_printf(ngettext("Finished (%d new message)",
821 "Finished (%d new messages)",
822 new_msgs
), new_msgs
);
824 fin_msg
= g_strdup_printf(_("Finished (no new messages)"));
826 progress_dialog_set_label(inc_dialog
->dialog
, fin_msg
);
828 while (inc_dialog
->queue_list
!= NULL
) {
829 session
= inc_dialog
->queue_list
->data
;
830 inc_session_destroy(session
);
831 inc_dialog
->queue_list
=
832 g_list_remove(inc_dialog
->queue_list
, session
);
835 if (prefs_common
.close_recv_dialog
|| !inc_dialog
->show_dialog
)
836 inc_progress_dialog_destroy(inc_dialog
);
838 gtk_window_set_title(GTK_WINDOW(inc_dialog
->dialog
->window
),
840 gtk_button_set_label(GTK_BUTTON(inc_dialog
->dialog
->cancel_btn
),
842 gtk_button_set_image(GTK_BUTTON(inc_dialog
->dialog
->cancel_btn
),
843 gtk_image_new_from_icon_name("window-close", GTK_ICON_SIZE_BUTTON
));
851 static IncState
inc_pop3_session_do(IncSession
*session
)
853 Pop3Session
*pop3_session
= POP3_SESSION(session
->session
);
854 IncProgressDialog
*inc_dialog
= (IncProgressDialog
*)session
->data
;
855 PrefsAccount
*ac
= pop3_session
->ac_prefs
;
860 ProxyInfo
*proxy_info
= NULL
;
862 debug_print("getting new messages of account %s...\n",
865 ac
->last_pop_login_time
= time(NULL
);
867 buf
= g_strdup_printf(_("%s: Retrieving new messages"),
869 gtk_window_set_title(GTK_WINDOW(inc_dialog
->dialog
->window
), buf
);
872 server
= ac
->recv_server
;
873 account_name
= ac
->account_name
;
874 port
= pop3_get_port(pop3_session
);
877 SESSION(pop3_session
)->ssl_type
= ac
->ssl_pop
;
878 if (ac
->ssl_pop
!= SSL_NONE
)
879 SESSION(pop3_session
)->nonblocking
=
880 ac
->use_nonblocking_ssl
;
882 if (ac
->ssl_pop
!= SSL_NONE
) {
883 if (alertpanel_full(_("Insecure connection"),
884 _("This connection is configured to be secured "
885 "using TLS, but TLS is not available "
886 "in this build of Claws Mail. \n\n"
887 "Do you want to continue connecting to this "
888 "server? The communication would not be "
890 NULL
, _("_Cancel"), NULL
, _("Con_tinue connecting"), NULL
, NULL
,
891 ALERTFOCUS_FIRST
, FALSE
, NULL
, ALERT_WARNING
) != G_ALERTALTERNATE
)
896 buf
= g_strdup_printf(_("Account '%s': Connecting to POP3 server: %s:%d..."),
897 account_name
, server
, port
);
898 statusbar_print_all("%s", buf
);
899 log_message(LOG_PROTOCOL
, "%s\n", buf
);
901 progress_dialog_set_label(inc_dialog
->dialog
, buf
);
904 if (ac
->use_default_proxy
) {
905 proxy_info
= (ProxyInfo
*)&(prefs_common
.proxy_info
);
906 if (proxy_info
->use_proxy_auth
)
907 proxy_info
->proxy_pass
= passwd_store_get(PWS_CORE
, PWS_CORE_PROXY
,
908 PWS_CORE_PROXY_PASS
);
910 proxy_info
= (ProxyInfo
*)&(ac
->proxy_info
);
911 if (proxy_info
->use_proxy_auth
)
912 proxy_info
->proxy_pass
= passwd_store_get_account(ac
->account_id
,
913 PWS_ACCOUNT_PROXY_PASS
);
916 SESSION(pop3_session
)->proxy_info
= proxy_info
;
921 session_set_timeout(SESSION(pop3_session
),
922 prefs_common
.io_timeout_secs
* 1000);
924 if (session_connect(SESSION(pop3_session
), server
, port
) < 0) {
925 if(!prefs_common
.no_recv_err_panel
) {
926 if((prefs_common
.recv_dialog_mode
== RECV_DIALOG_ALWAYS
) ||
927 ((prefs_common
.recv_dialog_mode
== RECV_DIALOG_MANUAL
) && focus_window
)) {
928 manage_window_focus_in(inc_dialog
->dialog
->window
, NULL
, NULL
);
930 alertpanel_error(_("Can't connect to POP3 server: %s:%d"),
932 manage_window_focus_out(inc_dialog
->dialog
->window
, NULL
, NULL
);
934 log_error(LOG_PROTOCOL
, _("Can't connect to POP3 server: %s:%d\n"),
937 session
->inc_state
= INC_CONNECT_ERROR
;
939 return INC_CONNECT_ERROR
;
942 while (session_is_running(SESSION(pop3_session
)) &&
943 session
->inc_state
!= INC_CANCEL
)
944 gtk_main_iteration();
946 if (session
->inc_state
== INC_SUCCESS
) {
947 switch (pop3_session
->error_val
) {
949 switch (SESSION(pop3_session
)->state
) {
951 if (pop3_session
->state
== POP3_READY
)
952 session
->inc_state
= INC_CONNECT_ERROR
;
954 session
->inc_state
= INC_ERROR
;
957 session
->inc_state
= INC_EOF
;
959 case SESSION_TIMEOUT
:
960 session
->inc_state
= INC_TIMEOUT
;
963 session
->inc_state
= INC_SUCCESS
;
968 session
->inc_state
= INC_AUTH_FAILED
;
971 session
->inc_state
= INC_IO_ERROR
;
974 session
->inc_state
= INC_SOCKET_ERROR
;
977 session
->inc_state
= INC_LOCKED
;
980 session
->inc_state
= INC_ERROR
;
985 session_disconnect(SESSION(pop3_session
));
988 return session
->inc_state
;
991 static void inc_progress_dialog_update(IncProgressDialog
*inc_dialog
,
992 IncSession
*inc_session
)
994 inc_progress_dialog_set_label(inc_dialog
, inc_session
);
995 inc_progress_dialog_set_progress(inc_dialog
, inc_session
);
998 static void inc_progress_dialog_set_label(IncProgressDialog
*inc_dialog
,
999 IncSession
*inc_session
)
1001 ProgressDialog
*dialog
= inc_dialog
->dialog
;
1002 Pop3Session
*session
;
1004 cm_return_if_fail(inc_session
!= NULL
);
1006 session
= POP3_SESSION(inc_session
->session
);
1008 switch (session
->state
) {
1011 case POP3_GETAUTH_USER
:
1012 case POP3_GETAUTH_PASS
:
1013 case POP3_GETAUTH_APOP
:
1014 progress_dialog_set_label(dialog
, _("Authenticating..."));
1015 statusbar_pop_all();
1016 statusbar_print_all(_("Retrieving messages from %s (%s)..."),
1017 SESSION(session
)->server
,
1018 session
->ac_prefs
->account_name
);
1020 case POP3_GETRANGE_STAT
:
1021 progress_dialog_set_label
1022 (dialog
, _("Getting the number of new messages (STAT)..."));
1024 case POP3_GETRANGE_LAST
:
1025 progress_dialog_set_label
1026 (dialog
, _("Getting the number of new messages (LAST)..."));
1028 case POP3_GETRANGE_UIDL
:
1029 progress_dialog_set_label
1030 (dialog
, _("Getting the number of new messages (UIDL)..."));
1032 case POP3_GETSIZE_LIST
:
1033 progress_dialog_set_label
1034 (dialog
, _("Getting the size of messages (LIST)..."));
1037 case POP3_RETR_RECV
:
1041 progress_dialog_set_label(dialog
, _("Quitting"));
1048 static void inc_progress_dialog_set_progress(IncProgressDialog
*inc_dialog
,
1049 IncSession
*inc_session
)
1051 gchar buf
[MESSAGEBUFSIZE
];
1052 Pop3Session
*pop3_session
= POP3_SESSION(inc_session
->session
);
1053 gchar
*total_size_str
;
1057 if (!pop3_session
->new_msg_exist
) return;
1059 cur_total
= inc_session
->cur_total_bytes
;
1060 total
= pop3_session
->total_bytes
;
1061 if (pop3_session
->state
== POP3_RETR
||
1062 pop3_session
->state
== POP3_RETR_RECV
||
1063 pop3_session
->state
== POP3_DELETE
) {
1064 Xstrdup_a(total_size_str
, to_human_readable((goffset
)total
), return);
1065 g_snprintf(buf
, sizeof(buf
),
1066 _("Retrieving message (%d / %d) (%s / %s)"),
1067 pop3_session
->cur_msg
, pop3_session
->count
,
1068 to_human_readable((goffset
)cur_total
), total_size_str
);
1069 progress_dialog_set_label(inc_dialog
->dialog
, buf
);
1072 progress_dialog_set_fraction
1073 (inc_dialog
->dialog
, (total
== 0) ? 0: (gfloat
)cur_total
/ (gfloat
)total
);
1075 statusbar_progress_all(pop3_session
->cur_msg
, pop3_session
->count
, 1);
1077 if (pop3_session
->cur_total_num
> 0) {
1078 g_snprintf(buf
, sizeof(buf
),
1079 ngettext("Retrieving (%d message (%s) received)",
1080 "Retrieving (%d messages (%s) received)",
1081 pop3_session
->cur_total_num
),
1082 pop3_session
->cur_total_num
,
1084 ((goffset
)pop3_session
->cur_total_recv_bytes
));
1085 progress_dialog_list_set_status(inc_dialog
->dialog
,
1086 inc_dialog
->cur_row
,
1091 static void inc_progress_dialog_update_periodic(IncProgressDialog
*inc_dialog
,
1092 IncSession
*inc_session
)
1094 GDateTime
*tv_cur
= g_date_time_new_now_local();
1095 GTimeSpan tv_result
;
1097 tv_result
= g_date_time_difference(tv_cur
, inc_dialog
->progress_tv
);
1098 g_date_time_unref(tv_cur
);
1099 if (tv_result
< 0) {
1100 tv_result
+= G_USEC_PER_SEC
;
1103 if (tv_result
> PROGRESS_UPDATE_INTERVAL
) {
1104 inc_progress_dialog_update(inc_dialog
, inc_session
);
1105 tv_cur
= g_date_time_add(inc_dialog
->progress_tv
, tv_result
);
1106 g_date_time_unref(inc_dialog
->progress_tv
);
1107 inc_dialog
->progress_tv
= tv_cur
;
1111 static gint
inc_recv_data_progressive(Session
*session
, guint cur_len
,
1112 guint total_len
, gpointer data
)
1114 IncSession
*inc_session
= (IncSession
*)data
;
1115 Pop3Session
*pop3_session
= POP3_SESSION(session
);
1116 IncProgressDialog
*inc_dialog
;
1119 cm_return_val_if_fail(inc_session
!= NULL
, -1);
1121 if (pop3_session
->state
!= POP3_RETR
&&
1122 pop3_session
->state
!= POP3_RETR_RECV
&&
1123 pop3_session
->state
!= POP3_DELETE
&&
1124 pop3_session
->state
!= POP3_LOGOUT
) return 0;
1126 if (!pop3_session
->new_msg_exist
) return 0;
1128 cur_total
= pop3_session
->cur_total_bytes
+ cur_len
;
1129 if (cur_total
> pop3_session
->total_bytes
)
1130 cur_total
= pop3_session
->total_bytes
;
1131 inc_session
->cur_total_bytes
= cur_total
;
1133 inc_dialog
= (IncProgressDialog
*)inc_session
->data
;
1134 inc_progress_dialog_update_periodic(inc_dialog
, inc_session
);
1139 static gint
inc_recv_data_finished(Session
*session
, guint len
, gpointer data
)
1141 IncSession
*inc_session
= (IncSession
*)data
;
1142 IncProgressDialog
*inc_dialog
;
1144 cm_return_val_if_fail(inc_session
!= NULL
, -1);
1146 inc_dialog
= (IncProgressDialog
*)inc_session
->data
;
1148 inc_recv_data_progressive(session
, 0, 0, inc_session
);
1150 if (POP3_SESSION(session
)->state
== POP3_LOGOUT
) {
1151 inc_progress_dialog_update(inc_dialog
, inc_session
);
1157 static gint
inc_recv_message(Session
*session
, const gchar
*msg
, gpointer data
)
1159 IncSession
*inc_session
= (IncSession
*)data
;
1160 IncProgressDialog
*inc_dialog
;
1162 cm_return_val_if_fail(inc_session
!= NULL
, -1);
1164 inc_dialog
= (IncProgressDialog
*)inc_session
->data
;
1166 switch (POP3_SESSION(session
)->state
) {
1167 case POP3_GETAUTH_USER
:
1168 case POP3_GETAUTH_PASS
:
1169 case POP3_GETAUTH_APOP
:
1170 case POP3_GETRANGE_STAT
:
1171 case POP3_GETRANGE_LAST
:
1172 case POP3_GETRANGE_UIDL
:
1173 case POP3_GETSIZE_LIST
:
1174 inc_progress_dialog_update(inc_dialog
, inc_session
);
1177 inc_recv_data_progressive(session
, 0, 0, inc_session
);
1180 inc_progress_dialog_update(inc_dialog
, inc_session
);
1189 static gint
inc_drop_message(Pop3Session
*session
, const gchar
*file
)
1192 FolderItem
*dropfolder
;
1193 IncSession
*inc_session
= (IncSession
*)(SESSION(session
)->data
);
1196 cm_return_val_if_fail(inc_session
!= NULL
, -1);
1198 if (session
->ac_prefs
->inbox
) {
1199 inbox
= folder_find_item_from_identifier
1200 (session
->ac_prefs
->inbox
);
1202 inbox
= folder_get_default_inbox();
1204 inbox
= folder_get_default_inbox();
1210 /* CLAWS: claws uses a global .processing folder for the filtering. */
1211 dropfolder
= folder_get_default_processing(session
->ac_prefs
->account_id
);
1213 /* add msg file to drop folder */
1214 if ((msgnum
= folder_item_add_msg(
1215 dropfolder
, file
, NULL
, TRUE
)) < 0) {
1223 static void inc_put_error(IncState istate
, Pop3Session
*session
)
1225 gchar
*log_msg
= NULL
;
1226 gchar
*err_msg
= NULL
;
1227 gboolean fatal_error
= FALSE
;
1230 case INC_CONNECT_ERROR
:
1232 if (prefs_common
.no_recv_err_panel
)
1234 err_msg
= g_strdup_printf(_("Connection to %s:%d failed."),
1235 SESSION(session
)->server
,
1236 SESSION(session
)->port
);
1239 log_msg
= _("Error occurred while processing mail.");
1241 if (prefs_common
.no_recv_err_panel
)
1243 if (session
->error_msg
)
1244 err_msg
= g_strdup_printf
1245 (_("Error occurred while processing mail:\n%s"),
1246 session
->error_msg
);
1248 err_msg
= g_strdup(log_msg
);
1251 log_msg
= _("No disk space left.");
1252 err_msg
= g_strdup(log_msg
);
1256 log_msg
= _("Can't write file.");
1257 err_msg
= g_strdup(log_msg
);
1260 case INC_SOCKET_ERROR
:
1261 log_msg
= _("Socket error.");
1262 if (prefs_common
.no_recv_err_panel
)
1264 err_msg
= g_strdup_printf(_("Socket error on connection to %s:%d."),
1265 SESSION(session
)->server
,
1266 SESSION(session
)->port
);
1269 log_msg
= _("Connection closed by the remote host.");
1270 if (prefs_common
.no_recv_err_panel
)
1272 err_msg
= g_strdup_printf(_("Connection to %s:%d closed by the remote host."),
1273 SESSION(session
)->server
,
1274 SESSION(session
)->port
);
1277 log_msg
= _("Mailbox is locked.");
1278 if (prefs_common
.no_recv_err_panel
)
1280 if (session
->error_msg
)
1281 err_msg
= g_strdup_printf(_("Mailbox is locked:\n%s"),
1282 session
->error_msg
);
1284 err_msg
= g_strdup(log_msg
);
1286 case INC_AUTH_FAILED
:
1287 log_msg
= _("Authentication failed.");
1289 if (prefs_common
.no_recv_err_panel
)
1291 if (session
->error_msg
)
1292 err_msg
= g_strdup_printf
1293 (_("Authentication failed:\n%s"), session
->error_msg
);
1295 err_msg
= g_strdup(log_msg
);
1298 log_msg
= _("Session timed out. You may be able to "
1299 "recover by increasing the timeout value in "
1300 "Preferences/Other/Miscellaneous.");
1301 if (prefs_common
.no_recv_err_panel
)
1303 err_msg
= g_strdup_printf(_("Connection to %s:%d timed out."),
1304 SESSION(session
)->server
,
1305 SESSION(session
)->port
);
1313 log_error(LOG_PROTOCOL
, "%s\n", log_msg
);
1315 log_warning(LOG_PROTOCOL
, "%s\n", log_msg
);
1317 if (prefs_common
.no_recv_err_panel
&& fatal_error
)
1318 mainwindow_show_error();
1321 alertpanel_error_log("%s", err_msg
);
1326 static void inc_cancel(IncProgressDialog
*dialog
)
1328 IncSession
*session
;
1330 cm_return_if_fail(dialog
!= NULL
);
1332 if (dialog
->queue_list
== NULL
) {
1333 inc_progress_dialog_destroy(dialog
);
1337 session
= dialog
->queue_list
->data
;
1339 session
->inc_state
= INC_CANCEL
;
1341 log_message(LOG_PROTOCOL
, _("Incorporation cancelled\n"));
1344 gboolean
inc_is_active(void)
1346 return (inc_dialog_list
!= NULL
);
1349 void inc_cancel_all(void)
1353 for (cur
= inc_dialog_list
; cur
!= NULL
; cur
= cur
->next
)
1354 inc_cancel((IncProgressDialog
*)cur
->data
);
1357 static void inc_showlog_cb(GtkWidget
*widget
, gpointer data
)
1359 MainWindow
*mainwin
= mainwindow_get_mainwindow();
1361 log_window_show(mainwin
->logwin
);
1364 static void inc_cancel_cb(GtkWidget
*widget
, gpointer data
)
1366 inc_cancel((IncProgressDialog
*)data
);
1369 static gint
inc_dialog_delete_cb(GtkWidget
*widget
, GdkEventAny
*event
,
1372 IncProgressDialog
*dialog
= (IncProgressDialog
*)data
;
1374 if (dialog
->queue_list
== NULL
)
1375 inc_progress_dialog_destroy(dialog
);
1380 static gint
inc_spool_account(PrefsAccount
*account
)
1386 if (account
->local_inbox
) {
1387 inbox
= folder_find_item_from_identifier(account
->local_inbox
);
1389 inbox
= folder_get_default_inbox();
1391 inbox
= folder_get_default_inbox();
1393 if (account
->local_mbox
) {
1394 if (is_file_exist(account
->local_mbox
))
1395 mbox
= g_strdup(account
->local_mbox
);
1396 else if (is_dir_exist(account
->local_mbox
))
1397 mbox
= g_strconcat(account
->local_mbox
, G_DIR_SEPARATOR_S
,
1398 g_get_user_name(), NULL
);
1400 debug_print("%s: local mailbox not found.\n",
1401 account
->local_mbox
);
1405 debug_print("local mailbox not set in account info.\n");
1409 result
= get_spool(inbox
, mbox
, account
);
1412 statusbar_pop_all();
1417 static gint
get_spool(FolderItem
*dest
, const gchar
*mbox
, PrefsAccount
*account
)
1421 gchar tmp_mbox
[MAXPATHLEN
+ 1];
1423 cm_return_val_if_fail(dest
!= NULL
, -1);
1424 cm_return_val_if_fail(mbox
!= NULL
, -1);
1425 cm_return_val_if_fail(account
!= NULL
, -1);
1427 if (!is_file_exist(mbox
) || (size
= get_file_size(mbox
)) == 0) {
1428 debug_print("%s: no messages in local mailbox.\n", mbox
);
1430 } else if (size
< 0)
1433 if ((lockfd
= lock_mbox(mbox
, LOCK_FLOCK
)) < 0)
1436 g_snprintf(tmp_mbox
, sizeof(tmp_mbox
), "%s%ctmpmbox.%p",
1437 get_tmp_dir(), G_DIR_SEPARATOR
, mbox
);
1439 if (copy_mbox(lockfd
, tmp_mbox
) < 0) {
1440 unlock_mbox(mbox
, lockfd
, LOCK_FLOCK
);
1444 debug_print("Getting new messages from %s into %s...\n",
1447 msgs
= proc_mbox(dest
, tmp_mbox
, account
->filter_on_recv
, account
);
1449 claws_unlink(tmp_mbox
);
1450 if (msgs
>= 0) empty_mbox(mbox
);
1451 unlock_mbox(mbox
, lockfd
, LOCK_FLOCK
);
1456 void inc_lock_real(void)
1461 void inc_unlock_real(void)
1463 if (inc_lock_count
> 0)
1467 static guint autocheck_timer
= 0;
1468 static gpointer autocheck_data
= NULL
;
1470 static void inc_notify_cmd(gint new_msgs
, gboolean notify
)
1472 gchar
*buf
, *numpos
, *ret_str
;
1473 gssize by_read
= 0, by_written
= 0;
1475 if (!(new_msgs
&& notify
&& prefs_common
.newmail_notify_cmd
&&
1476 *prefs_common
.newmail_notify_cmd
))
1479 buf
= g_strdup(prefs_common
.newmail_notify_cmd
);
1480 if ((numpos
= strstr(buf
, "%d")) != NULL
) {
1484 buf2
= g_strdup_printf("%s%d%s", buf
, new_msgs
, numpos
+ 2);
1489 ret_str
= g_locale_from_utf8(buf
, strlen(buf
), &by_read
, &by_written
,
1498 debug_print("executing new mail notification command: %s\n", buf
);
1499 execute_command_line(buf
, TRUE
, NULL
);
1504 void inc_autocheck_timer_init(MainWindow
*mainwin
)
1506 autocheck_data
= mainwin
;
1507 inc_autocheck_timer_set();
1510 static void inc_autocheck_timer_set_interval(guint _interval
)
1512 guint interval
= _interval
;
1514 /* Convert the interval to seconds if needed. */
1515 if (_interval
% 1000 == 0)
1518 inc_autocheck_timer_remove();
1519 /* last test is to avoid re-enabling auto_check after modifying
1520 the common preferences */
1521 if (prefs_common
.autochk_newmail
&& autocheck_data
1522 && prefs_common
.work_offline
== FALSE
) {
1524 g_timeout_add_seconds(interval
, inc_autocheck_func
, autocheck_data
);
1525 debug_print("added global inc timer %d at %u seconds\n",
1526 autocheck_timer
, interval
);
1530 void inc_autocheck_timer_set(void)
1532 inc_autocheck_timer_set_interval(prefs_common
.autochk_itv
* 1000);
1535 void inc_autocheck_timer_remove(void)
1537 if (autocheck_timer
) {
1538 debug_print("removed global inc timer %d\n", autocheck_timer
);
1539 g_source_remove(autocheck_timer
);
1540 autocheck_timer
= 0;
1544 static gint
inc_autocheck_func(gpointer data
)
1546 MainWindow
*mainwin
= (MainWindow
*)data
;
1548 if (inc_lock_count
) {
1549 debug_print("global inc: autocheck is locked.\n");
1550 inc_autocheck_timer_set_interval(1000);
1554 inc_all_account_mail(mainwin
, TRUE
, FALSE
, prefs_common
.newmail_notify_auto
);
1555 inc_autocheck_timer_set();
1560 static gboolean
inc_account_autocheck_func(gpointer data
)
1562 PrefsAccount
*account
= (PrefsAccount
*)data
;
1565 cm_return_val_if_fail(account
!= NULL
, FALSE
);
1567 debug_print("account %d: inc_account_autocheck_func\n",
1568 account
->account_id
);
1570 list
= g_list_append(list
, account
);
1571 inc_account_list_mail(mainwindow_get_mainwindow(),
1572 list
, TRUE
, prefs_common
.newmail_notify_auto
);
1575 inc_account_autocheck_timer_set_interval(account
);
1580 void inc_account_autocheck_timer_remove(PrefsAccount
*account
)
1582 cm_return_if_fail(account
!= NULL
);
1584 if (account
->autocheck_timer
!= 0) {
1585 g_source_remove(account
->autocheck_timer
);
1586 debug_print("INC: account %d: removed inc timer %d\n", account
->account_id
,
1587 account
->autocheck_timer
);
1588 account
->autocheck_timer
= 0;
1592 void inc_account_autocheck_timer_set_interval(PrefsAccount
*account
)
1594 cm_return_if_fail(account
!= NULL
);
1596 inc_account_autocheck_timer_remove(account
);
1598 if (account
->autochk_use_default
1599 || !account
->autochk_use_custom
1600 || account
->autochk_itv
== 0)
1603 account
->autocheck_timer
= g_timeout_add_seconds(
1604 account
->autochk_itv
, inc_account_autocheck_func
, account
);
1605 debug_print("INC: account %d: added inc timer %d at %u seconds\n",
1606 account
->account_id
, account
->autocheck_timer
, account
->autochk_itv
);
1609 gboolean
inc_offline_should_override(gboolean force_ask
, const gchar
*msg
)
1611 gint length
= 10; /* seconds */
1612 gint answer
= G_ALERTDEFAULT
;
1614 #ifdef HAVE_NETWORKMANAGER_SUPPORT
1615 /* If no network connection is available, override is not possible */
1616 if(!networkmanager_is_online(NULL
))
1620 if (prefs_common
.autochk_newmail
)
1621 length
= prefs_common
.autochk_itv
; /* seconds */
1624 inc_offline_overridden_no
= (time_t)0;
1627 if (prefs_common
.work_offline
) {
1630 if (time(NULL
) - inc_offline_overridden_yes
< length
* 60) /* seconds */
1632 else if (time(NULL
) - inc_offline_overridden_no
< length
* 60) /* seconds */
1636 gchar
*unit
= _("seconds");
1638 /* show the offline override time (length) using the must appropriate unit:
1639 the biggest unit possible (hours, minutes, seconds), provided that there
1640 is not inferior unit involved: 1 hour, 150 minutes, 25 minutes, 90 minutes,
1641 30 seconds, 90 seconds. */
1642 if ((length
/ 3600) > 0) { /* hours? */
1643 if (((length
% 3600) % 60) == 0) { /* no seconds left? */
1644 if ((length
% 3600) > 0) { /* minutes left? */
1645 length
= length
/ 60;
1646 unit
= ngettext("minute", "minutes", length
);
1648 length
= length
/ 3600;
1649 unit
= ngettext("hour", "hours", length
);
1651 } /* else: seconds */
1653 if ((length
/ 60) > 0) { /* minutes left? */
1654 if ((length
% 60) == 0) {
1655 length
= length
/ 60;
1656 unit
= ngettext("minute", "minutes", length
);
1658 } /* else: seconds */
1660 tmp
= g_strdup_printf(
1661 _("%s%sYou're working offline. Override for %d %s?"),
1666 tmp
= g_strdup_printf(
1667 _("%s%sYou're working offline. Override?"),
1671 answer
= alertpanel(_("Offline warning"),
1673 NULL
, _("_No"), NULL
, _("_Yes"),
1674 NULL
, !force_ask
? _("On_ly once"):NULL
, ALERTFOCUS_SECOND
);
1676 if (answer
== G_ALERTALTERNATE
) {
1677 inc_offline_overridden_yes
= time(NULL
);
1679 } else if (answer
== G_ALERTDEFAULT
) {
1681 inc_offline_overridden_no
= time(NULL
);
1684 inc_reset_offline_override_timers();
1691 void inc_reset_offline_override_timers()
1693 debug_print("resetting offline override timers\n");
1694 inc_offline_overridden_yes
= (time_t)0;
1695 inc_offline_overridden_no
= (time_t)0;