At 09:23 AM 11/4/94 +0000, Liam.Ward@Teltec.DCU.IE wrote:
>I'm a newbie to Majordomo and also to Perl more or less. I've set up a
>mailing list and would like to automatically number messages sent via the
>list. The number would be prepended to the subject line. The main purpose
>of this is to allow subscribers to know if they've missed a message and
>also to allow accurate referencing of the mail messages.
>
>I can try to learn more Perl and have a go at hacking the code but I'd like
>to ask your advice first. How difficult is this likely to be? My idea is to
>store a number in a file in the lists directory. For each message processed
>by resend, the number is read from the file inserted into the subject line
>somehow and re-written. Can anyone give me a few pointers on where to start
>changing things.
>
>Thanks in advance for any help you can give.
>
>Regards,
>
I had written something similar for archiving messages into separate, numbered
files. I adapted a chunk of that code to act as a subroutine within RESEND.
Let me state that I adapted this to work with the 1.62 RESEND, and I
haven't even seen the RESEND from 1.92. However, unless it's vastly different,
it should be easy enough to plug this in. I have to make a standard disclaimer
that if you try this and something bad happens, it's not my fault!
As always with perl, there's more than one way to do it. This method let's
the shell and 'sed' do the substitution work. The first version I did opened
yet another tmp file and processed the text again, but I thought that 3 tmp
files was just a bit too much. I don't know which method would be faster or
more efficient overall. The most important consideration was WHEN to add the
number, since you probably don't want to add sequence numbers to messages
that will end up getting bounced.
One last word regarding implementation: This should probably have a command
line switch or some other configuration method so that you can turn it on and
off per list. That's left as an exercise for the reader :-).
First, the inclusion of this subroutine requires the shlock.pl library, so
near the other "require" lines, add one that says:
requires "shlock.pl";
Then in the section of code just before the processed message gets sent, add
the call to the subroutine. And finally, change the system call to sendmail
so that the file passes through 'sed' on it's way to "sendmail". For 1.62,
it looked like this:
&get_msg_sequence; # This is the added call
if (defined($opt_d)) {
$| = 1;
print "Command: $sendmail_cmd\n";
$status = (system("cat /tmp/resend.$$.out") >> 8);
unlink(</tmp/resend.$$.*>);
exit($status);
} else {
#system("$sendmail_cmd </tmp/resend.$$.out");
# This next command is the modified sendmail command.
# Don't get confused by the extra backslashes. They're there to
# protect the command going through the "system" call.
# Note that this is all one line, but my mailer wants to wrap it.
system("cat /tmp/resend.$$.out|sed \'s/^Subject: \\(.*\\)/Subject: ($sequence) \\1
/\'|$sendmail_cmd");
unlink(</tmp/resend.$$.*>);
exit(0);
}
# Below is the actual subroutine:
# This routine generates and maintains 4 digit sequence numbers for messages.
# To increase the number of digits, change the "%04" to something else.
sub get_msg_sequence {
$seqfile = "$opt_l.N";
$sequence = 0;
chdir "$listdir" ||
die("resend-sequencer: cannot access lists directory $listdir");
if(! -e "$listdir/$seqfile") {
&lopen(SEQUENCE, ">", "$listdir/$seqfile");
printf SEQUENCE "%04d\n", $sequence;
&lreopen(SEQUENCE, "<", "$listdir/$seqfile");
} else {
&lopen(SEQUENCE, "<", "$listdir/$seqfile");
}
while(<SEQUENCE>) {
chop;
$sequence = $_;
}
++$sequence;
&lreopen(SEQUENCE, ">", "$listdir/$seqfile");
printf SEQUENCE "%04d\n", $sequence;
&lclose(SEQUENCE);
}
//////////////////////////////////////////////////////////////////////////////
Doug Plate Sr. <plate@dicomed.com>
Systems Engineer, Dicomed Inc. Burnsville, MN
Network Adminstrator Digital Photo Retouch Products
//////////////////////////////////////////////////////////////////////////////
Follow-Ups:
|
|