⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mail.c

📁 系统任务管理器
💻 C
📖 第 1 页 / 共 2 页
字号:
/* GKrellM|  Copyright (C) 1999-2006 Bill Wilson||  Author:  Bill Wilson    billw@gkrellm.net|  Latest versions might be found at:  http://gkrellm.net||  This program is free software which I release under the GNU General Public|  License. You may redistribute and/or modify this program under the terms|  of that license as published by the Free Software Foundation; either|  version 2 of the License, or (at your option) any later version.||  This program is distributed in the hope that it will be useful,|  but WITHOUT ANY WARRANTY; without even the implied warranty of|  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the|  GNU General Public License for more details.  Version 2 is in the|  COPYRIGHT file in the top level directory of this distribution.| |  To get a copy of the GNU General Puplic License, write to the Free Software|  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA*/#include "gkrellmd.h"#include "gkrellmd-private.h"#if !defined(WIN32)#define MBOX_MBOX		0#define MBOX_MAILDIR	1#define MBOX_MH_DIR		2typedef struct	{	gchar		*path;	gchar		*homedir_path;	gint		mboxtype;	gboolean	(*check_func)();	gint		mail_count;	gint		new_mail_count;	gint		old_mail_count;	gint		prev_mail_count,				prev_new_mail_count;	time_t		last_mtime;	off_t		last_size;	gboolean	is_internal;	/* Internal mail message (ie: localmachine) */	gboolean	changed;	}	Mailbox;static GList	*mailbox_list;static gint		mail_check_timeout = 5;			/* Seconds */static gboolean	unseen_is_new = TRUE;			/* Accessed but unread */static gboolean	mail_need_serve;  /* Look at a From line to see if it is valid, lines look like:  |  From sending_address dayofweek month dayofmonth timeofday year  |  eg: From billw@gkrellm.net Fri Oct 22 13:52:49 2010  */static gintis_From_line(Mailbox *mbox, gchar *buf)	{	gchar	sender[512];	gint	dayofmonth = 0;	if (strncmp(buf, "From ", 5))		return FALSE;	/* In case sending address missing, look for a day of month	|  number in field 3 or 4 (0 based).	*/	sender[0] = '\0';	if (sscanf(buf, "%*s %*s %*s %d", &dayofmonth) != 1)		{		if (sscanf(buf, "%*s %511s %*s %*s %d", sender, &dayofmonth) != 2)			return FALSE;		}	if (dayofmonth < 1 || dayofmonth > 31)		return FALSE;	if (strcmp(sender, "MAILER-DAEMON") == 0)		mbox->is_internal = TRUE;	return TRUE;	}  /* Check if this is a Content-Type-line. If it contains a boundary  |  field, copy boundary string to buffer (including two leading and  |  trailing dashes marking the end of a multipart mail) and return  |  true. Otherwise, return false.  */static gintis_multipart_mail(gchar *buf, gchar *separator)	{	gchar *fieldstart;	gchar *sepstart;	gint  seplen;		if (strncmp(buf, "Content-Type: ", 14) != 0)		return FALSE;	if (strncmp(&buf[14], "multipart/", 10) != 0)		return FALSE;	fieldstart = &buf[14];	while (*fieldstart!=0)		{		while (*fieldstart!=0 && *fieldstart!=';')			fieldstart++;		if (*fieldstart==';') fieldstart++;		while (*fieldstart!=0 && *fieldstart==' ')			fieldstart++;		if (strncmp(fieldstart, "boundary=", 9) == 0)			{			sepstart = fieldstart + 9;			if (sepstart[0]=='"')				{				sepstart++;				seplen = 0;				while (sepstart[seplen]!='"' && sepstart[seplen]>=32)					seplen++;				}			else				{				seplen = 0;				while (sepstart[seplen]!=';' && sepstart[seplen]>32)					seplen++;				}			strcpy(separator,"--");			strncpy(&separator[2],sepstart,seplen);			strcpy(&separator[seplen+2],"--");			return TRUE;			}		}	return FALSE;	}static gbooleanmh_sequences_new_count(Mailbox *mbox)	{	FILE	*f;	gchar	buf[1024];	gchar	*path, *tok;	gint	n0, n1;	path = g_strconcat(mbox->path, G_DIR_SEPARATOR_S,				".mh_sequences", NULL);	f = fopen(path, "r");	g_free(path);	if (!f)		return FALSE;	while (fgets(buf, sizeof(buf), f))		{		/* Look for unseen sequence like "unseen: 4 7-9 23"		*/		if (strncmp(buf, "unseen:", 7))			continue;		tok = strtok(buf, " \t\n");		while ((tok = strtok(NULL, " \t\n")) != NULL)			{			if (sscanf(tok, "%d-%d", &n0, &n1) == 2)				mbox->new_mail_count += n1 - n0 + 1;			else				mbox->new_mail_count++;			}		break;		}	fclose(f);	return TRUE;	}  /* Sylpheed procmsg.h enums MSG_NEW as (1 << 0) and MSG_UNREAD as (1 << 1)  |  And procmsg_write_flags() in Sylpheeds procmsg.c writes a mail record as  |  a pair of ints with msgnum first followed by flags.  */#define SYLPHEED_MSG_NEW		1#define SYLPHEED_MSG_UNREAD		2#define SYLPHEED_MARK_VERSION	2static gbooleansylpheed_mark_new_count(Mailbox *mbox)	{	FILE	*f;	gchar	*path;	gint	msgnum, flags, ver, mark_files = 0;	path = g_strconcat(mbox->path, G_DIR_SEPARATOR_S,				".sylpheed_mark", NULL);	f = fopen(path, "rb");	g_free(path);	if (!f)		return FALSE;	if (   fread(&ver, sizeof(ver), 1, f) == 1		&& SYLPHEED_MARK_VERSION == ver	   )		{		while (   fread(&msgnum, sizeof(msgnum), 1, f) == 1			   && fread(&flags, sizeof(flags), 1, f) == 1			  )			{			if (   (flags & SYLPHEED_MSG_NEW)				|| ((flags & SYLPHEED_MSG_UNREAD) && unseen_is_new)			   )				mbox->new_mail_count += 1;			++mark_files;			}		if (mark_files < mbox->mail_count)			mbox->new_mail_count += mbox->mail_count - mark_files;		}	fclose(f);	return TRUE;	}  /* Check a mh directory for mail. The way that messages are marked as new  |  depends on the MUA being using.  Only .mh_sequences and .sylpheed_mark  |  are currently checked, otherwise all mail found is considered new mail.  */static gbooleancheck_mh_dir(Mailbox *mbox)	{	GDir	*dir;	gchar	*name;	mbox->mail_count = mbox->new_mail_count = 0;	if ((dir = g_dir_open(mbox->path, 0, NULL)) == NULL)		return FALSE;	while ((name = (gchar *) g_dir_read_name(dir)) != NULL)		{		/* Files starting with a digit are messages. */		if (isdigit(name[0]))			mbox->mail_count++;		}	g_dir_close(dir);	/* Some MH dir clients use .mh_sequences, others such as mutt or gnus	|  do not.  For mixed cases, it's a user option to ignore .mh_sequences.	|  Sylpheed uses .sylpheed_mark.	*/	if (   !mh_sequences_new_count(mbox)		&& !sylpheed_mark_new_count(mbox)	   )		mbox->new_mail_count = mbox->mail_count;	return TRUE;	}  /* A maildir has new, cur, and tmp subdirectories.  Any file in new  |  or cur that does not begin with a '.' is a mail message.  It is  |  suggested that messages begin with the output of time() (9 digits)  |  but while mutt and qmail use this standard, procmail does not.  |  maildir(5) says:  |      It is a good idea for readers to skip all filenames in  |      new and cur starting with a dot.  Other than this,  |      readers should not attempt to parse filenames.  |  So check_maildir() simply looks for files in new and cur.  |  But if unseen_is_new flag is set, look for ":2,*S" file suffix where  |  the 'S' indicates the mail is seen.  |  See http://cr.yp.to/proto/maildir.html  */static gbooleancheck_maildir(Mailbox *mbox)	{	gchar	path[256], *s;	gchar	*name;	GDir	*dir;	mbox->new_mail_count = 0;	snprintf(path, sizeof(path), "%s%cnew", mbox->path,				G_DIR_SEPARATOR);	if ((dir = g_dir_open(path, 0, NULL)) != NULL)		{		while ((name = (gchar *) g_dir_read_name(dir)) != NULL)			mbox->new_mail_count++;		g_dir_close(dir);		}	mbox->mail_count = mbox->new_mail_count;	snprintf(path, sizeof(path), "%s%ccur", mbox->path,				G_DIR_SEPARATOR);	if ((dir = g_dir_open(path, 0, NULL)) != NULL)		{		while ((name = (gchar *) g_dir_read_name(dir)) != NULL)			{			mbox->mail_count++;			if (   unseen_is_new				&& (   (s = strchr(name, ':')) == NULL					|| !strchr(s, 'S')				   )			   )				mbox->new_mail_count++;			}		g_dir_close(dir);		}	if (_GK.debug_level & DEBUG_MAIL)		g_print(_("mdir %s total=%d old=%d new=%d\n"), mbox->path,			mbox->mail_count, mbox->old_mail_count, mbox->new_mail_count);    return TRUE;	}  /* Count total mail and old mail in a mailbox.  Old mail can be read  |  with a Status: R0, or can be accessed and not read with Status: O  |  So, new mail will be the diff - note that unread mail is not  |  necessarily new mail.  According to stat() man page:  |  st_atime is changed by mknod(), utime(), read(), write(), truncate()  |  st_mtime is changed by mknod(), utime(), write()  |  But, new mail arriving (writing mailbox) sets st_mtime while reading  |  the mailbox (mail program reading) sets st_atime.  So the test  |  st_atime > st_mtime is testing if mbox has been read since last new mail.  |  Mail readers may restore st_mtime after writting status.  |  And Netscape mail does status with X-Mozilla-Status: xxxS  |    where S is bitwise or of status flags:  |    1: read  2: replied  4: marked  8: 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_SEEN = 1<<4.  */  /* test if buf is a status for standard mail, mozilla or evolution   */static gbooleanis_status(gchar *buf)	{	if (buf[0] != 'S' && buf[0] != 'X')		return FALSE;	if (   !strncmp(buf, "Status:", 7)  /* Standard mail clients */	    || !strncmp(buf, "X-Mozilla-Status:", 17) /* Netscape */	    || !strncmp(buf, "X-Evolution:", 12)      /* Mozilla */	   )	    return TRUE;	else	    return FALSE;	}static gbooleanstatus_is_old(gchar *buf)	{	gchar	c;	int tmp;	/* Standard mail clients

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -