User Tools

Site Tools


software:cli:mail:filter

Introduction

Getting tired of managing tons of emails/email addresses ? I am too. So I decided to automatically sort this mega mess. I will use imapfilter as it looks easy to use/configure

Install

install imapfilter from the repositories of your distribution.

Confifguration

Create the imapfilter folder and the LUA config file:

mkdir -p ~/.imapfilter
vim ~/.imapfilter/config.lua

Edit it:

-- One of the work mailservers is slow.
-- -- The time in seconds for the program to wait for a mail server's response (default 60)
-- options.timeout = 120
 
-- According to the IMAP specification, when trying to write a message to a non-existent mailbox, the server must send a hint to the client, whether it should create the mailbox and try again or not. However some IMAP servers don't follow the specification and don't send the correct response code to the client. By enabling this option the client tries to create the mailbox, despite of the server's response. 
options.create = true
 
-- By enabling this option new mailboxes that were automatically created, get also subscribed; they are set active in order for IMAP clients to recognize them
options.subscribe = true
 
-- Normally, messages are marked for deletion and are actually deleted when the mailbox is closed. When this option is enabled, messages are expunged immediately after being marked deleted.
-- options.expunge = true
gmail1 = IMAP {
    server = "imap.gmail.com",
    username = "superaddress1@gmail.com",
    password = "M3g@P@ss",
    ssl = "tls1"
}
 
 
-- example filters
-- move calendar noification from my wife when read to a folder Events
print('moving Events')
events = gmail1.INBOX:contain_subject('New Event') + gmail1.INBOX:contain_subject('Updated Invitation:') + gmail1.INBOX:contain_subject('Canceled Event') * gmail1.INBOX:is_seen() *
       gmail1.INBOX:contain_from('mywife@gmail.com') *
       gmail1.INBOX:contain_to('myaddress@gmail.com')
events: mark_seen()
events:move_messages(gmail1['Events'])
-- google + messages ( useless, are on G+ && on the phone…)
print('Cleaning google+')
googleplus = gmail1.INBOX: contain_from('plus.google.com)') *
             gmail1.INBOX:contain_to('myaddress@gmail.com')
googleplus:delete_messages()

Once set, you can simply run:

 imapfilter

You can of course create more complex filters

references

software/cli/mail/filter.txt · Last modified: 2021/12/29 20:09 by warnaud