1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-23 19:39:06 +00:00

Multiple mailbox patch (thanks Ben Kibbey)

git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@969 7f574dfc-610e-0410-a909-a81674777703
This commit is contained in:
Brenden Matthews 2007-10-02 23:57:41 +00:00
parent da182541fb
commit 58c1eb36c3
9 changed files with 111 additions and 48 deletions

View File

@ -21,6 +21,7 @@ akash <akash at users dot sourceforge dot net>
Ben Kibbey <benkibbey at users dot sourceforge dot net>
$tail fifo patch
multiple mailbox patch
Blondak <blondak_nesercz at users dot sourceforge dot net>
diskio read & write patch

View File

@ -1,5 +1,8 @@
# $Id$
2007-10-02
* Multiple mailbox patch (thanks Ben Kibbey)
2007-09-28
* Small fix for $ibm_volume (thanks Kapil Hari Paranjape)
* Patch so $tail can read from a fifo file descriptor (thanks Ben Kibbey)

17
README
View File

@ -928,15 +928,17 @@ VARIABLES
Machine, i686 for example
mails Mail count in mail spool. You can use program like fetchmail to
get mails from some server using your favourite protocol. See
also new_mails.
mails (mailbox) (interval)
Mail count in the specified mailbox or your mail spool if not.
Both mbox and maildir type mailboxes are supported. You can use
a program like fetchmail to get mails from some server using
your favourite protocol. See also new_mails.
mboxscan (-n number of messages to print) (-fw from width) (-sw subject
width) mbox
Print a summary of recent messages in an mbox format mailbox.
mbox parameter is the filename of the mailbox (can be encapsu-
Print a summary of recent messages in an mbox format mailbox.
mbox parameter is the filename of the mailbox (can be encapsu-
lated using '"', ie. ${mboxscan -n 10 "/home/brenden/some box"}
@ -1019,8 +1021,9 @@ VARIABLES
name, depending on whats available
new_mails
Unread mail count in mail spool.
new_mails (mailbox) (interval)
Unread mail count in the specified mailbox or mail spool if not.
Both mbox and maildir type mailboxes are supported.
nodename

View File

@ -849,8 +849,11 @@ Kernel version
Machine, i686 for example
.TP
\fB\*(T<\fBmails\fR\*(T>\fR
Mail count in mail spool. You can use program like fetchmail to get mails from some server using your favourite protocol. See also new_mails.
\fB\*(T<\fBmails\fR\*(T>\fR \*(T<\fB(mailbox)\fR\*(T> \*(T<\fB(interval)\fR\*(T>
Mail count in the specified mailbox or your mail spool if not.
Both mbox and maildir type mailboxes are supported. You can
use a program like fetchmail to get mails from some server
using your favourite protocol. See also new_mails.
.TP
\fB\*(T<\fBmboxscan\fR\*(T>\fR \*(T<\fB(\-n number of messages to print) (\-fw from width) (\-sw subject width) mbox\fR\*(T>
@ -937,8 +940,9 @@ Prints the file name of the current MPD song
Prints the song name in either the form "artist - title" or file name, depending on whats available
.TP
\fB\*(T<\fBnew_mails\fR\*(T>\fR
Unread mail count in mail spool.
\fB\*(T<\fBnew_mails\fR\*(T>\fR \*(T<\fB(mailbox)\fR\*(T> \*(T<\fB(interval)\fR\*(T>
Unread mail count in the specified mailbox or mail spool if
not. Both mbox and maildir type mailboxes are supported.
.TP
\fB\*(T<\fBnodename\fR\*(T>\fR

View File

@ -1080,9 +1080,14 @@
<varlistentry>
<term>
<command><option>mails</option></command>
<option>(mailbox)</option>
<option>(interval)</option>
</term>
<listitem>
Mail count in mail spool. You can use program like fetchmail to get mails from some server using your favourite protocol. See also new_mails.
Mail count in the specified mailbox or your mail spool if not.
Both mbox and maildir type mailboxes are supported. You can
use a program like fetchmail to get mails from some server
using your favourite protocol. See also new_mails.
<para></para></listitem>
</varlistentry>
@ -1282,9 +1287,12 @@
<varlistentry>
<term>
<command><option>new_mails</option></command>
<option>(mailbox)</option>
<option>(interval)</option>
</term>
<listitem>
Unread mail count in mail spool.
Unread mail count in the specified mailbox or mail spool if
not. Both mbox and maildir type mailboxes are supported.
<para></para></listitem>
</varlistentry>

View File

@ -222,9 +222,6 @@ void update_stuff()
if (NEED(INFO_DISKIO))
update_diskio();
if (NEED(INFO_MAIL))
update_mail_count();
#if defined(__linux__)
if (NEED(INFO_I8K))
update_i8k();

View File

@ -1294,6 +1294,7 @@ struct text_object {
int delay;
} rss;
#endif
struct local_mail_s local_mail;
} data;
};
@ -1842,6 +1843,10 @@ static void free_text_objects(unsigned int count, struct text_object *objs)
free(objs[i].data.mboxscan.args);
free(objs[i].data.mboxscan.output);
break;
case OBJ_mails:
case OBJ_new_mails:
free(objs[i].data.local_mail.box);
break;
case OBJ_imap:
free(info.mail);
break;
@ -2951,7 +2956,26 @@ static struct text_object *construct_text_object(const char *s, const char *arg,
blockdepth++;
END OBJ(kernel, 0)
END OBJ(machine, 0)
END OBJ(mails, INFO_MAIL)
END OBJ(mails, 0) {
float n1;
char box[256], dst[256];
if (!arg) {
n1 = 9.5;
strncpy(box, MAIL_FILE, sizeof(box));
}
else {
if (sscanf(arg, "%s %f", box, &n1) != 2) {
n1 = 9.5;
strncpy(box, arg, sizeof(box));
}
}
variable_substitute(box, dst, sizeof(dst));
obj->data.local_mail.box = strdup(dst);
obj->data.local_mail.interval = n1;
}
END OBJ(mboxscan, 0)
obj->data.mboxscan.args = (char*)malloc(TEXT_BUFFER_SIZE);
obj->data.mboxscan.output = (char*)malloc(text_buffer_size);
@ -2978,7 +3002,26 @@ static struct text_object *construct_text_object(const char *s, const char *arg,
scan_mixer_bar(arg, &obj->data.mixerbar.l,
&obj->data.mixerbar.w, &obj->data.mixerbar.h);
END
OBJ(new_mails, INFO_MAIL)
OBJ(new_mails, 0) {
float n1;
char box[256], dst[256];
if (!arg) {
n1 = 9.5;
strncpy(box, MAIL_FILE, sizeof(box));
}
else {
if (sscanf(arg, "%s %f", box, &n1) != 2) {
n1 = 9.5;
strncpy(box, arg, sizeof(box));
}
}
variable_substitute(box, dst, sizeof(dst));
obj->data.local_mail.box = strdup(dst);
obj->data.local_mail.interval = n1;
}
END OBJ(nodename, 0)
END OBJ(processes, INFO_PROCS)
END OBJ(running_processes, INFO_RUN_PROCS)
@ -4793,14 +4836,16 @@ static void generate_text_internal(char *p, int p_max_size, struct text_object *
/* mail stuff */
OBJ(mails) {
snprintf(p, p_max_size, "%d", cur->mail_count);
update_mail_count(&obj->data.local_mail);
snprintf(p, p_max_size, "%d", obj->data.local_mail.mail_count);
}
OBJ(mboxscan) {
mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output, TEXT_BUFFER_SIZE);
snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
}
OBJ(new_mails) {
snprintf(p, p_max_size, "%d", cur->new_mail_count);
update_mail_count(&obj->data.local_mail);
snprintf(p, p_max_size, "%d", obj->data.local_mail.new_mail_count);
}
OBJ(nodename) {
@ -6856,7 +6901,6 @@ void clean_up(void)
free(text);
free(current_config);
free(current_mail_spool);
#ifdef TCP_PORT_MONITOR
destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );

View File

@ -321,7 +321,6 @@ struct information {
float loadavg[3];
int new_mail_count, mail_count;
struct mail_s* mail;
int mail_running;
#ifdef MPD
@ -580,6 +579,15 @@ struct process {
float totalmem;
};
struct local_mail_s {
char *box;
int mail_count;
int new_mail_count;
float interval;
time_t last_mtime;
double last_update;
};
void update_top();
void free_all_processes();
struct process *get_first_process();

View File

@ -38,28 +38,25 @@
char *current_mail_spool;
static time_t last_mail_mtime;
static double last_mail_update;
void update_mail_count()
void update_mail_count(struct local_mail_s *mail)
{
struct stat buf;
if (current_mail_spool == NULL)
if (mail == NULL)
return;
/* TODO: use that fine file modification notify on Linux 2.4 */
/* don't check mail so often (9.5s is minimum interval) */
if (current_update_time - last_mail_update < 9.5)
if (current_update_time - mail->last_update < 9.5)
return;
else
last_mail_update = current_update_time;
mail->last_update = current_update_time;
if (stat(current_mail_spool, &buf)) {
if (stat(mail->box, &buf)) {
static int rep;
if (!rep) {
ERR("can't stat %s: %s", current_mail_spool,
ERR("can't stat %s: %s", mail->box,
strerror(errno));
rep = 1;
}
@ -71,17 +68,16 @@ void update_mail_count()
DIR *dir;
char *dirname;
struct dirent *dirent;
info.mail_count = 0;
info.new_mail_count = 0;
mail->mail_count = mail->new_mail_count = 0;
dirname =
(char *) malloc(sizeof(char) *
(strlen(current_mail_spool) + 5));
(strlen(mail->box) + 5));
if (!dirname) {
ERR("malloc");
return;
}
strcpy(dirname, current_mail_spool);
strcpy(dirname, mail->box);
strcat(dirname, "/");
/* checking the cur subdirectory */
strcat(dirname, "cur");
@ -96,7 +92,7 @@ void update_mail_count()
while (dirent) {
/* . and .. are skipped */
if (dirent->d_name[0] != '.') {
info.mail_count++;
mail->mail_count++;
}
dirent = readdir(dir);
}
@ -115,8 +111,8 @@ void update_mail_count()
while (dirent) {
/* . and .. are skipped */
if (dirent->d_name[0] != '.') {
info.new_mail_count++;
info.mail_count++;
mail->new_mail_count++;
mail->mail_count++;
}
dirent = readdir(dir);
}
@ -127,7 +123,7 @@ void update_mail_count()
}
#endif
/* mbox format */
if (buf.st_mtime != last_mail_mtime) {
if (buf.st_mtime != mail->last_mtime) {
/* yippee, modification time has changed, let's read mail count! */
static int rep;
FILE *fp;
@ -136,10 +132,9 @@ void update_mail_count()
/* could lock here but I don't think it's really worth it because
* this isn't going to write mail spool */
info.new_mail_count = 0;
info.mail_count = 0;
mail->new_mail_count = mail->mail_count = 0;
fp = open_file(current_mail_spool, &rep);
fp = open_file(mail->box, &rep);
if (!fp)
return;
@ -154,10 +149,10 @@ void update_mail_count()
/* ignore MAILER-DAEMON */
if (strncmp(buf + 5, "MAILER-DAEMON ", 14)
!= 0) {
info.mail_count++;
mail->mail_count++;
if (reading_status)
info.new_mail_count++;
mail->new_mail_count++;
else
reading_status = 1;
}
@ -167,7 +162,7 @@ void update_mail_count()
17) == 0) {
/* check that mail isn't already read */
if (strchr(buf + 21, '0'))
info.new_mail_count++;
mail->new_mail_count++;
reading_status = 0;
continue;
@ -176,7 +171,7 @@ void update_mail_count()
&& strncmp(buf, "Status:", 7) == 0) {
/* check that mail isn't already read */
if (strchr(buf + 7, 'R') == NULL)
info.new_mail_count++;
mail->new_mail_count++;
reading_status = 0;
continue;
@ -191,8 +186,8 @@ void update_mail_count()
fclose(fp);
if (reading_status)
info.new_mail_count++;
mail->new_mail_count++;
last_mail_mtime = buf.st_mtime;
mail->last_mtime = buf.st_mtime;
}
}