Subject: checking for new mail

From: "Eric R. Holst" <[email-masked]>
Date: Tue, 14 Mar 1995 09:55:03 -0800 (PST)

I have been using procmail to filter my incoming mail into
different inbox folders in pine.  Everything works fine, 
except, I can't tell if I have new mail in these folders.

When I use frm or nfrm from the elm package, they
erroneously report that I have read mail in these folders
when there is new/unread mail in them.

If I try to us the from command (SunOs 4.1), I can's seem
to be able to specify my folders with the -e argument.

Please help, as I am growing tired of having to run pine
every time I want to check if I have new mail.

    /----------Eric R. Holst-----------------Microcomputer Specialist-----\
   |                Ventura County Library Services Agency                 |
   | [email-masked]  <insert standard disclaimer here>  C$erve 76527,162  |
    \---------------just slaving away in sunny Ventura, CA----------------/

---

From: Chris Halverson <[email-masked]>
Date: Tue, 14 Mar 1995 12:51:42 -0600 (CST)

> to be able to specify my folders with the -e argument.

Use the mailstat program that comes with Procmail to see to which folders
mail has been delivered. 

You could also setup multiple incoming folders in Pine. I never leave Pine
(3.91), I have setup multiple incoming folders and I just hit <TAB> to go
from my Inbox to the next incoming folder has new mail.  Pretty nice 
setup actually.

--
Chris D. Halverson          |  UNIX System Administrator
T I E S                     |  Voice: (612) 638-2311
1925 West County Rd. B2     |  Email: [email-masked]
Roseville, MN  55113-2791   |  WWW: http://www.ties.k12.mn.us/~cdh/

---

From: Mark Bynum <[email-masked]>
Date: Tue, 14 Mar 1995 14:12:24 -0500 (EST)

I had this same problem yesterday. I just got the elm sources, and rebuilt
from.c (frm) with a hack to it to display that you have new messages in
other folders than your main mailbox. frm and elm initially only recognize new
messages in the main mailbox, but with a modification to elm and frm you
can change this. If you want me to send you a copy of the "modified" frm
let me know.

An associated question is, does anyone see a problem with me as a regular user
having my own copy of elm, with the "modification" installed?

Anyway here is what I changed in from.c:

Change:
	    if (user_mailbox)
	      status = NEW_MSG;
	    else
	      status = READ_MSG;

to:
	    status = NEW_MSG;

It should work then. Note that there are some elm-created libraries and headers
it needs to recompile, and that if you get the default tar file (elm2.4.tar.gz)
then you should build the lib directory (so that you get the elm library), and
do a "make all" in the utils directory ("make from" crashed for me every time).

