-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmail_to_self
executable file
·51 lines (42 loc) · 978 Bytes
/
mail_to_self
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
#!/bin/bash
help() {
echo 'usage: echo "mail text" | mail_to_self SUBJECT'
echo ' mail_to_self SUBJECT TEXT'
echo ' mail_to_self --help'
echo
echo ' deliver email to local mbox of user that is'
echo ' executing this script'
echo
echo ' Requires the dmail executable from the'
echo ' alpine/pine mailutils'
echo
exit 1
}
[ "$1" == "--help" ] && help
set -e # stop on error
set -o pipefail # stop part of pipeline failing
set -u # stop on undefined variable
local_user=`id -u --name`
if [ "$1" == "" ]; then
echo "ERROR: you must set a subject"
exit 2
else
subject="$1"
fi
if [ -v 2 ]; then # if TEXT parameter was given
pass_on_stdin=false
text="$2"
else
pass_on_stdin=true
fi
(
echo "From: $local_user"
echo "To: $local_user"
echo "Subject: $subject"
echo
if [ "$pass_on_stdin" == "false" ]; then
echo "$text"
else
cat # pass on STDIN
fi
) | dmail $local_user