Re: email status, RO...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Joe Szilagyi wrote:
> Normally something in /var/spool/mail doesn't pick up the lines:
> 
> Status: O
> Status: RO
> 
> Or the link until a mail client actually accesses it, such as Pine (simply
> launching it), or Evo, Outlook, etc.
> 
> Is there any way in bash to force the file to upload, and pick up these
> tags, and be listed as R or RO? I'm wanting to write a quick script to read
> mailboxes and accurately output the number of "new" emails in a box without
> actually going into it.

Well, you haven't actually given us much to go on, here. There are a
number of ways of configuring e-mail.

The mention of Outlook makes me assume that you're running POP3 and/or
IMAP servers: which one (Dovecot? Cyrus?) Is *all* your e-mail access
through that service, or do you read any locally? What, exactly, do you
mean by "upload"?

The Status: header is traditional Unix mailbox format (see
http://www.washington.edu/pine/pine-info/2004.01/msg00061.html for more
details).

In my case, for instance, I use procmail to deliver to maildir folders,
in which case, counting the "new" items is simply a matter of doing a
wc -l on the "New" directory inside the maildir. Other flags are stored
in the filename, where you can use globs.

If what you're really after is a way to count e-mails in a file without
the Status: line, and if you're sure your MTA quotes lines that start
"From ", then you could use grep -c to count lines beginning "From "
and subtract the number of "Status: " lines.

Or you could add a blank "Status: " through procmail.

Um. You said "accurately". This means reading the mailbox: you can't
guarantee that some inconsiderate individual on a mailing list won't put
Status: at the beginning of a line... You need to know when a header
starts, and when it stops.

The procmail package already has a program to do this: formail.
formail -x From\  -s < mailbox
will list each "From " header in the mailbox.
formail -x Status -s < mailbox
will list each Status line in the mailbox. Use wc -l on each to count, and
expr to do the maths.

Hope this helps,

James.
-- 
E-mail address: james | "I blame the teachers, and I blame the politicians
@westexe.demon.co.uk  | for picking the teachers, and I blame the parents
                      | for voting them in, and top of the list I put the
                      | bastard who invented the caps-lock key."
                      |     -- Chris Hacking



[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux