about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--config/config.go69
-rw-r--r--doc/aerc-config.5.scd13
-rw-r--r--doc/aerc-imap.5.scd10
-rw-r--r--doc/aerc-smtp.5.scd10
4 files changed, 94 insertions, 8 deletions
diff --git a/config/config.go b/config/config.go
index aef796c..d864d2c 100644
--- a/config/config.go
+++ b/config/config.go
@@ -3,7 +3,9 @@ package config
 import (
 	"errors"
 	"fmt"
+	"net/url"
 	"os"
+	"os/exec"
 	"path"
 	"regexp"
 	"strings"
@@ -29,14 +31,16 @@ const (
 )
 
 type AccountConfig struct {
-	CopyTo   string
-	Default  string
-	From     string
-	Name     string
-	Source   string
-	Folders  []string
-	Params   map[string]string
-	Outgoing string
+	CopyTo          string
+	Default         string
+	From            string
+	Name            string
+	Source          string
+	SourceCredCmd   string
+	Folders         []string
+	Params          map[string]string
+	Outgoing        string
+	OutgoingCredCmd string
 }
 
 type BindingConfig struct {
@@ -115,8 +119,12 @@ func loadAccountConfig(path string) ([]AccountConfig, error) {
 		for key, val := range sec.KeysHash() {
 			if key == "folders" {
 				account.Folders = strings.Split(val, ",")
+			} else if key == "source_cred_cmd" {
+				account.SourceCredCmd = val
 			} else if key == "outgoing" {
 				account.Outgoing = val
+			} else if key == "outgoing_cred_cmd" {
+				account.OutgoingCredCmd = val
 			} else if key == "from" {
 				account.From = val
 			} else if key == "copy-to" {
@@ -128,6 +136,19 @@ func loadAccountConfig(path string) ([]AccountConfig, error) {
 		if account.Source == "" {
 			return nil, fmt.Errorf("Expected source for account %s", _sec)
 		}
+
+		source, err := parseCredential(account.Source, account.SourceCredCmd)
+		if err != nil {
+			return nil, fmt.Errorf("Invalid source credentials for %s: %s", _sec, err)
+		}
+		account.Source = source
+
+		outgoing, err := parseCredential(account.Outgoing, account.OutgoingCredCmd)
+		if err != nil {
+			return nil, fmt.Errorf("Invalid outgoing credentials for %s: %s", _sec, err)
+		}
+		account.Outgoing = outgoing
+
 		accounts = append(accounts, account)
 	}
 	if len(accounts) == 0 {
@@ -137,6 +158,38 @@ func loadAccountConfig(path string) ([]AccountConfig, error) {
 	return accounts, nil
 }
 
+func parseCredential(cred, command string) (string, error) {
+	if cred == "" || command == "" {
+		return cred, nil
+	}
+
+	u, err := url.Parse(cred)
+	if err != nil {
+		return "", err
+	}
+
+	// ignore the command if a password is specified
+	if _, exists := u.User.Password(); exists {
+		return cred, nil
+	}
+
+	// don't attempt to parse the command if the url is a path (ie /usr/bin/sendmail)
+	if !u.IsAbs() {
+		return cred, nil
+	}
+
+	cmd := exec.Command("sh", "-c", command)
+	output, err := cmd.Output()
+	if err != nil {
+		return "", fmt.Errorf("failed to read password: %s", err)
+	}
+
+	pw := strings.TrimSpace(string(output))
+	u.User = url.UserPassword(u.User.Username(), pw)
+
+	return u.String(), nil
+}
+
 func LoadConfig(root *string) (*AercConfig, error) {
 	if root == nil {
 		_root := path.Join(xdg.ConfigHome(), "aerc")
diff --git a/doc/aerc-config.5.scd b/doc/aerc-config.5.scd
index a221723..ecf7720 100644
--- a/doc/aerc-config.5.scd
+++ b/doc/aerc-config.5.scd
@@ -144,6 +144,12 @@ Note that many of these configuration options are written for you, such as
 
 	- *aerc-smtp*(5)
 
+*outgoing_cred_cmd*
+    Specifies an optional command that is run to get the outgoing account's
+    password. See each protocol's man page for more details:
+
+    - *aerc-smtp*(5)
+
 *source*
 	Specifies the source for reading incoming emails on this account. This key
 	is required for all accounts. It should be a connection string, and the
@@ -154,6 +160,13 @@ Note that many of these configuration options are written for you, such as
 
 	Default: none
 
+*source_cred_cmd*
+    Specifies an optional command that is run to get the source account's
+    password. See each protocol's man page for more details:
+
+    - *aerc-imap*(5)
+
+
 # BINDS.CONF
 
 This file is used for configuring keybindings used in the aerc interactive
diff --git a/doc/aerc-imap.5.scd b/doc/aerc-imap.5.scd
index 5899a34..d676c7c 100644
--- a/doc/aerc-imap.5.scd
+++ b/doc/aerc-imap.5.scd
@@ -35,6 +35,16 @@ available:
 	*imaps*:
 		IMAP with TLS/SSL
 
+*source_cred_cmd*
+    Specifies the command to run to get the password for the IMAP
+    account. This command will be run using `sh -c [command]`. If a
+    password is specified in the *source* option, the password will
+    take precedence over this command.
+
+    Example:
+
+    `pass hostname/username`
+
 # SEE ALSO
 
 *aerc*(1) *aerc-config*(5) *aerc-smtp*(5)
diff --git a/doc/aerc-smtp.5.scd b/doc/aerc-smtp.5.scd
index 7d07125..17eb627 100644
--- a/doc/aerc-smtp.5.scd
+++ b/doc/aerc-smtp.5.scd
@@ -39,6 +39,16 @@ available:
 		Authenticate with a username and password using AUTH PLAIN. This is the
 		default behavior.
 
+*outgoing_cred_cmd*
+    Specifies the command to run to get the password for the SMTP
+    account. This command will be run using `sh -c [command]`. If a
+    password is specified in the *outgoing* option, the password will
+    take precedence over this command.
+
+    Example:
+
+    `pass hostname/username`
+
 # SEE ALSO
 
 *aerc*(1) *aerc-config*(5) *aerc-smtp*(5)
c6ed6de161e40aa256c3fc0f2b1f7cf9'>672e3e50 ^
e5c11a51 ^
a654e4ec ^
204dae92 ^



201458e3 ^
204dae92 ^








201458e3 ^
204dae92 ^














2c678a4e ^
c0f84b1f ^
204dae92 ^

c0f84b1f ^
204dae92 ^





2c678a4e ^
4a48bedc ^



104e521c ^
805d58c6 ^
4a48bedc ^





c0f84b1f ^
805d58c6 ^





104e521c ^
805d58c6 ^


104e521c ^
805d58c6 ^






4a48bedc ^

805d58c6 ^
104e521c ^
805d58c6 ^




4a48bedc ^











1a4de9dd ^
4a48bedc ^


























c0f84b1f ^
4a48bedc ^


5fe060d5 ^




















104e521c ^
5fe060d5 ^


104e521c ^
5fe060d5 ^








































672e3e50 ^


a654e4ec ^
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259