emailbase64sieve-algorithm

Why does Sieve behave strangely on a base64 subject line?


I'm trying to get the message filtered by Sieve by the subject line:

Subject: =?utf-8?B?0K3Qu9C10LrRgtGA0L7QvdC90YvQuSDRh9C10Log0L/QviDQ?=
 =?utf-8?B?t9Cw0LrQsNC30YMgMTY5MzQwMTktMDA4Ng==?=

This filter does get the message discarded:

if header :contains "Subject" "0"
{
    discard;
}

but this one (or anything more complex) does not:

if header :contains "Subject" "L"
{
    discard;
}

How come Sieve thinks the subject line contains 0 but not L? Is there something fundamental I'm missing about Sieve and base64?


Solution

  • Sieve scripts will decode Subject header into actual human-readable string before test them. So your code tests 0/L against Электронный чек по заказу 16934019-0086, not =?utf-8?B?...?=. (Strictly speaking, the subject text breaks on the wrong place though)

    RFC5703 2.4.2.2

    Interpretation of header data SHOULD be done according to [MIME3] section 6.2 (see section 2.7.2 below for details).

    [MIME3] Moore, K., "MIME (Multipurpose Internet Mail Extensions) Part Three: Message Header Extensions for Non-ASCII Text", RFC 2047, November 1996.