forked from getmail6/getmail6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetmails
executable file
·91 lines (87 loc) · 2.01 KB
/
getmails
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/sh
# vim:se tw=78 sts=4:
# Copyright (C) 2011-2017 Osamu Aoki <[email protected]>, GPL2+
: '
Run getmail in parallel for all config files.
Since getmail6 v6.18, if no --rcfile <file>,
getmail itself fetches using all config files, but serially.
'
set -e
if [ "$1" = "-p" ]; then
para=true
shift
elif [ "$1" = "--" ]; then
para=false
shift
else
para=false
fi
# check file extension
endwith () {
[ "$1" != "${1%$2}" ] && return 0 || return 1
}
startswith () {
BASE1=${1##*/}
[ "$BASE1" != "${BASE1#$2}" ] && return 0 || return 1
}
isrc() {
! endwith "$1" '~' && \
! endwith "$1" '#' && \
! startswith "$1" 'oldmail-' && \
! startswith "$1" '.' && \
! endwith "$1" '.json' && \
! endwith "$1" '.swp' && \
! endwith "$1" '.bak' && \
[ -f "$1" ] && return 0 || return 1;
}
UID_BY_ID=$(id -u)
PID_GETMAILS=$(pgrep -U $UID_BY_ID '^getmails$')
if [ "x$PID_GETMAILS" != "x$$" ]; then
echo "The getmails script is already running as PID=\"$PID_GETMAILS\" ." >&2
exit 1
fi
configdir=${XDG_CONFIG_HOME:-$HOME/.config}
if [ ! -d "$configdir" ]; then
getmailrcdir="$HOME/.getmail/config"
else
getmailrcdir="$configdir/getmail"
fi
if [ -f $getmailrcdir/stop ]; then
#note: stop needs to be in the config folder now
echo "Do not run getmail ... (if not, remove $getmailrcdir/stop)" >&2
exit 1
fi
rcfiles="getmail"
# Address concerns raised by #863856
# emacs backup files: foo~ foo#
# vim backup files: foo~ foo.swp
# generic backup files: foo.bak
# These are excluded but let's allow file names with @
if $para ; then
pids=""
for file in $getmailrcdir/* ; do
if isrc $file ; then
$rcfiles --rcfile "$file" "$@" &
pids="$pids $!"
fi
done
rc=0
if [ -n "$pids" ]; then
for pid in $pids ; do
wait $pid
prc=$?
if [ $prc -gt $rc ]; then
rc=$prc
fi
done
fi
exit $rc
else
for file in $getmailrcdir/* ; do
if isrc $file ; then
rcfiles="$rcfiles --rcfile \"$file\""
fi
done
eval "$rcfiles $@"
exit $?
fi