Good luck (you'll need it),

Mark Bynum
[email-masked]

---

From: [email-masked] (Rodney P. Rutherford)
Date: Wed, 15 Mar 1995 08:50:38 -0800 (PST)

>     \---------------just slaving away in sunny Ventura, CA----------------/

I have been following the various versions of this thread for the past few
weeks (I finally got caught up on all of my mailing lists!) and thought I 
would provide my solution.

As others have indicated, setting the MAIL variable will specify your default
in box, so that elm, etc will display status.  Setting this variable also
handles proper locking on the mailbox you are reading as well. I took this 
info and put together a script that allows me to read all of my incoming 
mailboxes.

The other thing I do to facilitate this, is that I have setup my .procmailrc
to filter my mailing lists into seperate incoming mailboxes.  My script is
setup so that it reads these based upon the user setting the variable 
MAILBOX.  I use my incoming mailboxes just for that: incoming mail only.
If I wish to save any messages, I save them to a different mailbox.  ie,
for this mailing list I filter the incoming mail into $HOME/Mail/procmail-in
and save any messages to $HOME/Mail/procmail.  That way my incoming mailboxes
are always kept to a minimum.

I believe that I have setup my script to allow it to be transportable across
systems, and makes allows it to work with whatever mail reader you may be
using.  For your system, you will just want to set the defaults to the
correct values.  If anyone has any suggestions or feedback on the script, 
please email me.

Best regards,

Rodney

************************** CUT HERE ********************** 
#!/bin/csh -f
# /usr/local/bin/pmail
# Mon Mar  6 08:16:19 PST 1995 - Rodney P. Rutherford - [email-masked]
# Script for reading multiple incoming mailboxes

# First check for pre-existing variables.  The user should set the variables
# to the correct values in their .login file.  For example:
# setenv MAILBOX '/var/spool/mail/$user bind-in firewalls-in procmail-in'
# If these are not pre-defined, then they are set to a default value.
#
if ( "$?MAILDIR" == "0" ) then
	set MAILDIR=$HOME/Mail
endif

if ( "$?MAILBOX" == "0" ) then
	set MAILBOX = /var/spool/mail/$user
endif

if ( "$?READER" == "0" ) then
	set READER=/usr/local/bin/elm
endif

if ( "$?FROM" == "0" ) then
	set FROM='/usr/local/bin/frm -Sq'
endif

# The script will now indicate how many messages are in the mailbox(es)
# The script will now indicate how many messages are in the mailbox(es)
# and prompt the user if they wish to read that mailbox (y/n) or quit
# completely out of the script
#
cd $MAILDIR
clear

foreach FILE ($MAILBOX)
echo ""
echo -n "Your $FILE "
$FROM $FILE
echo ""
echo -n "Do you wish to read the $FILE folder now? [y/n/q] "
set input = $<
switch ($input)
        case n:
        case N:
        case no:
        case NO:
	   clear
           breaksw

	case q:
	case Q:
	case quit:
	case QUIT:
	   echo ""
	   exit

	default:
	   setenv MAIL $FILE
	   $READER
	   clear
	   breaksw
endsw
end
clear
exit
************************** CUT HERE ********************** 
-- 
 |  Rodney P. Rutherford   Zzyzx Workstation Peripherals      619-558-7800 |
 |  Technical  Director		5893 Oberlin Drive	      800-876-7818 |
 |  [email-masked]           San Diego, CA. 92121	 FAX: 619-558-8283 |

---

From: Alan Schwartz <[email-masked]>
Date: Wed, 15 Mar 1995 21:29:13 -0800 (PST)

> except, I can't tell if I have new mail in these folders.

I do this by having procmail log incoming mail to a file
(mail.log in my Mail directory), and checking if this file exists
on login (in my .login):

if (-e ~/Mail/mail.log) ~/Mail/procreport ~/Mail/mail.log

If it's there, I run my procreport script, which looks like this:

#!/usr/local/bin/perl5
#
# procreport - summarize procmail's mail.log LOGFILE
# Usage: procreport <filename>
#
while (<>) {
  next if (/^\s*(From|Subject)/);
  if (/Folder: (.*)\s+(\d+)$/) {
	$folder = join(" ",split(" ",$1));
	$count{$folder}++;
  }
}
foreach $folder (sort keys %count) {
  printf "%6d messages sent to %s\n",  $count{$folder}, $folder;
}

That'll show me where new mail has arrived when I log in.

In my .logout file, I delete mail.log. If you wanted to keep your
mail log, you could append it to a permanent file before removing it.
This has worked very well for me, as I'm usually only concerned
about mail that's arrived when I'm not logged in. I use the
mail shell variable to handle mail while I'm logged in.

Good luck!

 - Alan Schwartz

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
         Alan Schwartz           | Disclaimer: I represent no one
                                 |
[email-masked]       | "Life is what happens to you while
UC Berkeley                      |  you're busy making other plans"
Cognitive Psychology             |          - J. Lennon
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

---

From: "Amos A. Gouaux" <[email-masked]>
Date: Thu, 16 Mar 1995 01:49:04 -0600 (CST)

> > except, I can't tell if I have new mail in these folders.

Attached is a little hack I run when I login.  It produces output like 
this:  

    % ckmail
    Your "inbox" folder has 8 new messages.
    Your "tex-support" folder has 115 new messages.
    Your "pkg-log" folder has 156 new messages.
    Your "info-solbourne" folder has 44 new messages.
    Your "work" folder has 2 new messages.
    Your "ablan" folder has 1 new message.

I've been using it for a long time with Pine without any probs, though
I've heard that it doesn't work so well with Elm because Elm isn't always
very good about updating the status of the message.  However I haven't
verified that.

Then, after I have logged in, I usually do `tail -f proclog' in an xterm
window.  Not very sophisticated but it does okay.

Amos

#!/usr/local/bin/perl

$inbox = "/var/spool/mail/" . $ENV{'USER'};
$folderdir = $ENV{'HOME'} . "/mail/fol";
$pmrc = $ENV{'HOME'} . "/.procmailrc";

if (-f $inbox)  {
    &check_for_newmail($inbox);
}
if (-f $pmrc)  {
    chdir($folderdir);
    foreach $folder (&get_procmail_folders)  {
        next if (! -f $folder);
        &check_for_newmail($folder);
    }
}

sub check_for_newmail  {
    local($folder) = @_;
    local($new,$mesg);
    $new = 0;
    open(FOL,"< $folder") || die("Can't open folder $folder: $!");
    while (<FOL>)  {
        if (/^From .* \w+ \w+\s+\d+ \d+:\d+:\d+ \d+$/)  {
            $new++;
            while (<FOL>)  {
                $new-- if (/^Status: RO$/);
                last if (/^$/);
            }
        }
    }
    close(FOL);
    if ($new)  {
        $folder = "inbox" if ($folder eq $inbox);
        $mesg = "Your \"$folder\" folder has $new new message";
        $mesg = $mesg . "s" if ($new > 1);
        print("${mesg}.\n");
    }
}

sub get_procmail_folders  {
    local(@pmfolders,$conds,$action);
    @pmfolders = ();
    open(PM,"< $pmrc") || die("Can't open $pmrc: $!"); 
    while (<PM>)  {
        if (/^\s*:.*$/)  {      # beginning of a rule
            if (/(\d+)/)  {
                $conds = $1;    # number of patterns specified
            }
            elsif (/^\s*:.*A.*$/)  {
                $conds = 0;
            }
            else  {
                $conds = 1;
            }
            for ($i = 0; $i < $conds; $i++)  {
                <PM>;           # throw away known number of patterns
            }
            $_ = <PM>;          # folder unless using new syntax
            if (/^\s*\*.*$/)  {    # new syntax for pattern lines
                while (<PM>)  {
                    last if (/^[^*].*$/); # no more patterns
                }
            }
            chop($action = $_);
            $action =~ s/\\//g; # remove any "\" if they should exist
            if ($action !~ /^\s*[!|{].*$/ && !grep(/$action/,@pmfolders))  {
                push(@pmfolders,$action); # add action to list of folders
            }
        }
    }
    close(PM);
    @pmfolders;
}