📄 mail.c
字号:
*/ if ( !strncmp(buf, "Status:", 7) && (strchr(buf, 'R') || (!unseen_is_new && strchr(buf, 'O'))) ) return TRUE; /* Netscape */ if (!strncmp(buf, "X-Mozilla-Status:", 17)) { c = buf[21]; if (c < '8') /* Not deleted */ c -= '0'; if (c >= '8' || (c & 0x1)) return TRUE; } /* Evolution */ if (!strncmp(buf, "X-Evolution:", 12)) { sscanf(buf+22, "%04x", &tmp); if (tmp & (1<<4)) return TRUE; } return FALSE; } /* test if a mail is marked as deleted | Evolution uses status with X-Evolution: 00000000-xxxx where xxxx status is | a bitfield in hexadecimal (see enum _CamelMessageFlags in evolution/camel source) | and most importantly CAMEL_MESSAGE_DELETED = 1<<1. */static gbooleanstatus_is_deleted(gchar *buf) { gint tmp; /* Standard mail clients if ( !strncmp(buf, "Status:", 7) ) */ /* Netscape if (!strncmp(buf, "X-Mozilla-Status:", 17)) */ /* Evolution */ if (!strncmp(buf, "X-Evolution:", 12)) { sscanf(buf+22, "%04x", &tmp); if (tmp & (1<<1)) return TRUE; /* Junk is not explicitly marked as deleted but is shown as if | where in evolution */ if (tmp & (1<<7)) return TRUE; } return FALSE; }static gbooleancheck_mbox(Mailbox *mbox) { FILE *f; struct utimbuf ut; struct stat s; gchar buf[1024]; gchar mpart_sep[1024]; gint in_header = FALSE; gint marked_read = FALSE; gint is_multipart = FALSE; if (stat(mbox->path, &s) != 0) { mbox->mail_count = mbox->old_mail_count = mbox->new_mail_count = 0; mbox->last_mtime = 0; mbox->last_size = 0; if (_GK.debug_level & DEBUG_MAIL) printf("check_mbox can't stat(%s): %s\n", mbox->path, g_strerror(errno)); return FALSE; } /* If the mailboxes have been modified since last check, count | the new/total messages. */ if ( s.st_mtime != mbox->last_mtime || s.st_size != mbox->last_size ) { if ((f = fopen(mbox->path, "r")) == NULL) { if (_GK.debug_level & DEBUG_MAIL) printf("check_mbox can't fopen(%s): %s\n", mbox->path, g_strerror(errno)); return FALSE; } mbox->mail_count = 0; mbox->old_mail_count = 0; while(fgets(buf, sizeof(buf), f)) { if (is_multipart && !in_header) { /* Skip to last line of multipart mail */ if (strncmp(buf,mpart_sep,strlen(mpart_sep))==0) is_multipart = FALSE; } else if (buf[0] == '\n') { in_header = FALSE; mbox->is_internal = FALSE; } else if (is_From_line(mbox, buf)) { mbox->mail_count += 1; in_header = TRUE; marked_read = FALSE; } else if (in_header && is_status(buf)) { if (status_is_old(buf) && !marked_read) { mbox->old_mail_count += 1; marked_read = TRUE; } if (status_is_deleted(buf)) { if (marked_read) mbox->old_mail_count -= 1; mbox->mail_count -= 1; } } else if (in_header && mbox->is_internal) { if (strncmp(buf, "From: Mail System Internal Data", 31) == 0) { in_header = FALSE; mbox->mail_count -= 1; mbox->is_internal = FALSE; } } else if (in_header && is_multipart_mail(buf,mpart_sep)) { is_multipart = TRUE; } } fclose(f); /* Restore the mbox stat times for other mail checking programs and | so the (st_atime > st_mtime) animation override below will work. */ ut.actime = s.st_atime; ut.modtime = s.st_mtime; utime(mbox->path, &ut); mbox->last_mtime = s.st_mtime; mbox->last_size = s.st_size; if (_GK.debug_level & DEBUG_MAIL) g_print("mbox read <%s> total=%d old=%d\n", mbox->path, mbox->mail_count, mbox->old_mail_count); } /* If mbox has been accessed since last modify a MUA has probably read | the mbox. */ mbox->new_mail_count = mbox->mail_count - mbox->old_mail_count; if (s.st_atime > s.st_mtime) { mbox->prev_new_mail_count = mbox->new_mail_count; } return TRUE; }static voidupdate_mail(GkrellmdMonitor *mon, gboolean force) { Mailbox *mbox; GList *list; static gint second_count; if ( (!GK.second_tick || (++second_count % mail_check_timeout) != 0) && !force ) return; for (list = mailbox_list; list; list = list->next) { mbox = (Mailbox *) list->data; if (mbox->check_func) (*mbox->check_func)(mbox); if ( mbox->prev_mail_count != mbox->mail_count || mbox->prev_new_mail_count != mbox->new_mail_count ) { mbox->changed = TRUE; mail_need_serve = TRUE; gkrellmd_need_serve(mon); } mbox->prev_mail_count = mbox->mail_count; mbox->prev_new_mail_count = mbox->new_mail_count; } }static voidget_local_mboxtype(Mailbox *mbox) { gchar *path; if (*(mbox->path) == '~') { mbox->homedir_path = mbox->path; mbox->path = g_strdup_printf("%s%s", g_get_home_dir(), mbox->homedir_path + 1); } if (g_file_test(mbox->path, G_FILE_TEST_IS_DIR)) {#if GLIB_CHECK_VERSION(2,0,0) path = g_build_path(G_DIR_SEPARATOR_S, mbox->path, "new", NULL);#else path = g_strconcat(mbox->path, G_DIR_SEPARATOR_S, "new", NULL);#endif if (g_file_test(path, G_FILE_TEST_IS_DIR)) mbox->mboxtype = MBOX_MAILDIR; else mbox->mboxtype = MBOX_MH_DIR; g_free(path); } else mbox->mboxtype = MBOX_MBOX; }voidgkrellmd_add_mailbox(gchar *path) { Mailbox *mbox; if (!path || !*path) return; mbox = g_new0(Mailbox, 1); mbox->path = g_strdup(path); get_local_mboxtype(mbox); if (mbox->mboxtype == MBOX_MAILDIR) mbox->check_func = check_maildir; else if (mbox->mboxtype == MBOX_MH_DIR) mbox->check_func = check_mh_dir; else mbox->check_func = check_mbox; mailbox_list = g_list_append(mailbox_list, mbox); gkrellmd_add_serveflag_done(&mbox->changed); }/* ============================================================= */static voidserve_mail_data(GkrellmdMonitor *mon, gboolean first_serve) { Mailbox *mbox; GList *list; gchar *line; if ((!mail_need_serve && !first_serve) || !mailbox_list) return; gkrellmd_set_serve_name(mon, "mail"); for (list = mailbox_list; list; list = list->next) { mbox = (Mailbox *) list->data; if (mbox->changed || first_serve) { line = g_strdup_printf("%s %d %d\n", mbox->homedir_path ? mbox->homedir_path : mbox->path, mbox->mail_count, mbox->new_mail_count); gkrellmd_serve_data(mon, line); g_free(line); } } }static voidserve_mail_setup(GkrellmdMonitor *mon) { GkrellmdClient *client = mon->privat->client; GList *list; Mailbox *mbox; gchar *line; gkrellmd_send_to_client(client, "<mail_setup>\n"); for (list = mailbox_list; list; list = list->next) { mbox = (Mailbox *) list->data; line = g_strdup_printf("%s\n", mbox->homedir_path ? mbox->homedir_path : mbox->path); gkrellmd_send_to_client(client, line); g_free(line); } }static GkrellmdMonitor mail_monitor = { "mail", update_mail, serve_mail_data, serve_mail_setup };GkrellmdMonitor *gkrellmd_init_mail_monitor(void) { gkrellmd_add_serveflag_done(&mail_need_serve); return &mail_monitor; }#else /* defined(WIN32) */GkrellmdMonitor *gkrellmd_init_mail_monitor(void) { return NULL; }#endifvoidgkrellm_mail_local_unsupported(void) { /* WIN32 only calls this and it is taken care of by above #if */ }#if GLIB_CHECK_VERSION(2,0,0)GThread *#elsegpointer#endifgkrellm_mail_get_active_thread(void) { return NULL; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -