[prev in list] [next in list] [prev in thread] [next in thread]
List: cgi-list
Subject: Re: [CGI] counting msgs in mailbox on same server
From: Daniel Macks <dmacks () netspace ! org>
Date: 1998-06-22 3:22:34
[Download RAW message or body]
Jann Linder said:
:
: I need a surefire way of opening a mailbox (using the mailbox path, ie:
: /usr/spool/mail/jann) and placing each msg as an element of an array.
:
: This is what i have so far..but it doesnt take into account msgs that have
: the "mail msgs separator" (ie: newline newline "From ") in their bodies...
The "formail" command is good at parsing mailbox files, and understands
how to ignore those bogus "From"s. It can even fork off a command-line for
each message it finds. So my thought was to open a pipeline in which
formail's command is to append \0 (or some other guaranteed-not-to-be-
in-email delimitter) to each message. I'm having trouble making this
more elegant, but the following seems to solve the problem:
#!/usr/bin/perl
$/ = "\0";
open (FH,"formail -ds ender < $mailbox_filename |"); # 1
@msgs = <FH>;
close(FH);
pop @msgs; # 2
map chop, @msgs; # 3
print scalar (@msgs);
Note 1: I would have liked the command for formail -s to be
'cat - ; echo "\0"'
but formail (unlike find) doesn't seem to like multiple commands.
My work-around was to write a dinky command "ender":
#!/bin/csh -f
cat - ; echo "\000"
The effect is to insert a \0 into the stream between each message.
Note 2: There's a \0 after the last message, so which the read sees
as meaning there's another message to go, which there isn't.
Note 3: The record-separator is the last character of each message.
dan
--
Daniel Macks
dmacks@a.chem.upenn.edu
dmacks@netspace.org
http://www.netspace.org/~dmacks
-----------------------------------------------------------------
For subscription information, http://www.jann.com/lwgate/lwgate.pl/CGI-LIST/.
The CGI Tips & Tricks website (and archive of the list) is located
at http://www.jann.com/Perl/
cgi-list is hosted by Wizards of the Web (http://wizweb.com).
-----------------------------------------------------------------
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic