#!/bin/bash mtcnf=$HOME/.kde4/share/config/mailtransports walletname=mailtransports warn() { echo "${0##*/}: $1" >&2 } action=$1 case $action in get|store|erase) ;; *) warn "Unknown action $action" exit 1 esac while IFS== read key val; do case $key in protocol) protocol=$val ;; host) host=$val ;; path) # ignoring path ;; username) username=$val ;; password) password=$val ;; url) warn "URLs are not parsed" ;; *) warn "Ignoring unrecognized key $key" ;; esac done if [[ $protocol != smtp ]]; then warn "Only smtp protocol is supported" exit 1 fi transportid= while read tid; do cfguser=$(kreadconfig --file "$mtcnf" --group "Transport $tid" --key user) if [[ $cfguser == $username ]]; then transportid=$tid break fi done < <(grep -Po '^\[Transport \K[0-9]+' "$mtcnf") if [ -z "$transportid" ]; then warn "Mailtransport not found" exit 1 fi case $action in get) password=$(kwalletcli -f "$walletname" -e "$transportid" 2>/dev/null) if [ $? -ne 0 ]; then warn "Cannot retrieve password" exit 1 fi echo "password=$password" ;; store|erase) warn "Ignored action $action" ;; esac