2

I am trying to match header to set in a filter on roundcube. I have found another question about this and i tried the answers, but it doesn't work.

The regex works when tested in RegExr, but roundcube simply denies to save it.

This is my regex: \s*(?:Sun|Mon|Tue|Weds|Thu|Fri|Sat),\s*\d+\s+\w+\s+\d+\s+(?:0[12345678]|1[89]|2[0123]):\d\d:\d\d

Which i found in this answer, adjusted it to my needs: RegEx to match time in "Received: by" e-mail header

It should match times between: 18:00 - 09:00, which it does.

I am not a regex expert, so is there anyone out there that can help me with this?

Andy
  • 2,892
  • 2
  • 26
  • 33
  • `but roundcube simply denies to save it!` ... what is the exact error output? – Tim Biegeleisen Jul 26 '19 at 10:57
  • This is the error: https://imgur.com/a/yKPlEIK, it's not really clear what is wrong. Saving goes fine when i just enter some text, but not when i enter this regex. – Andy Jul 26 '19 at 11:02

2 Answers2

2

(?: ... ) is not valid in sieve. \s/\d/\w may not be either.

See: Sieve Email Filtering: Regular Expression Extension, POSIX ERE spec and other sieve documents.

Use normal groups and character classes:

[:space:]*(Sun|Mon|Tue|Weds|Thu|Fri|Sat),[:space:]*[:digit:]+[:space:]+[:alpha:]+[:space:]+[:digit:]+[:space:]+(0[12345678]|1[89]|2[0123]):[:digit:][:digit:]:[:digit:][:digit:]

(I replaced \w with [:alpha:] but this may not be what you want.)

Also, remember to require ["regex"];

Community
  • 1
  • 1
jhnc
  • 11,310
  • 1
  • 9
  • 26
0

You don't have to parse Received header by regex, Use date extension instead:

require "date";
require "relational";

if anyof (
    date :value "lt" "Received" "hour" "09",
    date :value "gt" "Received" "hour" "18"
) {
    # do something
}

or

require "date";
require "relational";

if anyof (
    currentdate :value "lt" "hour" "09",
    currentdate :value "gt" "hour" "18"
) {
    # do something
}

See rfc5260, it also mentions weekend.

ernix
  • 3,442
  • 1
  • 17
  • 23