View previous topic :: View next topic |
Author |
Message |
szatox Advocate
Joined: 27 Aug 2013 Posts: 3432
|
Posted: Sat Feb 10, 2018 11:26 pm Post subject: Email server: how do I filter messages sent by me? |
|
|
Yet another topic I really didn't know where to post.
I'm building my email server. The first and most basic bits are in place: postfix (MTA), dovecot (mailboxes, sasl, imap), mysql (domains, auth info, aliases), even certbot. So far so good.
I configured postfix to BCC the sender if sender's address is found in the database.
Now I'm trying to figure out a way to filter those messages from dovecot's Inbox folder to Sent folder.
In the most basic case I can use a sieve like that:
Code: | require "envelope";
require "imap4flags";
require "fileinto";
require "mailbox";
require "variables";
if envelope :matches "from" "*"
{
set "from" "${1}" ;
}
if envelope :matches "to" "${from}"
{
setflag "\\seen";
fileinto :create "Sent";
}
|
Unfortunately, it stops working as soon as I send an email from an alias address.
Unsurprisingly, in this case "from" address doesn't match delivery address anymore. Any ideas how I could handle it?
I'm in research/development phase with this one, I'm likely to scrap it at some point and reinstall, so even big changes are possible. |
|
Back to top |
|
|
szatox Advocate
Joined: 27 Aug 2013 Posts: 3432
|
Posted: Sat Feb 17, 2018 8:23 pm Post subject: |
|
|
For the record, I found extension to dovecot's sieve. I hoped for a more "native" solution, but it works well enough.
I came with a solution that:
- binds envelope TO and FROM to variables
- invokes an external script with bound variables as parameters
- binds output from script to another variable and uses error code to determine test result
The external script is basically an SQL query asking the database whether or not the addresses provided belong to the same user.
There is also another extension, external data source, however I'd rather have my database return a simple answer than dump the whole table into a dictionary so I can process it myself every time a message reaches some mailbox. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|