Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

6 May, 2024: The networking issue during the past two days has been identified and appears to be fixed. Will keep monitoring.


devel / comp.lang.python / imaplib: is this really so unwieldy?

SubjectAuthor
o imaplib: is this really so unwieldy?hw

1
imaplib: is this really so unwieldy?

<mailman.328.1621931030.3087.python-list@python.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=13308&group=comp.lang.python#13308

  copy link   Newsgroups: comp.lang.python
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!not-for-mail
From: hw...@adminart.net (hw)
Newsgroups: comp.lang.python
Subject: imaplib: is this really so unwieldy?
Date: Tue, 25 May 2021 10:23:41 +0200
Lines: 48
Message-ID: <mailman.328.1621931030.3087.python-list@python.org>
References: <21fb6c5f-97a4-654b-887f-2c31a549bcbe@adminart.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.uni-berlin.de mhl7q5SZnimr6w4/oRQioA6VFkMJfnZLtIE7P6HO9UYQ==
Return-Path: <hw@adminart.net>
X-Original-To: python-list@python.org
Delivered-To: python-list@mail.python.org
Authentication-Results: mail.python.org; dkim=pass
reason="2048-bit key; unprotected key"
header.d=adminart.net header.i=@adminart.net header.b=kfTlR0id;
dkim-adsp=pass; dkim-atps=neutral
X-Spam-Status: OK 0.003
X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '(which': 0.04; 'exit':
0.07; 'wrong.': 0.07; 'apparently': 0.09; 'convert': 0.09;
'forced': 0.09; 'overhead': 0.09; "shouldn't": 0.09; 'which,':
0.09; 'import': 0.14; 'awkward': 0.16; 'bytes)': 0.16;
'expressions': 0.16; 'far,': 0.16; 'readonly': 0.16;
'received:(client did not present a certificate)': 0.16; 'uid':
0.16; 'to:addr:python-list': 0.23; 'received:de': 0.24; 'seems':
0.26; 'extract': 0.27; 'port': 0.27; 'wrong': 0.27; 'function':
0.28; 'header:User-Agent:1': 0.31; 'seem': 0.31; 'stuff': 0.31;
'but': 0.31; '(with': 0.31; 'expect': 0.31; "doesn't": 0.32;
"i'm": 0.32; 'program': 0.33; 'using': 0.33; 'server': 0.33;
'functions': 0.34; "it's": 0.38; 'use': 0.38; 'hi,': 0.39;
'messages': 0.40; 'skip:i 30': 0.60; 'numbers': 0.63;
'subject:this': 0.63; 'skip:# 10': 0.64; 'supposed': 0.77;
'strings': 0.84; 'subject:really': 0.84; 'weird': 0.84
ARC-Seal: i=1; a=rsa-sha256; t=1621931022; cv=none;
d=strato.com; s=strato-dkim-0002;
b=FkX3DGZeVu99MxTg7fkjwOvA/Jr6aB2RLhtZQdZ3S6FgExfJlgP2mIZEMpTL1OOXuL
DDvzJPkR23akUteIJdFaXBgy7hu2skKHq4HRI5T8xnSx9Jyt9CrXH37GcHtbx7Tn+QoU
5ViB04CdZvHctoOj/NIp0Km4IQz/Kh2vaJewUvQbFbAJrBTyWkNEBWi4xSR+r1CvF00z
EPmaCbe9Tun2SXkKtO1Px8AsViCRtthGBDkrcbkdswz2DDZhdpV835c1F3YnztSYlGOD
HMyGHnTOMyv4dtSrNRDvCo6LfiNe03cMzHWSkqPSA8HkM66uAlTu+9R1jbIQcViKWEiI
Vh8g==
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; t=1621931022;
s=strato-dkim-0002; d=strato.com;
h=Date:Message-ID:Subject:From:To:Cc:Date:From:Subject:Sender;
bh=zLEccEJcvzUrkNAf/qNKJMEx7PwQsDBuJtn7P7dO0Ik=;
b=GiJzmt4F0yVMPpIVR8l4uxE3Y9gkHV5Dsl1g09C+f2FjGHjbepBEiZah4TTL0K7Vag
vH4GmInpd0CuMwLVJ/gjkS4+QG7c38xo6a3sKmgNME3BcNeVU5zve3jUk6FyreB6zi5k
5dqbb0aQP7hNU86rR2yWxaJQ1eKlIGdzytcPSvan5/ztjUJvmGe3tnqxM/eHZrOtoSHy
yW6gxUknvrgzK4JXRKA2L6IHGg9JokKhShuJ9JqXwC3P32yE6+j7Mc8hsvwlCo0H7Bhd
aI+aDbKPmlFZex7vuPNPP6GQuJdouzpjefLLMArRBZktWAtAeKxTXyRIQXq0iaPRWzIR
+u1Q==
ARC-Authentication-Results: i=1; strato.com;
dkim=none
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1621931022;
s=strato-dkim-0002; d=adminart.net;
h=Date:Message-ID:Subject:From:To:Cc:Date:From:Subject:Sender;
bh=zLEccEJcvzUrkNAf/qNKJMEx7PwQsDBuJtn7P7dO0Ik=;
b=kfTlR0id0XtQ2VVrlDyvxLBjwuMoXJlgwrJ1SxGHF0y6x+ulyc37b0AzA6k/8UiNdX
WfhxEbtKQwe3WcaUcYQ+mz+xRXuZYvH9QfuLtUYvxkfzko0PZMAYzwMQZfMKGLuATHlB
UVlC1EyLh58VN7o8d2uhnYAZyJbtU++3YQyRmu4og3kFCYqcFA2or3cMpIOxXA7Ha2qM
AhoUJR+Y+8x8fHIfJbN09rh8uAJWgu8W8Mhv3HKFkoFEU5hX4r8HuwgTU1QboqHGflfu
Y+xFCEWaMCFVNRJK5vZDrvp2j/ogaKrhKXi188a5+NeQotMFpAu4SG+qTv7bIDXaIAdZ
23yA==
Authentication-Results: strato.com;
dkim=none
X-RZG-AUTH: ":O2kGeEG7b/pS1Ey9Rna9iAZFrfz26y6zbtmqiE/f0+LThi5xYO8s9RmVPkxvrwQpRPenk8HVxDf4aQ=="
X-RZG-CLASS-ID: mo00
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.10.1
Content-Language: de-DE
X-BeenThere: python-list@python.org
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: General discussion list for the Python programming language
<python-list.python.org>
List-Unsubscribe: <https://mail.python.org/mailman/options/python-list>,
<mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive: <https://mail.python.org/pipermail/python-list/>
List-Post: <mailto:python-list@python.org>
List-Help: <mailto:python-list-request@python.org?subject=help>
List-Subscribe: <https://mail.python.org/mailman/listinfo/python-list>,
<mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID: <21fb6c5f-97a4-654b-887f-2c31a549bcbe@adminart.net>
 by: hw - Tue, 25 May 2021 08:23 UTC

