mailcow / mailcow-dockerized

mailcow: dockerized - 🐮 + 🐋 = 💕
https://mailcow.email
GNU General Public License v3.0
8.25k stars 1.12k forks source link

. as additional mail extension #5130

Open RogerSik opened 1 year ago

RogerSik commented 1 year ago

Summary

Currently it is possible to use + as mail extension.

Example jon+vacation@example.org

It would be nice, if we could extend it with dot. Because there sadly still sites which dont allow to use +. So it is possible to use the dot as workaround for these websites.

Example jon.vacation@example.org

GMail allows something similar: https://support.google.com/mail/answer/7436150?hl=en

Motivation

Some sites dont allow + as extension. So its possible to use . as a "workaround". The + extensions helps to filter easily the emails.

Additional context

No response

master2die commented 1 year ago

I agree with you that such an option in the UI would certainly not be wrong. Maybe you can create satisfaction for yourself by using filters.

Example:

# Rewrite dots in local part to +
require ["variables", "regex"];

if header :contains "To" "." {
    # Extract addresses from the To field
    extract :matches :raw "$To" "([^<,> ]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})" "addresses";

    # Search for addresses and replace dots in local part
    foreach :var "address" :in "addresses" {
        set "localpart" "${1}";
        set "domainpart" "${2}";

        if string :matches "${localpart}" "*.*" {
            set "new_localpart" "${localpart//./+}";
            set "new_address" "${new_localpart}@${domainpart}";
            replace :header "To" "${address}" "${new_address}";
        }
    }
}

After the filter is enabled, all emails sent to addresses with a dot in the local part will be automatically rewritten by replacing the dot with a plus sign. For example, the address "abc.def@example.org" will be rewritten to "abc+def@example.org". Addresses without a dot in the local part will remain unchanged, for example, "abcdef@abc.example.org" will not be changed to "abcdef@abc+example.org".

Please remember to make sure the Dovecot server is functioning properly after making changes to the filter, and that all emails are properly delivered since my code snippet is not tested properly.

RogerSik commented 9 months ago

Many thanks and sorry for answering soo late. @master2die

Where i would put this filter? In the mailcow backend under filter?

Because in the backend I get the error "line 5: unknown command extract"

25_15-37-36