Tag Archives: regexp

Gmail like “+” adresses aliases in Postfix

Gmail logo

A few weeks ago I completely migrated from Gmail to my own e-mail solution (based on Postfix, Dovecot, RoundCube and some evil security layers). One of the important things about managing you own email server is saving your time. So when tweaking – you should do it simple and fast.

I really missed one simple trick from Gmail – those aliases created dynamically with the use of plus character (e.g. maciej+spam@lasyk.info – you’ll find more here: https://support.google.com/mail/answer/12096?hl=en).

Of course – one could simply create some aliases in /etc/aliases or even in virtual_maps for particular domains but we have to save our time and we should find some way that it could be done without our intervention anytime we’d like to create new alias.

It’s really simple. just use PCRE tables (or regex – whatever). I used PCRE (http://www.postfix.org/pcre_table.5.html) – and added just one line there:

As PCREs are greedy by default I used the lazy quantifier “?” before the ‘@’. And now I can enjoy what I used back in Gmail epoch ;)

Grep is Your friend

GREP stands for Global Regular Expression Print. I think that every sysop loves grep, grepping and anything that has something in common with grep – this tool makes our lives really easier ;) If You’re not convinced than I think You’re in a good place – maybe the following text will convince You :)

    1. Excluding irrelevant words: sometimes We have to grep for some word but We have to exclude some irrelevant string. E.g. let’s grep for ‘index.html’ but let’s also exclude ‘404’ from this:
    2. egrep (extended grep, same as grep -e or grep –regexp=) allows us to do more powerful search including regular expressions with metacharacters like +, ?, | and ()
    3. Counting results – If we just want to know the number of lines that matched our query – We would use:
    4. Case Insensitive search – by default grep is case sensitive, If we want to make case insensitive search than we use:
    5. Matching eXact word only – by default grepping for Word will return lines containing SomeWord and <strongwordbytheway< strong=””>. If We would like to find only those lines containing exact word Word We should use:

grep -w could be also useful here.

      1. Matching left and right side of the word – to search for instances of string matching Word in the end or start We use \< or \>:Below would match any word starting with access, like access_entry:

        Below would match any word ending with error, like general_error:
  1. Showing context results – sometimes We would like to grep for some errors in logs, but we also would like to view the context of that log entry – e.g. grepping for ‘Relay access denied‘ in Postfix logs to see If that error is occurring with some pattern:
  2. zgrep – this one would grep in the compressed gzip file – just like gunzip -c flog.gz | grep Word:
  3. Coloring matched words – We can highlight our matched words with some color (check man page to see how to set exact color):