Re: [Nolug] automating email

From: Jerry Wilborn <jerrywilborn_at_gmail.com>
Date: Thu, 14 Apr 2011 08:17:49 -0500
Message-ID: <BANLkTinS1rWY+jq3YL55jZzTmhLOsH41Fw@mail.gmail.com>

Beat to fit, paint to match... Then add to cron.

#!/usr/bin/php
if ($conn = imap_open("{mail.domain.com:110/pop3}INBOX", "user@domain.com",
"secret")) {
$mc = imap_check($conn);
if ($mc->Nmsgs) {
print "Handling {$mc->Nmsgs} message" . ($mc->Nmsgs == 1 ? '' : 's') .
".\n";
$response = imap_fetch_overview($conn, "1:{$mc->Nmsgs}");

foreach ($response as $msg) {
if (preg_match("/(.*)\@domain\.com/", $msg->to, $matches) and $user =
$matches[1]) {
if (strtolower($user) == 'bob') {
// deal with attachments, see http://php.net/manual/en/book.imap.php for
example
// use file_put_contents to save body/attachments
} else {
// save to a catch-all location ?
}
}
}
}
}

Jerry Wilborn
jerrywilborn@gmail.com

On Thu, Apr 14, 2011 at 7:14 AM, Clint Billedeaux <clint@fastbadge.com>wrote:

>
>
> On Thu, Apr 14, 2011 at 12:12 AM, Petri Laihonen <pietu@weblizards.net>wrote:
>
>> Do you know any scripting languages such as PHP?
>>
>>
> I've been lucky enough to whack a PHP file or two into what I want, but I
> would never admit in public that I even have a clue what PHP is.
>
>
>
>> In the past, I made a PHP script to read mail, open the attachments and
>> then act upon the contents of said attachments. I was running the script
>> with cron, but nowdays I would just make a PHP script run as daemon which
>> can be stop|start|restart|etc just like any other daemon.
>>
>>
> I like the idea of using PHP though. I'll look into it. Thanks.
>
>
> IMHO, PHP is far easier than Procmail.
>>
>> P
>>
>>
>> On Wed, Apr 13, 2011 at 11:19 PM, Clint Billedeaux <clint@fastbadge.com>wrote:
>>
>>> I'm trying to automate some very routine email handling done by the
>>> office staff.
>>>
>>> At present, one person is assigned to check an email inbox and save it's
>>> attachments to folders on the file server. I'm sure scripting this to
>>> happen throughout the day shouldn't be a huge ordeal, but I haven't the
>>> foggiest idea how to start. I looked at a few procmail scripts, but I'm
>>> coming up short on comprehending how to save the email attachments.
>>>
>>> Any ideas where I should look for help?
>>>
>>> Thanks,
>>> Clint
>>>
>>
>>
>

___________________
Nolug mailing list
nolug@nolug.org
Received on 04/14/11

This archive was generated by hypermail 2.2.0 : 04/14/11 EDT