summaryrefslogtreecommitdiff
path: root/imap-tool
diff options
context:
space:
mode:
authorPaul Kocialkowski2023-04-12 11:41:32 +0200
committerPaul Kocialkowski2023-04-12 11:41:32 +0200
commitbf86d948b6df8eec6c330464c1e9da78c7d74dbd (patch)
tree0bab6d8cad67f5336c0ae496fc922e6b0ddfde4e /imap-tool
parent3e543994ebe66e69f35d19b847232201648e33ba (diff)
imap-tool: Add SSL support
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Diffstat (limited to 'imap-tool')
-rwxr-xr-ximap-tool20
1 files changed, 17 insertions, 3 deletions
diff --git a/imap-tool b/imap-tool
index 0089d87..ecb3f02 100755
--- a/imap-tool
+++ b/imap-tool
@@ -22,6 +22,7 @@ class imap_tool():
port = 143
user = "user"
password = "password"
+ ssl = False
action = imap_action.MAILBOX_LIST
usage = "Usage: " + os.path.basename(sys.argv[0]) + " [options] [actions]\n" \
@@ -31,6 +32,7 @@ class imap_tool():
" -u [user]\n" \
" -p [password]\n" \
" -i [port]\n" \
+ " -s\n" \
"\n" \
"Actions:\n" \
" mailbox-list\n" \
@@ -47,8 +49,16 @@ class imap_tool():
def act(self):
print("Connecting to " + self.host)
- imap = imaplib2.IMAP4(host = self.host, port = self.port)
- imap.starttls()
+ if self.ssl:
+ imap = imaplib2.IMAP4_SSL(host = self.host, port = self.port)
+ else:
+ imap = imaplib2.IMAP4(host = self.host, port = self.port)
+
+ if "STARTTLS" not in imap.capabilities:
+ print("Unable to create a secure TLS connection")
+ return 1
+
+ imap.starttls()
print("Authenticating with user " + self.user)
@@ -106,8 +116,10 @@ class imap_tool():
imap.logout()
+ return 0
+
def main(self):
- options, arguments = getopt.getopt(sys.argv[1:], "h:u:p:i:")
+ options, arguments = getopt.getopt(sys.argv[1:], "h:u:p:i:s")
for key, value in options:
if key == "-h":
@@ -118,6 +130,8 @@ class imap_tool():
self.password = value
elif key == "-i":
self.port = int(value)
+ elif key == "-s":
+ self.ssl = True
if len(arguments) == 0:
print(self.usage)