'Regex match time from "Received" e-mail header
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?
Solution 1:[1]
(?: ... ) 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"];
Solution 2:[2]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Community |
| Solution 2 | ernix |
