mirror of https://github.com/deuill/dotfiles.git
Update mail-sync configuration for latest versions
This commit is contained in:
parent
269bc7424d
commit
c525bf356d
|
@ -8,6 +8,10 @@ BACKEND=""
|
|||
FULLNAME=""
|
||||
USERNAME=""
|
||||
|
||||
# Static password or command-line used for fetching password. Use one.
|
||||
# PASSWORD=""
|
||||
PASSWORD_COMMAND=""
|
||||
|
||||
# IMAP and SMTP server hostnames.
|
||||
# Gmail accounts generally do not need to set these.
|
||||
IMAP_HOSTNAME=""
|
||||
|
|
|
@ -15,4 +15,4 @@ NOTMUCH_CONFIG="${NOTMUCH_CONFDIR}/config"
|
|||
TRANSIENT_TAGS="draft|flagged|passed|replied|unread|attachment|signed|encrypted|unread|not-notified|new"
|
||||
|
||||
# Command for checking connectivity status.
|
||||
NETWORK_CONNECTED="[[ $(nmcli -t -f state general) = 'connected' ]]"
|
||||
NETWORK_CONNECTED="true"
|
||||
|
|
|
@ -1,18 +1,16 @@
|
|||
# Configuration file for mbsync.
|
||||
#
|
||||
# This file is a template for generic IMAP servers, and can be
|
||||
# used with mbsync with the following example command:
|
||||
# This file is a template for generic IMAP servers, and can be used with mbsync with the following
|
||||
# example command:
|
||||
#
|
||||
# mbsync <user> -c <(USERNAME=<user> HOSTNAME=<host> envsubst < <conf>)
|
||||
# mbsync <user> -c <(USERNAME=<user> PASSWORD=<pass> HOSTNAME=<host> envsubst < <conf>)
|
||||
#
|
||||
# Where <user> is something like "[email protected]" and host is something
|
||||
# like "mail.test.com". This is assuming that a password is set for
|
||||
# the above name in the `mail.sync.user <user>` key in Gnome-Keyring.
|
||||
# Where <user> is something like "[email protected]" and host is something like "mail.test.com".
|
||||
|
||||
IMAPAccount ${USERNAME}
|
||||
Host ${HOSTNAME}
|
||||
User ${USERNAME}
|
||||
PassCmd "secret-tool lookup mail.sync.user ${USERNAME}"
|
||||
Pass ${PASSWORD}
|
||||
SSLType IMAPS
|
||||
CertificateFile /etc/ssl/certs/ca-certificates.crt
|
||||
|
||||
|
@ -25,10 +23,9 @@ Path ${MAIL_DATADIR}/${USERNAME}/
|
|||
Inbox ${MAIL_DATADIR}/${USERNAME}/Inbox
|
||||
|
||||
Channel imap-default
|
||||
Master :imap-remote:
|
||||
Slave :imap-local:
|
||||
Far :imap-remote:
|
||||
Near :imap-local:
|
||||
Patterns * INBOX
|
||||
|
||||
Create Both
|
||||
Sync Pull Push New ReNew Flags
|
||||
SyncState *
|
||||
|
|
|
@ -1,18 +1,16 @@
|
|||
# Configuration file for mbsync.
|
||||
#
|
||||
# This file is a template for Gmail-based accounts, and can be used with
|
||||
# mbsync with the following example command:
|
||||
# This file is a template for Gmail-based accounts, and can be used with mbsync with the following
|
||||
# example command:
|
||||
#
|
||||
# mbsync <user> -c <(USERNAME=<user> envsubst < <conf>)
|
||||
# mbsync <user> -c <(USERNAME=<user> PASSWORD=<pass> envsubst < <conf>)
|
||||
#
|
||||
# Where <user> is something like "[email protected]". This is assuming that a
|
||||
# password is set for the above name in the `mail.sync.user <user>` key
|
||||
# in Gnome-Keyring.
|
||||
# Where <user> is something like "[email protected]".
|
||||
|
||||
IMAPAccount ${USERNAME}
|
||||
Host imap.gmail.com
|
||||
User ${USERNAME}
|
||||
PassCmd "secret-tool lookup mail.sync.user ${USERNAME}"
|
||||
Pass ${PASSWORD}
|
||||
SSLType IMAPS
|
||||
CertificateFile /etc/ssl/certs/ca-certificates.crt
|
||||
|
||||
|
@ -24,34 +22,33 @@ Path ${MAIL_DATADIR}/${USERNAME}/
|
|||
Inbox ${MAIL_DATADIR}/${USERNAME}/Inbox
|
||||
|
||||
Channel gmail-default
|
||||
Master :gmail-remote:
|
||||
Slave :gmail-local:
|
||||
Far :gmail-remote:
|
||||
Near :gmail-local:
|
||||
Patterns * INBOX !Drafts !Sent !Important !Spam !Trash !"[Gmail]/*"
|
||||
|
||||
Channel gmail-drafts
|
||||
Master :gmail-remote:"[Gmail]/Drafts"
|
||||
Slave :gmail-local:Drafts
|
||||
|
||||
Channel gmail-sent
|
||||
Master :gmail-remote:"[Gmail]/Sent Mail"
|
||||
Slave :gmail-local:Sent
|
||||
|
||||
Channel gmail-important
|
||||
Master :gmail-remote:"[Gmail]/Important"
|
||||
Slave :gmail-local:Important
|
||||
|
||||
Channel gmail-spam
|
||||
Master :gmail-remote:"[Gmail]/Spam"
|
||||
Slave :gmail-local:Spam
|
||||
|
||||
Channel gmail-trash
|
||||
Master :gmail-remote:"[Gmail]/Trash"
|
||||
Slave :gmail-local:Trash
|
||||
|
||||
Create Both
|
||||
Sync Pull Push New ReNew Flags
|
||||
SyncState *
|
||||
|
||||
Channel gmail-drafts
|
||||
Far :gmail-remote:"[Gmail]/Drafts"
|
||||
Near :gmail-local:Drafts
|
||||
|
||||
Channel gmail-sent
|
||||
Far :gmail-remote:"[Gmail]/Sent Mail"
|
||||
Near :gmail-local:Sent
|
||||
|
||||
Channel gmail-important
|
||||
Far :gmail-remote:"[Gmail]/Important"
|
||||
Near :gmail-local:Important
|
||||
|
||||
Channel gmail-spam
|
||||
Far :gmail-remote:"[Gmail]/Spam"
|
||||
Near :gmail-local:Spam
|
||||
|
||||
Channel gmail-trash
|
||||
Far :gmail-remote:"[Gmail]/Trash"
|
||||
Near :gmail-local:Trash
|
||||
|
||||
Group ${USERNAME}
|
||||
Channel gmail-default
|
||||
Channel gmail-drafts
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
# Configuration file for msmtp.
|
||||
#
|
||||
# This file is a template for generic SMTP servers, and can be
|
||||
# used with msmtp with the following example command:
|
||||
# This file is a template for generic SMTP servers, and can be used with msmtp with the following
|
||||
# example command:
|
||||
#
|
||||
# msmtp -C <(USERNAME=<user> HOSTNAME=<host> envsubst < <conf>)
|
||||
# msmtp -C <(USERNAME=<user> PASSWORD=<pass> HOSTNAME=<host> envsubst < <conf>)
|
||||
#
|
||||
# Where <user> is something like "[email protected]" and host is something
|
||||
# like "mail.test.com". This is assuming that a password is set for
|
||||
# the above name in the `mail.sync.user <user>` key in Gnome-Keyring.
|
||||
# Where <user> is something like "[email protected]" and host is something like "mail.test.com".
|
||||
|
||||
defaults
|
||||
auth on
|
||||
|
@ -15,11 +13,11 @@ tls on
|
|||
tls_trust_file /etc/ssl/certs/ca-certificates.crt
|
||||
logfile ${MAIL_DATADIR}/msmtp.log
|
||||
|
||||
account ${USERNAME}
|
||||
host ${HOSTNAME}
|
||||
port 587
|
||||
from ${USERNAME}
|
||||
user ${USERNAME}
|
||||
passwordeval "secret-tool lookup mail.sync.user ${USERNAME}; echo"
|
||||
account ${USERNAME}
|
||||
host ${HOSTNAME}
|
||||
port 587
|
||||
from ${USERNAME}
|
||||
user ${USERNAME}
|
||||
password ${PASSWORD}
|
||||
|
||||
account default: ${USERNAME}
|
||||
account default: ${USERNAME}
|
||||
|
|
|
@ -1,13 +1,11 @@
|
|||
# Configuration file for msmtp.
|
||||
#
|
||||
# This file is a template for Gmail servers, and can be used with
|
||||
# msmtp with the following example command:
|
||||
# This file is a template for Gmail servers, and can be used with msmtp with the following example
|
||||
# command:
|
||||
#
|
||||
# msmtp -C <(USERNAME=<user> HOSTNAME=<host> envsubst < <conf>)
|
||||
# msmtp -C <(USERNAME=<user> PASSWORD=<pass> HOSTNAME=<host> envsubst < <conf>)
|
||||
#
|
||||
# Where <user> is something like "[email protected]", assuming that a
|
||||
# password is set for the above name in the `mail.sync.user <user>`
|
||||
# key in Gnome-Keyring.
|
||||
# Where <user> is something like "[email protected]".
|
||||
|
||||
defaults
|
||||
auth on
|
||||
|
@ -15,11 +13,11 @@ tls on
|
|||
tls_trust_file /etc/ssl/certs/ca-certificates.crt
|
||||
logfile ${MAIL_DATADIR}/msmtp.log
|
||||
|
||||
account ${USERNAME}
|
||||
host smtp.gmail.com
|
||||
port 587
|
||||
from ${USERNAME}
|
||||
user ${USERNAME}
|
||||
passwordeval "secret-tool lookup mail.sync.user ${USERNAME}; echo"
|
||||
account ${USERNAME}
|
||||
host smtp.gmail.com
|
||||
port 587
|
||||
from ${USERNAME}
|
||||
user ${USERNAME}
|
||||
password ${PASSWORD}
|
||||
|
||||
account default: ${USERNAME}
|
||||
account default: ${USERNAME}
|
||||
|
|
|
@ -17,6 +17,11 @@ function fetch() {
|
|||
export USERNAME="$2"
|
||||
export HOSTNAME="$3"
|
||||
|
||||
if [[ -z "${PASSWORD:-}" && -n "${PASSWORD_COMMAND}" ]]
|
||||
then
|
||||
export PASSWORD=$(bash -c "${PASSWORD_COMMAND}")
|
||||
fi
|
||||
|
||||
# Synchronize and index mail from IMAP server.
|
||||
fetch-pre-hook "${USERNAME}"
|
||||
mbsync -c <(envsubst < "${MBSYNC_CONFDIR}/${type}.conf") "${USERNAME}"
|
||||
|
@ -31,6 +36,11 @@ function send() {
|
|||
export USERNAME="$2"
|
||||
export HOSTNAME="$3"
|
||||
|
||||
if [[ -z "${PASSWORD:-}" && -n "${PASSWORD_COMMAND}" ]]
|
||||
then
|
||||
export PASSWORD=$(bash -c "${PASSWORD_COMMAND}")
|
||||
fi
|
||||
|
||||
# Add message to the queue.
|
||||
local queuedir="${MAIL_DATADIR}/${USERNAME}/.queue"
|
||||
local basename=$(date +%Y-%m-%d-%H.%M.%S)
|
||||
|
@ -38,40 +48,32 @@ function send() {
|
|||
mkdir -p "${queuedir}"
|
||||
cat > "${queuedir}/${basename}.mail"
|
||||
|
||||
# Abort process if we're not online.
|
||||
# Abort process if we cannot contact mail server.
|
||||
${NETWORK_CONNECTED} || return 0
|
||||
|
||||
# Send all queued email.
|
||||
for mail in "${queuedir}"/*.mail
|
||||
do
|
||||
echo "Sending '${mail}..."
|
||||
|
||||
msmtp -C <(envsubst < "${MSMTP_CONFDIR}/${type}.conf") -t < "${mail}"
|
||||
[[ $? -ne 0 ]] && return 1
|
||||
|
||||
msmtp -C <(envsubst < "${MSMTP_CONFDIR}/${type}.conf") -t < "${mail}" || return 1
|
||||
rm "${mail}"
|
||||
done
|
||||
}
|
||||
|
||||
# Setup account configuration for `notmuch`, `mbsync`, `msmtp` etc.
|
||||
# Setup account configuration for notmuch, mbsync, msmtp etc.
|
||||
function account-setup() {
|
||||
local account="$1"
|
||||
|
||||
# Create or load user configuration.
|
||||
# Create or load default user configuration.
|
||||
if [[ ! -e "${MAIL_CONFDIR}/account.d/${account}.conf" ]]
|
||||
then
|
||||
mkdir -p "${MAIL_CONFDIR}/account.d"
|
||||
cp "${MAIL_CONFDIR}/account.conf.template" "${MAIL_CONFDIR}/account.d/${account}.conf"
|
||||
|
||||
read -r -p "Press enter to edit user configuration for '${account}': "
|
||||
${EDITOR:=vi} "${MAIL_CONFDIR}/account.d/${account}.conf"
|
||||
|
||||
echo "Please enter password for '${account}': "
|
||||
secret-tool store --label "mail-sync ${account}" mail.sync.user "${account}"
|
||||
else
|
||||
echo "Using existing configuration file for '${account}'..."
|
||||
fi
|
||||
|
||||
read -r -p "Press enter to edit user configuration for '${account}': "
|
||||
${EDITOR:=vi} "${MAIL_CONFDIR}/account.d/${account}.conf"
|
||||
|
||||
load-account-config "${account}" || return 1
|
||||
account-setup-post-hook "${account}"
|
||||
|
||||
|
@ -82,10 +84,14 @@ function account-setup() {
|
|||
function account-exists() {
|
||||
local account="$1"
|
||||
|
||||
if [[ ! -e "${MAIL_CONFDIR}/account.d/${account}.conf" ]]
|
||||
if [[ -z "${account}" ]]
|
||||
then
|
||||
echo "No account name provided, aborting."
|
||||
return 1
|
||||
elif [[ ! -e "${MAIL_CONFDIR}/account.d/${account}.conf" ]]
|
||||
then
|
||||
echo "Configuration for account '${account}' not found."
|
||||
echo "Did you intend to run 'add' instead?"
|
||||
echo "Did you intend to run 'setup' instead?"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
@ -155,16 +161,6 @@ function main() {
|
|||
local action="${1:-}"
|
||||
local account="${2:-}"
|
||||
|
||||
# Check for valid command name.
|
||||
[[ -z "${action}" ]] && usage
|
||||
|
||||
# Check for account name parameter.
|
||||
if [[ -z "${account}" ]]
|
||||
then
|
||||
echo "Error: Please specify an account name to fetch from."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
load-global-config && lock
|
||||
|
||||
case "${action}" in
|
||||
|
@ -177,6 +173,12 @@ function main() {
|
|||
send "${TYPE}" "${USERNAME}" "${SMTP_HOSTNAME}"
|
||||
;;
|
||||
setup)
|
||||
if [[ -z "${account}" ]]
|
||||
then
|
||||
echo "Error: Please specify an account name to setup."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
account-setup "${account}"
|
||||
;;
|
||||
*)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
# Mu integration with mail-sync.
|
||||
|
||||
function fetch-pre-hook() {
|
||||
return true
|
||||
return 0
|
||||
}
|
||||
|
||||
function fetch-post-hook() {
|
||||
|
@ -12,5 +12,5 @@ function fetch-post-hook() {
|
|||
}
|
||||
|
||||
function account-setup-post-hook() {
|
||||
return true
|
||||
return 0
|
||||
}
|
||||
|
|
|
@ -163,6 +163,7 @@ function fetch-post-hook() {
|
|||
${NOTMUCH} tag -"notified" tag:"${account}" AND tag:"inbox" AND tag:"not-notified"
|
||||
}
|
||||
|
||||
# Set up configuration and initialize database for Notmuch.
|
||||
function account-setup-post-hook() {
|
||||
if [[ ! -e "${NOTMUCH_CONFDIR}/config" ]]
|
||||
then
|
||||
|
@ -174,5 +175,5 @@ function account-setup-post-hook() {
|
|||
echo "${tmp}" > "${NOTMUCH_CONFDIR}/config"
|
||||
fi
|
||||
|
||||
${NOTMUCH} new &> /dev/null
|
||||
${NOTMUCH} new
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue