Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Email server: how do I filter messages sent by me?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo
View previous topic :: View next topic  
Author Message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3432

PostPosted: Sat Feb 10, 2018 11:26 pm    Post subject: Email server: how do I filter messages sent by me? Reply with quote

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
View user's profile Send private message
szatox
Advocate
Advocate


Joined: 27 Aug 2013
Posts: 3432

PostPosted: Sat Feb 17, 2018 8:23 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Other Things Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
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