Hi,

I'm about to do stuff with emails on an IMAP server and wrote a program
using imaplib which, so far, gets the UIDs of the messages in the inbox:

#!/usr/bin/python

import imaplib
import re

imapsession = imaplib.IMAP4_SSL('imap.example.com', port = 993)

status, data = imapsession.login('user', 'password')
if status != 'OK':
print('Login failed')
exit

messages = imapsession.select(mailbox = 'INBOX', readonly = True)
typ, msgnums = imapsession.search(None, 'ALL')
message_uuids = []
for number in str(msgnums)[3:-2].split():
status, data = imapsession.fetch(number, '(UID)')
if status == 'OK':
match = re.match('.*\(UID (\d+)\)', str(data))
message_uuids.append(match.group(1))
for uid in message_uuids:
print('UID %5s' % uid)

imapsession.close()
imapsession.logout()

It's working (with Cyrus), but I have the feeling I'm doing it all wrong
because it seems so unwieldy. Apparently the functions of imaplib
return some kind of bytes while expecting strings as arguments, like
message numbers must be strings. The documentation doesn't seem to say
if message UIDs are supposed to be integers or strings.

So I'm forced to convert stuff from bytes to strings (which is weird
because bytes are bytes) and to use regular expressions to extract the
message-uids from what the functions return (which I shouldn't have to
because when I'm asking a function to give me a uid, I expect it to
return a uid).

This so totally awkward and unwieldy and involves so much overhead that
I must be doing this wrong. But am I? How would I do this right?

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor