add some filters for ebay orders
This commit is contained in:
160
liam/sieve.nix
160
liam/sieve.nix
@@ -2,6 +2,7 @@
|
||||
pkgs,
|
||||
lib,
|
||||
config,
|
||||
vaculib,
|
||||
...
|
||||
}:
|
||||
let
|
||||
@@ -141,6 +142,55 @@ let
|
||||
else
|
||||
assert "dunno what to do with this";
|
||||
null;
|
||||
is_flagish =
|
||||
flag_name:
|
||||
let
|
||||
# escape_all = map lib.escapeRegex;
|
||||
|
||||
# all from https://datatracker.ietf.org/doc/html/rfc9051#name-formal-syntax
|
||||
# resp-specials = escape_all [ "]" ];
|
||||
# DQUOTE = ''"'';
|
||||
# quoted-specials = escape_all [ DQUOTE "\\" ];
|
||||
# list-wildcards = escape_all [ "%" "*" ];
|
||||
# CTL = something; # 0x00 thru 0x1F, and 0x7F
|
||||
# SP = escape_all [ " " ];
|
||||
# atom-specials = (escape_all [ "(" ")" "{" ]) ++ [ SP CTL list-wildcards quoted-specials resp-specials ];
|
||||
# " " 0x20 !allowed
|
||||
# "!" 0x21 ok
|
||||
# "\"" 0x22 !allowed
|
||||
# "#" 0x23 ok
|
||||
# "$" 0x24 ok
|
||||
# "%" 0x25 !allowed
|
||||
# "&" 0x26 ok
|
||||
# "'" 0x27 ok
|
||||
# "(" 0x28 !allowed
|
||||
# ")" 0x29 !allowed
|
||||
# "*" 0x2a !allowed
|
||||
# "+" 0x2b ok
|
||||
# ...
|
||||
# "Z" 0x5a ok
|
||||
# "[" 0x5b !allowed
|
||||
# "\\" 0x5c !allowed
|
||||
# "]" 0x5d ok
|
||||
# ...
|
||||
# "z" 0x7a ok
|
||||
# "{" 0x7b !allowed
|
||||
# "|" 0x7c ok
|
||||
# "}" 0x7d ok
|
||||
# "~" 0x7e ok
|
||||
# DEL 0x7f !allowed
|
||||
# ATOM-CHAR = something; # "any CHAR except atom-specials"
|
||||
ATOM-CHAR = ''[!#$&'+-Z\]-z|}~]'';
|
||||
atom = "${ATOM-CHAR}+";
|
||||
flag-keyword = ''\$MDNSent|\$Forwarded|\$Junk|\$NotJunk|\$Phishing|(${atom})'';
|
||||
flag-extension = ''\\(${atom})'';
|
||||
flag = ''\\Answered|\\Flagged|\\Deleted|\\Seen|\\Draft|(${flag-keyword})|(${flag-extension})'';
|
||||
in
|
||||
(isString flag_name) && ((builtins.match flag flag_name) != null);
|
||||
known_flags = rec {
|
||||
seen = ''\Seen'';
|
||||
read = seen;
|
||||
};
|
||||
pure_flags_impl =
|
||||
flags: conditions:
|
||||
assert isListWhere flags isString;
|
||||
@@ -209,6 +259,11 @@ let
|
||||
''string :is "''${${var_name}}" ${sieve_encode rhs}'';
|
||||
var_is_true = var_name: var_is var_name "1";
|
||||
var_is_false = var_name: not (var_is_true var_name);
|
||||
has_flag =
|
||||
flag_name:
|
||||
assert isString flag_name;
|
||||
assert is_flagish flag_name; #no spaces allowed in flag names
|
||||
''hasflag :is ${sieve_encode flag_name};'';
|
||||
set_with_interp =
|
||||
var_name: new_val:
|
||||
assert isString var_name;
|
||||
@@ -297,6 +352,32 @@ let
|
||||
debug_log ${sieve_quote_string_with_interp msg};
|
||||
}
|
||||
'';
|
||||
# trimmed down from https://pages.ebay.com/securitycenter/security_researchers_eligible_domains.html
|
||||
ebay_domains = vaculib.listOfLines {} ''
|
||||
ebay.com
|
||||
ebay.co.uk
|
||||
ebay.com.au
|
||||
ebay.de
|
||||
ebay.ca
|
||||
ebay.fr
|
||||
ebay.it
|
||||
ebay.es
|
||||
ebay.at
|
||||
ebay.ch
|
||||
ebay.com.hk
|
||||
ebay.com.sg
|
||||
ebay.com.my
|
||||
ebay.in
|
||||
ebay.ph
|
||||
ebay.ie
|
||||
ebay.pl
|
||||
ebay.be
|
||||
ebay.nl
|
||||
ebay.cn
|
||||
ebay.com.tw
|
||||
ebay.co.jp
|
||||
ebaythailand.co.th
|
||||
'';
|
||||
sieve_text = ''
|
||||
require [
|
||||
"fileinto",
|
||||
@@ -374,6 +455,7 @@ let
|
||||
if ${var_is "userfor" "shelvacu"} {
|
||||
addheader "X-Vacu-Sieved" "''${sieved_message}";
|
||||
removeflag "not-spamish";
|
||||
removeflag "orders";
|
||||
removeflag "A";
|
||||
removeflag "B";
|
||||
removeflag "C";
|
||||
@@ -420,13 +502,29 @@ let
|
||||
${pure_flags "bloomberg" (envelope_is "bloomberg@shelvacu.com")}
|
||||
|
||||
${pure_flags
|
||||
[ "money-stuff" "not-spamish" "B" ]
|
||||
[ "money-stuff" "not-spamish" ]
|
||||
[
|
||||
(envelope_is "bloomberg@shelvacu.com")
|
||||
''header :matches "From" "\"Matt Levine\" *"''
|
||||
]
|
||||
}
|
||||
|
||||
${pure_flags
|
||||
[ "money-stuff-podcast" "D" known_flags.read ]
|
||||
[
|
||||
(has_flag "money-stuff")
|
||||
(subject_matches "Money Stuff: The Podcast:*")
|
||||
]
|
||||
}
|
||||
|
||||
${pure_flags
|
||||
[ "money-stuff-not-podcast" "B" ]
|
||||
[
|
||||
(has_flag "money-stuff")
|
||||
(not (has_flag "money-stuff-podcast"))
|
||||
]
|
||||
}
|
||||
|
||||
${pure_flags [ "git" "not-spamish" "B" ] (exists [
|
||||
"X-GitHub-Reason"
|
||||
"X-GitLab-Project"
|
||||
@@ -456,17 +554,63 @@ let
|
||||
}
|
||||
|
||||
${pure_flags "gmail-fwd" (envelope_is "gmailfwd-fc2e10bec8b2@shelvacu.com")}
|
||||
${pure_flags [ "aliexpress-delivered" "B" ] (allof [
|
||||
(from_is "transaction@notice.aliexpress.com")
|
||||
(header_matches "Subject" "Order * has been signed for")
|
||||
])}
|
||||
${pure_flags [ "aliexpress" "C" ] (allof [
|
||||
${pure_flags [ "ebay" "orders" ] (envelope_is "ebay@shelvacu.com")}
|
||||
${pure_flags [ "ebay-delivered" "B" ] [
|
||||
(has_flag "ebay")
|
||||
(header_matches "Subject" "ORDER DELIVERED:*")
|
||||
]}
|
||||
${pure_flags [ "ebay-message" "A" ] [
|
||||
(has_flag "ebay")
|
||||
(from_matches (map (domain: "*@members.${domain}") ebay_domains))
|
||||
]}
|
||||
${pure_flags [ "ebay-offer" "B" ] [
|
||||
(has_flag "ebay")
|
||||
(header_matches "Subject" [
|
||||
"You have an offer from the seller, *"
|
||||
"You saw it at *, but the seller is now offering *"
|
||||
])
|
||||
]}
|
||||
${pure_flags [ "ebay-order-update" "C" ] [
|
||||
(has_flag "ebay")
|
||||
(header_matches "Subject" [
|
||||
"Out for delivery: *"
|
||||
"DELIVERY UPDATE: *"
|
||||
"Order update: *"
|
||||
"Important information regarding your Global Shipping Program transaction *" #ebay: "important information! your order is being shipped." why did you say this was ""important""???
|
||||
"Your package is now with *"
|
||||
"Order confirmed: *"
|
||||
"Your order is confirmed"
|
||||
"Your order is in!"
|
||||
])
|
||||
]}
|
||||
${pure_flags [ "ebay-bid-ongoing-notification" "C" ] [
|
||||
(has_flag "ebay")
|
||||
(header_matches "Subject" "Michael, your bid for * is winning")
|
||||
]}
|
||||
${pure_flags [ "royal-mail" "orders" ] (from_is "no-reply@royalmail.com")}
|
||||
${pure_flags [ "royal-mail-delivered" "B" ] [
|
||||
(has_flag "royal-mail")
|
||||
(header_matches "Subject" "Your Royal Mail parcel has been delivered")
|
||||
]}
|
||||
${pure_flags [ "royal-mail-on-the-way" "D" ] [
|
||||
(has_flag "royal-mail")
|
||||
(header_matches "Subject" "Your Royal Mail parcel is on its way")
|
||||
]}
|
||||
${pure_flags [ "aliexpress" "orders" ]
|
||||
(from_is [
|
||||
"transaction@notice.aliexpress.com"
|
||||
"aliexpress@notice.aliexpress.com"
|
||||
])
|
||||
''not hasflag "aliexpress-delivered"''
|
||||
])}
|
||||
}
|
||||
${pure_flags [ "aliexpress-delivered" "B" ] [
|
||||
(has_flag "aliexpress")
|
||||
(from_is "transaction@notice.aliexpress.com")
|
||||
(header_matches "Subject" "Order * has been signed for")
|
||||
]}
|
||||
${pure_flags [ "aliexpress" "orders" "C" ] [
|
||||
(has_flag "aliexpress")
|
||||
(not (has_flag "aliexpress-delivered"))
|
||||
]}
|
||||
${pure_flags [ "brandcrowd" "D" ] (envelope_is "brandcrowd@shelvacu.com")}
|
||||
${pure_flags [ "cpapsupplies" "D" ] (envelope_is "cpapsupplies@shelvacu.com")}
|
||||
${pure_flags [ "genshin" "D" ] (envelope_is "genshin@shelvacu.com")}
|
||||
|
Reference in New Issue
Block a user