|
|
@@ -75,70 +75,50 @@ shopt -s nullglob |
|
|
|
# Matchers |
|
|
|
|
|
|
|
# Subject |
|
|
|
function subject_contains { |
|
|
|
function subject { |
|
|
|
# Perl snippet from https://superuser.com/a/972248 |
|
|
|
|
|
|
|
get_header "$1" \ |
|
|
|
| grep "^Subject: " \ |
|
|
|
| perl -CS -MEncode -ne 'print decode("MIME-Header", $_)' \ |
|
|
|
| grep -q "^Subject: .*${2}.*" |
|
|
|
} |
|
|
|
|
|
|
|
function subject_is { |
|
|
|
# Perl snippet from https://superuser.com/a/972248 |
|
|
|
|
|
|
|
get_header "$1" \ |
|
|
|
| grep "^Subject: " \ |
|
|
|
| perl -CS -MEncode -ne 'print decode("MIME-Header", $_)' \ |
|
|
|
| grep -q "^Subject: ${2}\$" |
|
|
|
|
|
|
|
| grep "^Subject:" \ |
|
|
|
| grep -qP "$2" |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# From |
|
|
|
function from_contains { |
|
|
|
get_header "$1" | grep -qi "^From: .*${2}.*" |
|
|
|
} |
|
|
|
|
|
|
|
function from_is { |
|
|
|
get_header "$1" | grep -qi "^From: ${2}\$" |
|
|
|
|
|
|
|
function from { |
|
|
|
get_header "$1" | grep -i "^From:" | grep -qP "$2" |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# To |
|
|
|
function to_contains { |
|
|
|
get_header "$1" | grep -qi "^To: .*${2}.*" |
|
|
|
function to { |
|
|
|
get_header "$1" | grep -i "^To:" | grep -qP "$2" |
|
|
|
} |
|
|
|
|
|
|
|
function to_is { |
|
|
|
get_header "$1" | grep -qi "^To: ${2}\$" |
|
|
|
function cc { |
|
|
|
get_header "$1" | grep -i "^Cc:" | grep -qP "$2" |
|
|
|
} |
|
|
|
|
|
|
|
function bcc { |
|
|
|
get_header "$1" | grep -i "^Bcc:" | grep -qP "$2" |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Involves |
|
|
|
function involves_contains { |
|
|
|
from_contains $@ || to_contains $@ |
|
|
|
} |
|
|
|
|
|
|
|
function involves_is { |
|
|
|
from_is $@ || to_is $@ |
|
|
|
function involves { |
|
|
|
get_header "$1" | grep -i -e "^From:" -e "^To:" -e "^Cc:" -e "^Bcc:" | grep -qP "$2" |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Return-Path |
|
|
|
function return_path_contains { |
|
|
|
get_header "$1" | grep -qi "^Return-Path: .*${2}.*" |
|
|
|
} |
|
|
|
|
|
|
|
function return_path_is { |
|
|
|
get_header "$1" | grep -qi "^Return-Path: ${2}\$" |
|
|
|
|
|
|
|
function return_path { |
|
|
|
get_header "$1" | grep "^Return-Path:" | grep -qP "$2" |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@@ -156,17 +136,6 @@ shopt -s nullglob |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Flags |
|
|
|
function has_flag { |
|
|
|
echo "$1" | grep -q ":2,.*$2.*" |
|
|
|
} |
|
|
|
|
|
|
|
function has_no_flag { |
|
|
|
echo "$1" | grep -vq ":2,.*$2.*" |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ACTIONS |
|
|
|
|
|
|
|
function move { |
|
|
@@ -208,39 +177,13 @@ shopt -s nullglob |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function set_flag { |
|
|
|
echo " set_flag $@" |
|
|
|
echo " currently disabled." |
|
|
|
|
|
|
|
# if ! has_flag "$1" "$2"; then |
|
|
|
# mv "$1" "$1$2" |
|
|
|
# fi |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function clear_flag { |
|
|
|
echo " clear_flag $@" |
|
|
|
|
|
|
|
if has_flag "$1" "$2"; then |
|
|
|
local new=$(echo "$1" | sed "s_\(.*\:2,.*\)$2\(.*\)_\1\2_") |
|
|
|
mv "$1" "$new" |
|
|
|
fi |
|
|
|
} |
|
|
|
|
|
|
|
function noop { |
|
|
|
echo " noop $@" |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# INTERNAL |
|
|
|
|
|
|
|
function get_header { |
|
|
|
while IFS= read l; do |
|
|
|
test -z "$l" && break |
|
|
|
echo "$l" 2>/dev/null |
|
|
|
done <"$1" |
|
|
|
done <"$1" | sed ':a;$!N;s/\n[ \t][ \t]*/ /;ta;P;D' |
|
|
|
} |
|
|
|
|
|
|
|
function matchHelper { |