summaryrefslogtreecommitdiff
path: root/git-credential-kwallet-mailtransports
blob: a1b9045f117e1ac06f151144302de60b693a0f6c (plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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