Revision 3211 src/inc.c
| inc.c (revision 3211) | ||
|---|---|---|
| 1 | 1 |
/* |
| 2 | 2 |
* Sylpheed -- a GTK+ based, lightweight, and fast e-mail client |
| 3 |
* Copyright (C) 1999-2012 Hiroyuki Yamamoto
|
|
| 3 |
* Copyright (C) 1999-2013 Hiroyuki Yamamoto
|
|
| 4 | 4 |
* |
| 5 | 5 |
* This program is free software; you can redistribute it and/or modify |
| 6 | 6 |
* it under the terms of the GNU General Public License as published by |
| ... | ... | |
| 58 | 58 |
#include "progressdialog.h" |
| 59 | 59 |
#include "alertpanel.h" |
| 60 | 60 |
#include "trayicon.h" |
| 61 |
#include "notificationwindow.h" |
|
| 61 | 62 |
#include "filter.h" |
| 62 | 63 |
#include "folder.h" |
| 63 | 64 |
#include "procheader.h" |
| ... | ... | |
| 70 | 71 |
gint new_messages; |
| 71 | 72 |
} IncAccountNewMsgCount; |
| 72 | 73 |
|
| 74 |
typedef struct _IncMsgSummary |
|
| 75 |
{
|
|
| 76 |
gchar *subject; |
|
| 77 |
gchar *from; |
|
| 78 |
} IncMsgSummary; |
|
| 73 | 79 |
|
| 80 |
struct _IncResult |
|
| 81 |
{
|
|
| 82 |
GSList *count_list; |
|
| 83 |
GSList *msg_summaries; |
|
| 84 |
}; |
|
| 85 |
|
|
| 86 |
|
|
| 74 | 87 |
static GList *inc_dialog_list = NULL; |
| 75 | 88 |
|
| 76 | 89 |
static gboolean inc_is_running = FALSE; |
| ... | ... | |
| 84 | 97 |
|
| 85 | 98 |
|
| 86 | 99 |
static void inc_finished (MainWindow *mainwin, |
| 87 |
GSList *msg_counts);
|
|
| 100 |
IncResult *result);
|
|
| 88 | 101 |
static GSList *inc_add_message_count (GSList *list, |
| 89 | 102 |
PrefsAccount *account, |
| 90 | 103 |
gint new_messages); |
| 104 |
static void inc_result_free (IncResult *result, |
|
| 105 |
gboolean free_self); |
|
| 91 | 106 |
|
| 92 | 107 |
static gint inc_remote_account_mail (MainWindow *mainwin, |
| 93 | 108 |
PrefsAccount *account); |
| 94 | 109 |
static gint inc_account_mail_real (MainWindow *mainwin, |
| 95 |
PrefsAccount *account); |
|
| 110 |
PrefsAccount *account, |
|
| 111 |
IncResult *result); |
|
| 96 | 112 |
|
| 97 | 113 |
static IncProgressDialog *inc_progress_dialog_create |
| 98 | 114 |
(gboolean autocheck); |
| ... | ... | |
| 101 | 117 |
|
| 102 | 118 |
static IncSession *inc_session_new (PrefsAccount *account); |
| 103 | 119 |
static void inc_session_destroy (IncSession *session); |
| 104 |
static gint inc_start (IncProgressDialog *inc_dialog, |
|
| 105 |
GSList **count_list); |
|
| 120 |
static gint inc_start (IncProgressDialog *inc_dialog); |
|
| 106 | 121 |
static IncState inc_pop3_session_do (IncSession *session); |
| 107 | 122 |
|
| 108 | 123 |
static void inc_progress_dialog_update (IncProgressDialog *inc_dialog, |
| ... | ... | |
| 161 | 176 |
/** |
| 162 | 177 |
* inc_finished: |
| 163 | 178 |
* @mainwin: Main window. |
| 164 |
* @msg_counts: GSList of Number of received messages for each account.
|
|
| 179 |
* @result: Information of incorporation result.
|
|
| 165 | 180 |
* @new_messages: Number of received messages. |
| 166 | 181 |
* |
| 167 | 182 |
* Update the folder view and the summary view after receiving |
| 168 | 183 |
* messages. If @new_messages is 0, this function avoids unneeded |
| 169 | 184 |
* updating. |
| 170 | 185 |
**/ |
| 171 |
static void inc_finished(MainWindow *mainwin, GSList *msg_counts)
|
|
| 186 |
static void inc_finished(MainWindow *mainwin, IncResult *result)
|
|
| 172 | 187 |
{
|
| 173 | 188 |
FolderItem *item; |
| 174 | 189 |
gint new_messages = 0; |
| ... | ... | |
| 176 | 191 |
IncAccountNewMsgCount *count; |
| 177 | 192 |
GSList *cur; |
| 178 | 193 |
|
| 179 |
for (cur = msg_counts; cur != NULL; cur = cur->next) {
|
|
| 180 |
count = cur->data; |
|
| 181 |
if (count->new_messages > 0) |
|
| 182 |
new_messages += count->new_messages; |
|
| 194 |
if (result) {
|
|
| 195 |
for (cur = result->count_list; cur != NULL; cur = cur->next) {
|
|
| 196 |
count = cur->data; |
|
| 197 |
if (count->new_messages > 0) |
|
| 198 |
new_messages += count->new_messages; |
|
| 199 |
} |
|
| 183 | 200 |
} |
| 184 | 201 |
|
| 185 | 202 |
debug_print("inc_finished: %d new message(s)\n", new_messages);
|
| ... | ... | |
| 190 | 207 |
} |
| 191 | 208 |
|
| 192 | 209 |
if (new_messages > 0 && !block_notify) {
|
| 210 |
gchar buf[1024]; |
|
| 193 | 211 |
GString *str; |
| 194 | 212 |
gint c = 0; |
| 195 | 213 |
|
| 196 | 214 |
str = g_string_new("");
|
| 197 | 215 |
g_string_printf(str, _("Sylpheed: %d new messages"),
|
| 198 | 216 |
new_messages); |
| 199 |
if (msg_counts) {
|
|
| 200 |
for (cur = msg_counts; cur != NULL; cur = cur->next) {
|
|
| 217 |
if (result) {
|
|
| 218 |
for (cur = result->count_list; cur != NULL; cur = cur->next) {
|
|
| 201 | 219 |
count = cur->data; |
| 202 | 220 |
if (count->new_messages > 0) {
|
| 203 | 221 |
if (c == 0) |
| ... | ... | |
| 214 | 232 |
debug_print("inc_finished: %s\n", str->str);
|
| 215 | 233 |
trayicon_set_tooltip(str->str); |
| 216 | 234 |
trayicon_set_notify(TRUE); |
| 235 |
|
|
| 236 |
g_snprintf(buf, sizeof(buf), _("Sylpheed: %d new messages"), new_messages);
|
|
| 237 |
g_string_truncate(str, 0); |
|
| 238 |
if (result) {
|
|
| 239 |
for (cur = result->msg_summaries; cur != NULL; cur = cur->next) {
|
|
| 240 |
IncMsgSummary *summary = cur->data; |
|
| 241 |
gchar *markup; |
|
| 242 |
|
|
| 243 |
if (str->len > 0) |
|
| 244 |
g_string_append_c(str, '\n'); |
|
| 245 |
markup = g_markup_printf_escaped("<b>%s</b> %s", summary->subject, summary->from);
|
|
| 246 |
g_string_append(str, markup); |
|
| 247 |
g_free(markup); |
|
| 248 |
} |
|
| 249 |
} |
|
| 250 |
|
|
| 251 |
notification_window_create(buf, str->str, 5); |
|
| 252 |
|
|
| 217 | 253 |
g_string_free(str, TRUE); |
| 218 | 254 |
} |
| 219 | 255 |
|
| ... | ... | |
| 271 | 307 |
return g_slist_append(list, count); |
| 272 | 308 |
} |
| 273 | 309 |
|
| 310 |
static void inc_result_free(IncResult *result, gboolean free_self) |
|
| 311 |
{
|
|
| 312 |
GSList *cur; |
|
| 313 |
|
|
| 314 |
slist_free_strings(result->count_list); |
|
| 315 |
g_slist_free(result->count_list); |
|
| 316 |
for (cur = result->msg_summaries; cur != NULL; cur = cur->next) {
|
|
| 317 |
IncMsgSummary *sum = cur->data; |
|
| 318 |
g_free(sum->subject); |
|
| 319 |
g_free(sum->from); |
|
| 320 |
g_free(sum); |
|
| 321 |
} |
|
| 322 |
g_slist_free(result->msg_summaries); |
|
| 323 |
|
|
| 324 |
if (free_self) |
|
| 325 |
g_free(result); |
|
| 326 |
} |
|
| 327 |
|
|
| 274 | 328 |
void inc_mail(MainWindow *mainwin) |
| 275 | 329 |
{
|
| 330 |
IncResult result = {NULL, NULL};
|
|
| 276 | 331 |
gint new_msgs = 0; |
| 277 |
GSList *list = NULL; |
|
| 278 | 332 |
|
| 279 | 333 |
if (inc_lock_count) return; |
| 280 | 334 |
if (inc_is_active()) return; |
| ... | ... | |
| 301 | 355 |
|
| 302 | 356 |
if (prefs_common.inc_local) {
|
| 303 | 357 |
new_msgs = inc_spool(); |
| 304 |
list = inc_add_message_count(list, NULL, new_msgs);
|
|
| 358 |
result.count_list = inc_add_message_count(result.count_list, NULL, new_msgs);
|
|
| 305 | 359 |
} |
| 306 | 360 |
} else {
|
| 307 | 361 |
if (prefs_common.inc_local) {
|
| 308 | 362 |
new_msgs = inc_spool(); |
| 309 | 363 |
if (new_msgs < 0) |
| 310 | 364 |
new_msgs = 0; |
| 311 |
list = inc_add_message_count(list, NULL, new_msgs);
|
|
| 365 |
result.count_list = inc_add_message_count(result.count_list, NULL, new_msgs);
|
|
| 312 | 366 |
} |
| 313 | 367 |
|
| 314 |
new_msgs = inc_account_mail_real(mainwin, cur_account); |
|
| 315 |
list = inc_add_message_count(list, cur_account, new_msgs); |
|
| 368 |
new_msgs = inc_account_mail_real(mainwin, cur_account, &result); |
|
| 316 | 369 |
} |
| 317 | 370 |
|
| 318 |
inc_finished(mainwin, list); |
|
| 319 |
slist_free_strings(list); |
|
| 320 |
g_slist_free(list); |
|
| 371 |
inc_finished(mainwin, &result); |
|
| 372 |
inc_result_free(&result, FALSE); |
|
| 321 | 373 |
|
| 322 | 374 |
inc_is_running = FALSE; |
| 323 | 375 |
|
| ... | ... | |
| 455 | 507 |
return new_msgs; |
| 456 | 508 |
} |
| 457 | 509 |
|
| 458 |
static gint inc_account_mail_real(MainWindow *mainwin, PrefsAccount *account) |
|
| 510 |
static gint inc_account_mail_real(MainWindow *mainwin, PrefsAccount *account, |
|
| 511 |
IncResult *result) |
|
| 459 | 512 |
{
|
| 460 | 513 |
IncProgressDialog *inc_dialog; |
| 461 | 514 |
IncSession *session; |
| ... | ... | |
| 471 | 524 |
inc_dialog = inc_progress_dialog_create(FALSE); |
| 472 | 525 |
inc_dialog->queue_list = g_list_append(inc_dialog->queue_list, session); |
| 473 | 526 |
inc_dialog->mainwin = mainwin; |
| 527 |
inc_dialog->result = result; |
|
| 474 | 528 |
inc_progress_dialog_set_list(inc_dialog); |
| 475 | 529 |
|
| 476 | 530 |
main_window_set_toolbar_sensitive(mainwin); |
| 477 | 531 |
main_window_set_menu_sensitive(mainwin); |
| 478 | 532 |
|
| 479 |
return inc_start(inc_dialog, NULL);
|
|
| 533 |
return inc_start(inc_dialog); |
|
| 480 | 534 |
} |
| 481 | 535 |
|
| 482 | 536 |
gint inc_account_mail(MainWindow *mainwin, PrefsAccount *account) |
| 483 | 537 |
{
|
| 538 |
IncResult result = {NULL, NULL};
|
|
| 484 | 539 |
gint new_msgs; |
| 485 |
GSList *list; |
|
| 486 | 540 |
|
| 487 | 541 |
if (inc_lock_count) return 0; |
| 488 | 542 |
if (inc_is_active()) return 0; |
| ... | ... | |
| 498 | 552 |
|
| 499 | 553 |
syl_plugin_signal_emit("inc-mail-start", account);
|
| 500 | 554 |
|
| 501 |
new_msgs = inc_account_mail_real(mainwin, account); |
|
| 555 |
new_msgs = inc_account_mail_real(mainwin, account, &result);
|
|
| 502 | 556 |
|
| 503 |
list = inc_add_message_count(NULL, account, new_msgs); |
|
| 504 |
inc_finished(mainwin, list); |
|
| 505 |
slist_free_strings(list); |
|
| 506 |
g_slist_free(list); |
|
| 557 |
inc_finished(mainwin, &result); |
|
| 558 |
inc_result_free(&result, FALSE); |
|
| 507 | 559 |
|
| 508 | 560 |
inc_is_running = FALSE; |
| 509 | 561 |
|
| ... | ... | |
| 517 | 569 |
{
|
| 518 | 570 |
GList *list, *queue_list = NULL; |
| 519 | 571 |
IncProgressDialog *inc_dialog; |
| 520 |
GSList *count_list = NULL;
|
|
| 572 |
IncResult result = {NULL, NULL};
|
|
| 521 | 573 |
gint new_msgs = 0; |
| 522 | 574 |
|
| 523 | 575 |
if (inc_lock_count) return; |
| ... | ... | |
| 538 | 590 |
new_msgs = inc_spool(); |
| 539 | 591 |
if (new_msgs < 0) |
| 540 | 592 |
new_msgs = 0; |
| 541 |
count_list = inc_add_message_count(count_list, NULL, new_msgs);
|
|
| 593 |
result.count_list = inc_add_message_count(result.count_list, NULL, new_msgs);
|
|
| 542 | 594 |
} |
| 543 | 595 |
|
| 544 | 596 |
/* check IMAP4 / News folders */ |
| ... | ... | |
| 547 | 599 |
if ((account->protocol == A_IMAP4 || |
| 548 | 600 |
account->protocol == A_NNTP) && account->recv_at_getall) {
|
| 549 | 601 |
new_msgs = inc_remote_account_mail(mainwin, account); |
| 550 |
count_list = inc_add_message_count(count_list, account, new_msgs);
|
|
| 602 |
result.count_list = inc_add_message_count(result.count_list, account, new_msgs);
|
|
| 551 | 603 |
} |
| 552 | 604 |
} |
| 553 | 605 |
|
| ... | ... | |
| 567 | 619 |
inc_dialog = inc_progress_dialog_create(autocheck); |
| 568 | 620 |
inc_dialog->queue_list = queue_list; |
| 569 | 621 |
inc_dialog->mainwin = mainwin; |
| 622 |
inc_dialog->result = &result; |
|
| 570 | 623 |
inc_progress_dialog_set_list(inc_dialog); |
| 571 | 624 |
|
| 572 | 625 |
main_window_set_toolbar_sensitive(mainwin); |
| 573 | 626 |
main_window_set_menu_sensitive(mainwin); |
| 574 | 627 |
|
| 575 |
inc_start(inc_dialog, &count_list);
|
|
| 628 |
inc_start(inc_dialog); |
|
| 576 | 629 |
} |
| 577 | 630 |
|
| 578 |
inc_finished(mainwin, count_list); |
|
| 579 |
slist_free_strings(count_list); |
|
| 580 |
g_slist_free(count_list); |
|
| 631 |
inc_finished(mainwin, &result); |
|
| 632 |
inc_result_free(&result, FALSE); |
|
| 581 | 633 |
|
| 582 | 634 |
inc_is_running = FALSE; |
| 583 | 635 |
|
| ... | ... | |
| 612 | 664 |
_("Authenticating with POP3"));
|
| 613 | 665 |
inc_dialog->queue_list = g_list_append(inc_dialog->queue_list, session); |
| 614 | 666 |
inc_dialog->mainwin = mainwin; |
| 667 |
inc_dialog->result = NULL; |
|
| 615 | 668 |
inc_progress_dialog_set_list(inc_dialog); |
| 616 | 669 |
inc_dialog->show_dialog = TRUE; |
| 617 | 670 |
|
| 618 | 671 |
main_window_set_toolbar_sensitive(mainwin); |
| 619 | 672 |
main_window_set_menu_sensitive(mainwin); |
| 620 | 673 |
|
| 621 |
inc_start(inc_dialog, NULL);
|
|
| 674 |
inc_start(inc_dialog); |
|
| 622 | 675 |
|
| 623 | 676 |
inc_is_running = FALSE; |
| 624 | 677 |
|
| ... | ... | |
| 776 | 829 |
folderview_update_item_foreach(table, TRUE); |
| 777 | 830 |
} |
| 778 | 831 |
|
| 779 |
static gint inc_start(IncProgressDialog *inc_dialog, GSList **count_list)
|
|
| 832 |
static gint inc_start(IncProgressDialog *inc_dialog) |
|
| 780 | 833 |
{
|
| 781 | 834 |
IncSession *session; |
| 782 | 835 |
GList *qlist; |
| ... | ... | |
| 903 | 956 |
break; |
| 904 | 957 |
} |
| 905 | 958 |
|
| 906 |
if (count_list)
|
|
| 907 |
*count_list = inc_add_message_count(*count_list, pop3_session->ac_prefs, session->new_msgs);
|
|
| 959 |
if (inc_dialog->result)
|
|
| 960 |
inc_dialog->result->count_list = inc_add_message_count(inc_dialog->result->count_list, pop3_session->ac_prefs, session->new_msgs);
|
|
| 908 | 961 |
new_msgs += session->new_msgs; |
| 909 | 962 |
|
| 910 | 963 |
if (!prefs_common.scan_all_after_inc) {
|
| ... | ... | |
| 1394 | 1447 |
return 0; |
| 1395 | 1448 |
} |
| 1396 | 1449 |
|
| 1450 |
/** |
|
| 1451 |
* inc_drop_message: |
|
| 1452 |
* @session: Current Pop3Session. |
|
| 1453 |
* @file: Received message file. |
|
| 1454 |
* |
|
| 1455 |
* Callback function to drop received message into local mailbox. |
|
| 1456 |
* |
|
| 1457 |
* Return value: DROP_OK if succeeded. DROP_ERROR if error occurred. |
|
| 1458 |
* DROP_DONT_RECEIVE if the message should be skipped. |
|
| 1459 |
* DROP_DELETE if the message should be deleted. |
|
| 1460 |
**/ |
|
| 1397 | 1461 |
static gint inc_drop_message(Pop3Session *session, const gchar *file) |
| 1398 | 1462 |
{
|
| 1399 | 1463 |
FolderItem *inbox; |
| ... | ... | |
| 1404 | 1468 |
gint val; |
| 1405 | 1469 |
gboolean is_junk = FALSE; |
| 1406 | 1470 |
gboolean is_counted = FALSE; |
| 1471 |
IncProgressDialog *inc_dialog; |
|
| 1407 | 1472 |
|
| 1408 | 1473 |
g_return_val_if_fail(inc_session != NULL, DROP_ERROR); |
| 1409 | 1474 |
|
| 1410 | 1475 |
gdk_threads_enter(); |
| 1411 | 1476 |
|
| 1477 |
inc_dialog = (IncProgressDialog *)inc_session->data; |
|
| 1478 |
|
|
| 1412 | 1479 |
if (session->ac_prefs->inbox) {
|
| 1413 | 1480 |
inbox = folder_find_item_from_identifier |
| 1414 | 1481 |
(session->ac_prefs->inbox); |
| ... | ... | |
| 1521 | 1588 |
else {
|
| 1522 | 1589 |
val = DROP_OK; |
| 1523 | 1590 |
if (!is_junk && is_counted && |
| 1524 |
fltinfo->actions[FLT_ACTION_MARK_READ] == FALSE) |
|
| 1591 |
fltinfo->actions[FLT_ACTION_MARK_READ] == FALSE) {
|
|
| 1525 | 1592 |
inc_session->new_msgs++; |
| 1593 |
|
|
| 1594 |
if (inc_dialog->result && msginfo->subject && g_slist_length(inc_dialog->result->msg_summaries) < 5) {
|
|
| 1595 |
IncMsgSummary *summary; |
|
| 1596 |
summary = g_new(IncMsgSummary, 1); |
|
| 1597 |
summary->subject = g_strdup(msginfo->subject); |
|
| 1598 |
summary->from = g_strdup(msginfo->fromname); |
|
| 1599 |
inc_dialog->result->msg_summaries = g_slist_append(inc_dialog->result->msg_summaries, summary); |
|
| 1600 |
} |
|
| 1601 |
} |
|
| 1526 | 1602 |
} |
| 1527 | 1603 |
|
| 1528 | 1604 |
procmsg_msginfo_free(msginfo); |
Also available in: Unified diff