-
Notifications
You must be signed in to change notification settings - Fork 2
/
install-signature.sh
executable file
·47 lines (37 loc) · 1.49 KB
/
install-signature.sh
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
#!/usr/bin/env bash
set -euo pipefail
signatureUniqueId="$(uuidgen)"
signaturesDirectory="$HOME/Library/Mobile Documents/com~apple~mail/Data/V4/Signatures"
allSignaturesPlist="$signaturesDirectory/AllSignatures.plist"
mailsignatureFile="$signaturesDirectory/$signatureUniqueId.mailsignature"
# Not using iCloud Drive.
if [ ! -f "$signaturesDirectory/AllSignatures.plist" ]; then
signaturesDirectory="$HOME/Library/Mail/V6/MailData/Signatures"
allSignaturesPlist="$signaturesDirectory/AllSignatures.plist"
mailsignatureFile="$signaturesDirectory/$signatureUniqueId.mailsignature"
fi
if [ ! -f "$allSignaturesPlist" ]; then
>&2 echo "Could not find $allSignaturesPlist."
exit 1
fi
if [ -t 0 ]; then
>&2 echo "stdin seems to be empty."
exit 1
fi
if [ -z "${1:-}" ]; then
>&2 echo "No signature name passed."
exit 1
fi
/usr/libexec/PlistBuddy -c "Add :0 dict" "$allSignaturesPlist"
/usr/libexec/PlistBuddy -c "Add :0:SignatureIsRich bool true" "$allSignaturesPlist"
/usr/libexec/PlistBuddy -c "Add :0:SignatureName string '$1'" "$allSignaturesPlist"
/usr/libexec/PlistBuddy -c "Add :0:SignatureUniqueId string '$signatureUniqueId'" "$allSignaturesPlist"
cat <<EOF > "$mailsignatureFile"
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
charset=utf-8
Message-Id: <$(uuidgen)>
Mime-Version: 1.0 (Mac OS X Mail 12.0 \(3445.100.39\))
EOF
cat | perl -MMIME::QuotedPrint -pe '$_=MIME::QuotedPrint::encode($_)' >> "$mailsignatureFile"
echo "Installed “$1” signature with ID $signatureUniqueId."