Implement Drush commands for Mailhandler
| Project: | Mailhandler |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | xurizaemon |
| Status: | needs review |
Jump to:
Drush implementation using this patch allows us to separate the frequency of mailhandler retrievals from the frequency of running Drupal cron.
This feature request was inspired by #392782: Retrieve content automatically w/out running cron? (Every 5 mins cron seems too much). Some sites wish to be able to run Mailhandler frequently, and cron infrequently.
Files attached here are identical to the files in comment #12 on that issue.
By mailhandler.drush.inc in the mailhandler directory* you can use it thus:
## show available mailboxes
$ drush mailhandler list
Available mailhandler mailboxes: test1@example.org, test2@example.org
## retrieve all mailboxes
$ drush mailhandler retrieve
Retrieving mail for test1@example.org
Retrieving mail for test2@example.org
## retrieve a specific mailbox
$ drush mailhandler retrieve test2@example.org
Retrieving mail for test2@example.orgTo check all mailhandler mailboxes at a ten minute interval, use a system cron entry like this:
*/10 * * * * /path/to/drush mailhandler retrieveAttached ZIP contains mailhandler.drush.inc for easy installation. Patch is against CVS DRUPAL-6--1.
| Attachment | Size |
|---|---|
| 392782-mailhandler_drush_retrieve.patch | 3.11 KB |
| mailhandler-drush-inc.zip | 1.67 KB |

#1
What I meant to say was,
By placing mailhandler.drush.inc in the mailhandler directory* you can use it thus:
...
* Or if you want to keep your mailhandler module install super-clean, ...
You can put your drush command file in a number of places:
- In a .drush folder in your HOME folder. Note, that you have
to make the .drush folder yourself.
- Along with one of your existing modules. If your command is
related to an existing module, this is the preferred option.
- In a folder specified with the include option (see above).
- In /path/to/drush/commands (not a Smart Thing, but it would work).
... but then you'll probably need to remove the command file if Mailhandler starts shipping its own copy, as I hope it will.
#2
A couple of things which came up while implementing this:
drush mailhandler retrieveruns each ten minutes, then the mailbox may be accessed twice at :00. There are other situations where this might arise, eg someone doing a manual retrieve while cron is running, or two admins simultaneously retrieving. So locking to prevent duplicate retrievals may be a consideration.mailhandler_cron_retrieve()could return$retrieved_messages, at which point Drush could report the number of successful messages retrieved. (The number of successful node / comment submissions would also be interesting to see here, but that's notmailhandler_cron_retrieve()'s job.Neither of these are required to be fixed for this issue IMO, but they might be worth their own issues if the Mailhandler team thinks they are worth raising.
#3
subscribing
#4
The (now postponed) issue #606018: Provide argument to drush cron allowing specific cron hooks to be run was inspired by this issue, but the patch here allows finer control of mailhandler, as it makes it possible to handle mailboxes individually as well.