Automatically add addresses from email to your aliases file. Automatically refresh aliases on mail, bounce or forward.
This commit is contained in:
parent
1f0ebe4226
commit
b269d5ba89
@ -83,16 +83,36 @@ yesno() {
|
||||
|
||||
initialize_directory()
|
||||
{
|
||||
if ! [ -d "$muttHome" ]; then
|
||||
mkdir -p "${muttHome}/cache/bodies"
|
||||
fi
|
||||
mkdir -p "${muttHome}/cache/bodies"
|
||||
mkdir -p "${muttHome}/scripts"
|
||||
if ! [ -f "$muttHome/aliases" ]; then
|
||||
touch "$muttHome/aliases"
|
||||
fi
|
||||
# Create scripts
|
||||
if ! [ -f "$muttHome/scripts/add_address.sh" ]; then
|
||||
cat << EOF > "$muttHome/scripts/add_address.sh"
|
||||
#!/bin/bash
|
||||
|
||||
message="\$(cat)"
|
||||
|
||||
newAlias=\$(echo "\${message}" | grep "^From: " | sed 's/[\,\"\']//g' | awk '{\$1=""; if (NF == 3) {print "alias" \$0;} else if (NF == 2) {print "alias" \$0 \$0;} else if (NF > 3) {print "alias", tolower(\$2)"-"tolower(\$(NF-1)) \$0;}}')
|
||||
emailAddress="<\${newAlias##*<}"
|
||||
|
||||
if ! grep -Fq "\$emailAddress" "$muttHome/aliases" ; then
|
||||
echo "\$newAlias" >> "$muttHome/aliases"
|
||||
sort -u "$muttHome/aliases" -o "$muttHome/aliases"
|
||||
fi
|
||||
|
||||
echo "\${message}"
|
||||
|
||||
EOF
|
||||
fi
|
||||
# End of add_address script
|
||||
if ! [ -f "$muttHome/mailcap" ]; then
|
||||
# Find desired browser
|
||||
local x=0
|
||||
for i in\
|
||||
$BROWSER\
|
||||
chromium\
|
||||
elinks\
|
||||
epiphany\
|
||||
@ -157,13 +177,15 @@ initialize_directory()
|
||||
keyName="$(gpg --list-secret-keys --keyid-format short | grep -B1 ^uid | head -n1 | rev | cut -c -8 | rev)"
|
||||
echo "set pgp_sign_as=$keyName" >> "$muttHome/gpg.rc"
|
||||
fi
|
||||
# Create macro file
|
||||
if ! [ -f "$muttHome/macros" ]; then
|
||||
echo "macro index 'c' '<change-folder>?<change-dir><home>^K=<enter>'" > "$muttHome/macros"
|
||||
echo "bind index \"^\" imap-fetch-mail\"" >> "$muttHome/macros"
|
||||
echo "macro pager \cb <pipe-entry>'urlview'<enter> 'Follow links with urlview'" >> "$muttHome/macros"
|
||||
echo "macro attach 'B' \"<pipe-entry>cat >~/.cache/mutt/mail.html && $BROWSER ~/.cache/\"" >> "$muttHome/macros"
|
||||
fi
|
||||
# Create or update macro file
|
||||
echo "macro index 'c' '<change-folder>?<change-dir><home>^K=<enter>'" >> "$muttHome/macros"
|
||||
echo "bind index \"^\" imap-fetch-mail\"" >> "$muttHome/macros"
|
||||
echo "macro pager \cb <pipe-entry>'urlview'<enter> 'Follow links with urlview'" >> "$muttHome/macros"
|
||||
echo "macro attach 'B' \"<pipe-entry>cat >~/.cache/mutt/mail.html && $BROWSER ~/.cache/\"" >> "$muttHome/macros"
|
||||
echo "macro index,pager b '<enter-command>source $muttHome/aliases<enter><bounce-message>'" >> "$muttHome/macros"
|
||||
echo "macro index,pager f '<enter-command>source $muttHome/aliases<enter><forward-message>'" >> "$muttHome/macros"
|
||||
echo "macro index,pager m '<enter-command>source $muttHome/aliases<enter><mail>'" >> "$muttHome/macros"
|
||||
|
||||
# Create basic muttrc
|
||||
if ! [ -f "$muttHome/muttrc" ]; then
|
||||
# Find desired editor
|
||||
@ -204,6 +226,7 @@ initialize_directory()
|
||||
echo "set pager_stop = 'yes'" >> "$muttHome/muttrc"
|
||||
echo "set sort=threads" >> "$muttHome/muttrc"
|
||||
echo "set beep_new=yes" >> "$muttHome/muttrc"
|
||||
echo "set display_filter = '$muttHome/scripts/add_address.sh'" >> "$muttHome/muttrc"
|
||||
echo "set print=yes" >> "$muttHome/muttrc"
|
||||
echo "set imap_check_subscribed" >> "$muttHome/muttrc"
|
||||
echo "set sort_alias=alias" >> "$muttHome/muttrc"
|
||||
|
Loading…
x
Reference in New Issue
Block a user