Re: Re: accessing mailbox files
by tedrek (Pilgrim) on Jul 28, 2003 at 22:19 UTC
|
I just want to point out that depending on your MTA mail can be delivered to a maildir format box instead of mbox format, in which case you would have multiple messages each in their own file inside of one directory. of course you could also have your mail delivered to the moon dependant on your MTA :P
| [reply] |
|
|
tedrek,
I will not to pretend to be an expert at Sendmail, but that is the MTA referenced in previous threads. It has been my experience on every *nix box I have been on that it is a single mbox file. I also admit that Sendmail has been around forever and could probably be configured to cook dinner if you wanted to - so point taken. It doesn't change the fact that this isn't the "out of the box" configuration for Sendmail, so it caught myself (as well as others) off guard.
Cheers - L~R
| [reply] |
Re: Re: accessing mailbox files
by jc23 (Acolyte) on Jul 28, 2003 at 22:23 UTC
|
Hey L~R,
Thanks for your patience. You are correct in your assumptions. There are messages in a temp folder received via Sendmail, that I would like to forward to another account. The messages have not been modified. They are simply directly forwarded. It's basically like an auto forwarding script out of one directory. I'm not sure what the exact format of email messages are in a folder, so I assume each message was its own file. Please correct me on that if I am wrong. I have integrated your code with a modified version of the script I was writing. I'm pretty sure there are things wrong with it so please let me know. =).
use strict;
use Cwd;
use Lite;
use Mail:Audit;
my $dirpath;
my $divider = 0;
my $input;
my $mailprog = '/usr/lib/sendmail';
my $recipient= 'recip@email.com';
my $sender = 'jc@email.com';
my $dirpath = '/var/mail/user/temp';
unless ( chdir $dirpath ) #change to directory
{
exit(0);
}
unless (opendir( CHANGEME, $dirpath )){
# print "\nCan't open $dirpath. ";
exit (0);
}
#find all directory contents OTHER than those that begin in .
my @dirContents = grep !/^\./, readdir(CHANGEME);
if(!@dirContents){
# print "No files were found inside $dirpath\n";
exit (0);
}
#forward each email message to recipient
foreach my $dirContent ( @dirContents )
{
open (MESSAGE, "$dirContent");
my @message = <MESSAGE>;
my $mail = Mail::Audit->new(data => \@message);
my $recip = $recipient;
$mail->replace_header('To', $recip);
$mail->resend($recip);
`rm $dirContent`;
}
closedir ( CHANGEME );
exit (0);
Could this also be done using MIME::Lite?
Thanks for the tips!
jc
| [reply] [d/l] |
|
|
| [reply] |
|
|
L~R,
Here's the big picture: The user chooses to send a bunch of messages to an alias that will later post everything onto a webboard. Instead of sending each mail separate, the user can drag and drop all da mail files he wants posted or any original email he writes into the folder *temp*. THe script I was asking for help on, will then go through the folder and "forward" each piece of mail to the alias. I wanted this "Forwarding" step to be automatic.
I'm not sure what you mean by *forks*. If this is a more efficient process than the script, could you please tell me how to set this up?
Lastly, someone mentioned that all messages in a mailbox is kept in one file. Does the code you posted earlier allow each message to be grabbed from the one index file and sent out separately?
thanks for the help.
jc
PS I will go back and clean up the variables and formatting. I pulled that portion of it out of a larger context.
| [reply] |
|
|
|
|
|
|
Reinventing the wheel and all that. I sound like a broken record, I guess, but I have some questions.
Q: It looks to me like if the $dirContent file has more than one message in it, you won't forward other than the first messages. Is that the case?
Q: Are you just forwarding ALL of the mail sent to a given user? If so, how is this superior to a .forward file in the user's home directory that contains: recip@email.com?
Q: If you are filtering mail to a user based on some criteria, how is this superior to using procmail? e.g. a .procmailrc file that filters for Perlmonks in the subject:
:0:
* ^Subject:.*Perlmonks.*
! recip@email.com
| [reply] [d/l] |
|
|
Saintbrie,
To clarify, I am forwarding all messages in a single local mail folder, not all contents of inbox. I'm not sure how to do this in procmail, so I haven't used that laternative.
Secondly, mail in the folder that is being forwarded, isn't incoming mail. It is mail that has been drag and dropped from a separate mail folder using dtmail. In other words, it is mail that the user has chosen to send out to a single alias. By putting all the mail to be sent to one address in a folder and having it automatically send, it is less tedious.
Hope that clarifies.
jc
| [reply] |
|
|
| [reply] |
|
|
If all you are trying to do is to take some raw email messages in files and forward them to another account, then look at using formail. It is installed along side sendmail, and is useful for parsing email messages.
I have used the following to send an entire mbox file to another user:
cat <mboxfile> | formail +1 -ds sendmail -oem <dest-address>
I admit that I have not read your other questions, so I may be off base with what you are trying to achieve, but I always think it wise to look at the tools you have available with your mail system before starting to write your own...
- Cees | [reply] [d/l] |
|
|
| [reply] |
|
|
|
|
|