View Full Version : Python filter to move mail to another mailbox
MarkW
06-20-2005, 10:47 AM
Hi
I have a mailbox that I want to periodically 'empty' into another mailbox.
Can this be done with a Python filter script, and can someone please provide an example.
I'd like to be able to execute this script both automatically or via a page-call (e.g. http://www.example.com/movemymail.php). An example of how this call is made in php would also be appreciated.
Many thanks
Mark
sheila
06-21-2005, 07:26 PM
The only methods for accessing mailboxes on the FutureQuest network via scripts are...
POP3 protocol
IMAP protocol
SMTP protocol
or, for sending email to a mailbox, "piping" an email to the mail server.
In order to "move" email from one mailbox to another, you would need to do two steps:
(1) Retrieve the email from the first mailbox
(2) Send the email to the second mailbox.
For (1) you have two options: POP3 or IMAP. IMAP is supposedly much more complicated than using POP3. I've not personally done much with IMAP in Python scripts (a teensy bit of poking around). For anything that actually works and accomplishes something, I've used POP3.
Here are links to two rather similar POP3 Python scripts that retrieve email from a POP mailbox (among other things):
http://www.aota.net/forums/showthread.php?postid=75306#post75306
http://www.aota.net/forums/showthread.php?postid=67492#post67492
Once you have retrieved the email in part (1) using POP3 or IMAP, then you would need to use either IMAP, SMTP or "file pipe" to send the emails to the second mailbox. Again, I have no experience writing Python scripts that use IMAP to do this. However, directions using the other two methods are available here:
http://www.thinkspot.net/sheila/article.php?story=20040822174141155
I hope that gets you started....
kitchin
06-21-2005, 10:45 PM
:ytskydve:
You can do this task from th CNC control panel. Click Email manager and then the name of the POP mailbox. There're links for Messages: "Forward", "Delete" and "Reset".
<edit>I re-read your original post, so CNC is not what you're looking for. :ythair: </edit>
sheila
06-22-2005, 12:22 AM
Actually, I think the CNC would be fine for his "wants to be able to call it from a PHP page" version. If he did call the script from a PHP page, it would have to be available under his /www folder, which means publicly accessible, then you'd need to password protect it... The CNC is already secured and provides this functionality, so no sense in re-inventing the wheel.
Unless he wants someone who does not have CNC access to run the script from this PHP page, then I would recommend the CNC version for that.
Of course, that doesn't work for the "automatically" running version (which I assume would be a cron job).
The other thing about using the CNC to accomplish this task from a web page, is that it doesn't require using two different language interpreters to preform a single task. Somehow it always grates on me to see someone use a PHP page to call a script in another language, or vice-versa (call a Perl or PHP script from within a Python cgi script...for example).
I don't think you want to do this with a "filter" script, either...as filters run every time an email is received at the target email address, and you don't want to "empty" the first mailbox every time it receives an email. So what you really want is a cron job (or use the CNC as kitchin suggested for doing it from a web page).
Couldn't it be easily accomplished by just putting in that nifty forward script FQ has in the Knowledge base section? I've used it and if I recall, it was one short line of code and all mail to that box went to a non-FQ box while leaving a copy on the server which was deleted manually once in a while.
Betsy
--looking quickly around to make sure no one named Pete ever mentioned this before.
sheila
06-22-2005, 12:58 AM
You know, since Mark hasn't really provided a lot of details about his goal/purpose in seeking a scripting solution, it's hard to say. But that forwarding script you mention, Betsy, certainly would be MUCH easier to implement than the Python solution originally requested. If it would suit his purposes, then it's a no-brainer. Thanks for suggesting it. (Somehow, I am just not coming up with the "easy" ideas tonight...)
It's that big moon, Sheila. Don't worry, it too will pass to another phase soon :ytflying:
Betsy
--where's the FQ cow jumping over the moon?
MarkW
06-22-2005, 06:40 AM
Hi guys
Just a quick note to says thanks for all your advice. I'll need to study them in more detail later, when I'm less snowed under, but I do appreciate your expertise in the area.
Thanks
Mark
vBulletin® v3.6.8, Copyright ©2000-2009, Jelsoft Enterprises Ltd.