1 (edited by lakano 2015-08-18 20:25:02)

Topic: Pipe to external script and return the folder where to store the email

==== Required information ====
- iRedMail version (check /etc/iredmail-release):
- Linux/BSD distribution name and version:
- Store mail accounts in which backend (LDAP/MySQL/PGSQL):
- Web server (Apache or Nginx):
- Manage mail accounts with iRedAdmin-Pro?
- Related log if you're reporting an issue:
======== Required information ====
- iRedMail version (check /etc/iredmail-release): 0.9.2
- Linux/BSD distribution name and version: Ubuntu Server 14.04.1
- Store mail accounts in which backend (LDAP/MySQL/PGSQL): MySQL
- Web server (Apache or Nginx): Nginx
- Manage mail accounts with iRedAdmin-Pro? Not yet
- Related log if you're reporting an issue:
====

Hello,

Thanks again for your usefull tool iRedMail smile

I would like to pipe incoming email to my own postfix transport program, I've seen it's possible in the FAQ, but I also want to return the Maildir path where to store the email.

Is it possible ?

Before iRedMail, my script was called by the .procmailrc like that:

SWITCH=`/usr/bin/php /home/{$user}/.emails-switch/emails-switch.php`

:0 f
| formail -A "X-Emails-Switch: ${SWITCH}"

:0:
$SWITCH

Procmail doesn't seems to be installed with iRedMail, and I suppose because user account are virtual ( /var/vmail and no /home/$user/ account )

By the way, procmail was also permit me to dynamically inject new line in the headers of the email ( with "formail" tool ), I don't known if there is an alternative with iRedMail.

Any help will be appreciated smile

Thanks,
Regards

EDIT:

May be a solution will be to pipe my program and to add a new line in the header like that :
X-Emails-Switch: {$MAILDIR_PATH_TO_STORE}

Then to use Sieve rules to automatically moved all emails that contains this header to the value inside this header.
I've never used Sieve, so I don't known if it's possible...

----

Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.

2

Re: Pipe to external script and return the folder where to store the email

I don't quite understand what you want, but if you just want to know how to get the maildir path, here it is:

mysql> USE vmail;
mysql> SELECT CONCAT(mailbox.storagebasedirectory, '/', mailbox.storagenode, '/', mailbox.maildir) FROM mailbox WHERE username='user@domain.com' LIMIT 1;

3

Re: Pipe to external script and return the folder where to store the email

Thanks for your quick answer Zhang.
I known where is the Maildir, my apologies for my english if my problem wasn't clear.

In fact, I want to call an external script on each incoming email.
I known how to do that ( pipe / postfix transport program )

The goal of my program is to decide in which Maildir folder the email need to be saved.
What I don't known, it's how to said to iRedMail the folder path where to store the email incoming.

It's possible with Procmailrc with real unix account, but it's may be not possible at all in iRedMail because of virtual users.

Regards,

4

Re: Pipe to external script and return the folder where to store the email

If you get the maildir path, why cannot decides which folder to store the mail? I don't understand what the real problem is. Sorry.

5

Re: Pipe to external script and return the folder where to store the email

ZhangHuangbin wrote:

If you get the maildir path, why cannot decides which folder to store the mail? I don't understand what the real problem is. Sorry.

My program known the root Maildir.
My script will read the email, get sender/destinator, check my DB, and reply "this email go in INBOX/Family/"  or for example "this email need to be saved in INBOX/Business/ProjectName/"

My DB known in which folder to move the email by watching when the user move a n email to another folder.

( BTW, the script will also manage SPAM, with Captcha system)

So, my problem is, how my script can said to iRedMail (or Dovecot)  "save this email in INBOX/The/Good/Path/" ?

Currently, my script could said the path to procmailrc, but I don't known how to said that to iRedMail.

Regards

6

Re: Pipe to external script and return the folder where to store the email

Check the lines in /etc/postfix/master.cf:

# Use dovecot deliver program as LDA.                                              
dovecot unix    -       n       n       -       -      pipe                        
    flags=DRh user=vmail:vmail argv=/usr/libexec/dovecot/deliver -f ${sender} -d ${user}@${domain} -m ${extension}

So you may call the 'deliver' program with proper arguments. the '-m ${extension}' defines the folder name.

Check Dovecot wiki page for more details:
http://wiki2.dovecot.org/LDA

7 (edited by lakano 2015-08-19 17:22:07)

Re: Pipe to external script and return the folder where to store the email

Ok thanks Zhang !

So, it's not related to iRedMail, it's directly inside Postfix, and Postfix give the possibility to choose the maildir folder to dovecot with the "-m" parameter.

Now, I need to found a solution that permit to my previous piped program, to dynamically change the ${extension} value, for each incoming email.

I don't known if it's possible, may be it's a simple environment value. If you have information about this, this could help smile

Thanks again for your time and perseverance!
Best regards,

EDIT: I'll try an alternative option, use Sieve + extprogram to call my script
PS: I don't found any option to close topic.