zsh-users
 help / color / mirror / code / Atom feed
From: Pete Williams <petew@lexis-nexis.com>
To: Justin Sheehy <dworkin@k2.ccs.neu.edu>
Cc: zsh-users@math.gatech.edu
Subject: Program for Mail-checking MH folders
Date: Fri, 26 Jan 96 14:41:40 EST	[thread overview]
Message-ID: <9601261941.AA26216@ant.lexis-nexis.com> (raw)
In-Reply-To: Your message of "Fri, 12 Jan 96 22:51:54 EST." <199601130351.WAA10123@k2.ccs.neu.edu>

Justin Sheehy <dworkin@k2.ccs.neu.edu> writes:
>>I'm trying to set up my mail variables within zsh 2.5.03 so that whenever
>>mail arrives within one of my MH folders (it's been pre-filtered by mailagent
>
>As an mh user and a zsh user, I have had this same problem.
>You cannot get zsh to work with mh without extreme kludginess. What I

I had been trying to get the zsh "mail" variable to work with MH folders. 
As all my mail is prefiltered, my spoolfile rarely has any mail.  As zsh
has (apparently) no way of checking MH folders for new mail, I whipped up a
perl script to do the job.

What it does is build a "database" of you current MH folders (as a DBM
file), and then every time it's called, it looks at the "Unseen-Sequence"
line of each folder to see if there's anything new and prints out an
appropriate message to the terminal.

Additional notes head the program.
 
It's a quick hack, but it works for my purposes.  Hope someone else will
find it useful.

Pete Williams <petew@lexis-nexis.com>

--------------- SITUATION: Users Want Phone List Application ---------------
ADMINISTRATIVE FASCIST: Oracle.  Users give up and go back to post-it notes.
  -- Stephan Zielinski "KNOW YOUR UNIX SYSTEM ADMINISTRATOR - A Field Guide"

#! /usr/local/bin/perl
##############################################################################
# CHECKMH
#
# To find MH folders with new mail and print out those that do.
#
#  Install:
# 1. Change the $mailspool and $mailbox variables to point to your system
#    mail spooling directory and the name of your home mailbox directory,
#    respectively.
# 2. Change $dbmbase, $dbmfile, and $dbmpag if you wish your dbm file to be
#    something besides $maildir/.curfolders.
# 3. Look at your .mh_profile and check the value of "Unseen-Sequence".  Set
#    the variable $unseen_seq to this value.  If it's not there, add the line
#    "Unseen-Sequence: unseen" to .mh_profile.
# 4. If running under zsh, and you want to emulate the behavior of the 
#    "mail" variable,
#    -- add this line to ~/.zshenv: "export PERIOD=600"
#    -- add this line to ~/.zshrc:  "periodic () { ~/bin/checkmh }"
# 5. You should run this script with the "-i" option periodically so that
#    your current (existing) folders are kept updated.  Add a crontab entry
#    like the following:
#    23 19 * * 0-5 /u/pete/bin/checkmh -i
#
###############################################################################

$| = 1;

$mailspool = '/var/spool/mail';
$mailbox   = 'Mail';
$dbmbase   = '.curfolders';
$unseen_seq= 'unseen';

($name,$homedir) = (getpwuid($<))[0,7];

$spool   = "${mailspool}/$name";
$maildir = "${homedir}/$mailbox";
$dbmfile = "${maildir}/$dbmbase";
$dbmpag  = "${maildir}/${dbmbase}.pag";

$0 =~ s:^.*/::;

if ($_ = $ARGV[0]) {
	if (/^-i/) { 
		&update_mhfolders;
	} else {
		die <<"UrGgGh!";
usage: $0 [-i]
       $0   : check MH folders
       $0 -i: update folder list in folder database
UrGgGh!
	}
} else {
	&check_mail;
}

##############################################################################
# CHECK_MAIL
#
# Check system mailbox first, then all the MH folders
# Report results to STDOUT
##############################################################################

sub check_mail {
	&update_mhfolders unless -e $dbmpag;

	dbmopen(FOLDERDBM,$dbmfile,0666) || die "Can't open $dbmfile: $!";

	foreach $folder (sort keys %FOLDERDBM) {
		($basename = $folder) =~ s:^${maildir}/::;
		substr($basename,0,0) = '+';
		$seqfile = join('/',$folder,'.mh_sequences');
		open(SEQ,$seqfile); # No warning, but probably not a problem!
		while (<SEQ>) {
			next unless /^$unseen_seq:/;
			print "New mail in $basename.\n";
		}
		close SEQ;
	}

	dbmclose FOLDERDBM;
}

##############################################################################
# UPDATE_MHFOLDERS
#
# Initialize (-i)/update the mhfolders database.
# Updates a dbm file on the current folders in the MAIL directory.
# Normally run once at setup time and then added to the user's crontab file.
##############################################################################

sub update_mhfolders {
	local(%tmparray);
	require "find.pl";

	dbmopen(FOLDERDBM,$dbmfile,0666) || die "Can't open $dbmfile: $!";

	foreach $key (keys %FOLDERDBM) { delete $FOLDERDBM{$key}; }

	&find($maildir);

	warn "MH folders added to $dbmfile:\n";

	foreach $key (keys %tmparray) {
		unless ($key eq $maildir) {
			# If run by cron, this line should send you info about
			# new folders added to the dbm file.
			warn "    $key\n";
			$FOLDERDBM{$key}++;
		}
	}

	dbmclose FOLDERDBM;
	exit;
}

##############################################################################
# WANTED
# Traverse desired filesystems
##############################################################################

sub wanted {
	if ((($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) && -d _) {
		$name =~ s:^//:/:;
		$tmparray{$name}++;
	}
}


      reply	other threads:[~1996-01-26 20:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-01-12 22:12 MAIL variable help! Pete Williams
1996-01-13  3:51 ` Justin Sheehy
1996-01-26 19:41   ` Pete Williams [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9601261941.AA26216@ant.lexis-nexis.com \
    --to=petew@lexis-nexis.com \
    --cc=dworkin@k2.ccs.neu.edu \
    --cc=zsh-users@math.gatech.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).