From 7867923e113c53472ffc9acbc55b80d167103161 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Mon, 28 Oct 2013 10:59:59 +0100 Subject: git-credential-kwallet-mailtransports: git helper Useful for using git-send-email without storing typing the long passwords all the time. --- git-credential-kwallet-mailtransports | 75 +++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100755 git-credential-kwallet-mailtransports diff --git a/git-credential-kwallet-mailtransports b/git-credential-kwallet-mailtransports new file mode 100755 index 0000000..a1b9045 --- /dev/null +++ b/git-credential-kwallet-mailtransports @@ -0,0 +1,75 @@ +#!/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 -- cgit v1.2.1