Skip to content

[fix] Improve Sieve “Complex filtering with variables” example to correctly handle From header parsing #492

@D0LLYNH0

Description

@D0LLYNH0

The Sieve script example (Complex filtering with variables) can be improved.

As it stands, depending on the From header, the result may not be what was intended.

Current example:

require ["variables", "fileinto", "regex"];

if header :regex "From" "(.+)@example\\.com" {
    set :lower "sender" "${1}";
    fileinto "Contacts/${sender}";
}
From: "John Doe" <john.doe@example.com>
filing message into 'Contacts/"john doe" <john.doe'

Suggestion:

require ["variables", "fileinto", "regex"];

if address :all :regex "From" "(.+)@example\\.com$" {
    set :lower "sender" "${1}";
    fileinto "Contacts/${sender}";
}
From: "John Doe" <john.doe@example.com>
filing message into 'Contacts/john.doe'

Using regex here might be overkill; matches could be more appropriate (although regex still works well as an example).


require ["variables", "fileinto", "mailbox"];

if address :all :matches "From" "*@example.com" {
    set :lower :upperfirst "sender" "${1}";
    fileinto :create "Contacts/${sender}";
}
From: "John Doe" <john.doe@example.com>
filing message into 'Contacts/John.doe'

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions