summarylogtreecommitdiffstats
path: root/0001-Added-passwordeval-option-and-documentation.patch
blob: 6080dbde55525522e5f7b9f098af66737d246ff1 (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
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
From e81910097884e05a58da38e277b581ea3a073da9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Esa=20M=C3=A4=C3=A4tt=C3=A4?= <esa.maatta_at_iki.fi>
Date: Mon, 7 May 2012 20:02:23 +0300
Subject: [PATCH 1/1] Added passwordeval option and documentation.

Removes need for plain text password in the getmailrc file. Instead of "password"
option "passwordeval" option can be used.

For example:

passwordeval = gpg -d gmail.gpg

The value of the "passwordeval" option is run and the output is used as the
password. If password cannot be found from the output, then password is prompted
from the user.
---
 docs/configuration.html   | 22 ++++++++++++++++++++--
 docs/getmailrc-examples   | 34 ++++++++++++++++++++++++----------
 getmailcore/retrievers.py | 11 +++++++++++
 getmailcore/utilities.py  | 24 +++++++++++++++++++++++-
 4 files changed, 78 insertions(+), 13 deletions(-)

diff --git a/docs/configuration.html b/docs/configuration.html
index 0508ddf..f48ab27 100644
--- a/docs/configuration.html
+++ b/docs/configuration.html
@@ -548,8 +548,9 @@ type = <span class="meta">typename</span>
         password
         (<a href="#parameter-string">string</a>)
         &mdash; password to use when logging in to the mail server.  If not
-        using Kerberos authentication -- see below -- getmail gets the password
-        credential for the POP/IMAP server in one of the following ways:
+        using Kerberos authentication or passwordeval option -- see below --
+        getmail gets the password credential for the POP/IMAP server in one of
+        the following ways:
         <ol>
             <li>from the <span class="file">password</span> configuration item in the getmailrc file</li>
             <li>on Mac OS X only, from the OS X keychain</li>
@@ -569,6 +570,12 @@ type = <span class="meta">typename</span>
         via the keychain.  See <a href="http://article.gmane.org/gmane.mail.getmail.user/5120">this
         posting to the getmail users' mailing list by Alan Schmitt</a> for details.
     </li>
+    <li>
+        passwordeval
+        (<a href="#parameter-string">string</a>)
+        &mdash; command which output is used as the password. This can be used
+        instead of the password option.
+    </li>
 </ul>
 <p>
     All IMAP retriever types also take the following optional parameters:
@@ -1248,6 +1255,17 @@ password = my_mail_password
 </pre>
 
 <p>
+    A typical POP3 mail account with password in gpg encrypted file.
+</p>
+<pre class="example">
+[retriever]
+type = SimplePOP3Retriever
+server = popmail.isp.example.net
+username = account_name
+passwordeval = gpg -d ~/.popmail.isp.example.net.gpg
+</pre>
+
+<p>
     If your ISP provides POP3 access on a non-standard port number, you would
     need to include the port parameter:
 </p>
diff --git a/docs/getmailrc-examples b/docs/getmailrc-examples
index dc8da2d..3d98ce8 100644
--- a/docs/getmailrc-examples
+++ b/docs/getmailrc-examples
@@ -22,8 +22,22 @@ password = mailpassword
 type = Maildir
 path = ~jeffp/Maildir/
 
+# Example 2:  same as (1), but evaluate password using external command. In this
+# case gpg.
 #
-# Example 2:  same as (1), but operate quietly, delete messages from
+
+[retriever]
+type = SimplePOP3Retriever
+server = pop.example.net
+username = jeff.plotzky
+passwordeval = gpg -d ~/.pop.example.net.gpg
+
+[destination]
+type = Maildir
+path = ~jeffp/Maildir/
+
+#
+# Example 3:  same as (1), but operate quietly, delete messages from
 # the server after retrieving them, and log getmail's actions (in detail)
 # to a file.
 #
@@ -45,7 +59,7 @@ type = Maildir
 path = ~jeffp/Maildir/
 
 #
-# Example 3: same as (1), but the mail account is accessed via IMAP4 instead
+# Example 4: same as (1), but the mail account is accessed via IMAP4 instead
 # of POP3.
 #
 
@@ -60,7 +74,7 @@ type = Maildir
 path = ~jeffp/Maildir/
 
 #
-# Example 4: same as (3), but retrieve mail from the INBOX, INBOX.spam, and
+# Example 5: same as (4), but retrieve mail from the INBOX, INBOX.spam, and
 # mailing-lists.getmail-users mail folders.
 #
 
@@ -76,7 +90,7 @@ type = Maildir
 path = ~jeffp/Maildir/
 
 #
-# Example 5: same as (3), but move messages to the mail folder "sent-mail"
+# Example 6: same as (4), but move messages to the mail folder "sent-mail"
 # after retrieving them.  Note that you do this by setting delete and
 # move_on_delete options.
 #
@@ -96,7 +110,7 @@ type = Maildir
 path = ~jeffp/Maildir/
 
 #
-# Example 6:  same as (1), but deliver the messages to an mboxrd-format mbox
+# Example 7:  same as (1), but deliver the messages to an mboxrd-format mbox
 # file as user "jeffp".
 #
 
@@ -112,7 +126,7 @@ path = ~jeffp/Mail/inbox
 user = jeffp
 
 #
-# Example 7:  same as (1), but deliver the messages through an external MDA
+# Example 8:  same as (1), but deliver the messages through an external MDA
 # which takes several arguments.
 #
 
@@ -129,7 +143,7 @@ arguments = ("--message-from-stdin", "--scan-message", "--to-maildir",
   "~jeffp/Maildir/")
 
 #
-# Example 8:  retrieve mail from a corporate POP3-SSL domain mailbox,
+# Example 9:  retrieve mail from a corporate POP3-SSL domain mailbox,
 # sort messages for several local users and deliver to maildirs in their
 # home directories (except Sam, who likes mbox files, and Christina, who
 # uses procmail for further sorting), and deliver all other mail to
@@ -187,7 +201,7 @@ arguments = ("-f", "%(sender)", "-m", "/home/christina/.procmailrc")
 user = christina
 
 #
-# Example 9: same as (3), but use SpamAssassin to filter out spam,
+# Example 10: same as (4), but use SpamAssassin to filter out spam,
 # and ClamAV to filter out MS worms.
 #
 
@@ -213,7 +227,7 @@ type = Maildir
 path = ~jeffp/Maildir/
 
 #
-# Example 10: same as (3), but deliver all mail to two different local
+# Example 11: same as (4), but deliver all mail to two different local
 # mailboxes.
 #
 
@@ -231,7 +245,7 @@ destinations = (
     )
 
 #
-# Example 11:  retrieve mail from a simple (non-multidrop) POP3 mailbox.
+# Example 12:  retrieve mail from a simple (non-multidrop) POP3 mailbox.
 # Then extract addresses from the message header (see documentation for which
 # fields are examined), and deliver mail containing the address
 # <list1@domain.example.net> to ~/Mail/lists/list1/, mail containing the
diff --git a/getmailcore/retrievers.py b/getmailcore/retrievers.py
index 6e82df7..351dade 100755
--- a/getmailcore/retrievers.py
+++ b/getmailcore/retrievers.py
@@ -62,6 +62,7 @@ class SimplePOP3Retriever(POP3RetrieverBase, POP3initMixIn):
         ConfInt(name='port', required=False, default=110),
         ConfString(name='username'),
         ConfPassword(name='password', required=False, default=None),
+        ConfString(name='passwordeval', required=False, default=None),
         ConfBool(name='use_apop', required=False, default=False),
         ConfBool(name='delete_dup_msgids', required=False, default=False),
     )
@@ -95,6 +96,7 @@ class SimplePOP3SSLRetriever(POP3RetrieverBase, POP3SSLinitMixIn):
         ConfInt(name='port', required=False, default=POP3_ssl_port),
         ConfString(name='username'),
         ConfPassword(name='password', required=False, default=None),
+        ConfString(name='passwordeval', required=False, default=None),
         ConfBool(name='use_apop', required=False, default=False),
         ConfBool(name='delete_dup_msgids', required=False, default=False),
         ConfFile(name='keyfile', required=False, default=None),
@@ -171,6 +173,7 @@ class BrokenUIDLPOP3Retriever(BrokenUIDLPOP3RetrieverBase, POP3initMixIn):
         ConfInt(name='port', required=False, default=110),
         ConfString(name='username'),
         ConfPassword(name='password', required=False, default=None),
+        ConfString(name='passwordeval', required=False, default=None),
         ConfBool(name='use_apop', required=False, default=False),
     )
     received_with = 'POP3'
@@ -201,6 +204,7 @@ class BrokenUIDLPOP3SSLRetriever(BrokenUIDLPOP3RetrieverBase, POP3SSLinitMixIn):
         ConfInt(name='port', required=False, default=POP3_ssl_port),
         ConfString(name='username'),
         ConfPassword(name='password', required=False, default=None),
+        ConfString(name='passwordeval', required=False, default=None),
         ConfBool(name='use_apop', required=False, default=False),
         ConfFile(name='keyfile', required=False, default=None),
         ConfFile(name='certfile', required=False, default=None),
@@ -237,6 +241,7 @@ class MultidropPOP3Retriever(MultidropPOP3RetrieverBase, POP3initMixIn):
         ConfInt(name='port', required=False, default=110),
         ConfString(name='username'),
         ConfPassword(name='password', required=False, default=None),
+        ConfString(name='passwordeval', required=False, default=None),
         ConfBool(name='use_apop', required=False, default=False),
         ConfString(name='envelope_recipient'),
     )
@@ -270,6 +275,7 @@ class MultidropPOP3SSLRetriever(MultidropPOP3RetrieverBase, POP3SSLinitMixIn):
         ConfInt(name='port', required=False, default=POP3_ssl_port),
         ConfString(name='username'),
         ConfPassword(name='password', required=False, default=None),
+        ConfString(name='passwordeval', required=False, default=None),
         ConfBool(name='use_apop', required=False, default=False),
         ConfString(name='envelope_recipient'),
         ConfFile(name='keyfile', required=False, default=None),
@@ -316,6 +322,7 @@ class MultidropSDPSRetriever(SimplePOP3Retriever, POP3initMixIn):
         ConfInt(name='port', required=False, default=110),
         ConfString(name='username'),
         ConfPassword(name='password', required=False, default=None),
+        ConfString(name='passwordeval', required=False, default=None),
         # Demon apparently doesn't support APOP
         ConfBool(name='use_apop', required=False, default=False),
     )
@@ -368,6 +375,7 @@ class SimpleIMAPRetriever(IMAPRetrieverBase, IMAPinitMixIn):
         ConfInt(name='port', required=False, default=imaplib.IMAP4_PORT),
         ConfString(name='username'),
         ConfPassword(name='password', required=False, default=None),
+        ConfString(name='passwordeval', required=False, default=None),
         ConfTupleOfUnicode(name='mailboxes', required=False,
                            default="('INBOX', )", allow_specials=('ALL',)),
         ConfBool(name='use_peek', required=False, default=True),
@@ -409,6 +417,7 @@ class SimpleIMAPSSLRetriever(IMAPRetrieverBase, IMAPSSLinitMixIn):
         ConfInt(name='port', required=False, default=imaplib.IMAP4_SSL_PORT),
         ConfString(name='username'),
         ConfPassword(name='password', required=False, default=None),
+        ConfString(name='passwordeval', required=False, default=None),
         ConfTupleOfUnicode(name='mailboxes', required=False,
                            default="('INBOX', )", allow_specials=('ALL',)),
         ConfBool(name='use_peek', required=False, default=True),
@@ -454,6 +463,7 @@ class MultidropIMAPRetriever(MultidropIMAPRetrieverBase, IMAPinitMixIn):
         ConfInt(name='port', required=False, default=imaplib.IMAP4_PORT),
         ConfString(name='username'),
         ConfPassword(name='password', required=False, default=None),
+        ConfString(name='passwordeval', required=False, default=None),
         ConfTupleOfUnicode(name='mailboxes', required=False,
                            default="('INBOX', )", allow_specials=('ALL',)),
         ConfBool(name='use_peek', required=False, default=True),
@@ -496,6 +506,7 @@ class MultidropIMAPSSLRetriever(MultidropIMAPRetrieverBase, IMAPSSLinitMixIn):
         ConfInt(name='port', required=False, default=imaplib.IMAP4_SSL_PORT),
         ConfString(name='username'),
         ConfPassword(name='password', required=False, default=None),
+        ConfString(name='passwordeval', required=False, default=None),
         ConfTupleOfUnicode(name='mailboxes', required=False,
                            default="('INBOX', )", allow_specials=('ALL',)),
         ConfBool(name='use_peek', required=False, default=True),
diff --git a/getmailcore/utilities.py b/getmailcore/utilities.py
index 9ed6643..572be61 100755
--- a/getmailcore/utilities.py
+++ b/getmailcore/utilities.py
@@ -688,7 +688,29 @@ if keychain_password is None:
 
 #######################################
 def get_password(label, user, server, protocol, logger):
-    # try keychain/keyrings first, where available
+    # try passwordeval first
+    if label.conf['passwordeval']:
+        cmd = label.conf['passwordeval']
+        (status, output) = commands.getstatusoutput(cmd)
+        password = None
+        if status != os.EX_OK or not output:
+            emsg = 'passwordeval command "{}" failed: {} {}'.format(
+                    cmd, status, output)
+            # Add line separator if missing so that prompting for password is
+            # clearer
+            if emsg[-1] != os.linesep:
+                emsg += os.linesep
+            logger.error(emsg)
+        else:
+            # select last line as password from the output and remove any line
+            # separators from the end.
+            password = output.rstrip(os.linesep).rpartition(os.linesep)[2]
+        # if could not be evaluated, prompt in the usual way
+        if not password:
+            password = getpass.getpass('Enter password for %s:  ' % label)
+        return password
+
+    # try keychain/keyrings second, where available
     password = keychain_password(user, server, protocol, logger)
     if password:
         logger.debug('using password from keychain/keyring')
-- 
2.11.0