Fixed IMAP SEARCH BEFORE command

This commit is contained in:
mdecimus
2023-12-31 10:17:29 +01:00
parent 2f58638df6
commit b36d2dbf78
5 changed files with 29 additions and 6 deletions

View File

@@ -3,6 +3,8 @@ import socket
import time
import threading
from email.message import Message
from email.utils import formatdate
from datetime import datetime, timedelta
def append_message(thread_id, start, end):
conn = imaplib.IMAP4('localhost')
@@ -10,15 +12,20 @@ def append_message(thread_id, start, end):
conn.socket().setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
start_time = time.time()
base_date = datetime(2000, 1, 1)
for n in range(start, end):
current_date = base_date + timedelta(hours=n)
msg = Message()
msg['From'] = 'somebody@some.where'
msg['To'] = 'john@example.org'
msg['Message-Id'] = f'unique.message.id.{n}@nowhere'
msg['Date'] = formatdate(time.mktime(current_date.timetuple()), localtime=False, usegmt=True)
msg['Subject'] = f"This is message #{n}"
msg.set_payload('...nothing...')
response_code, response_details = conn.append('INBOX', '', None, str(msg).encode('utf-8'))
response_code, response_details = conn.append('INBOX', '', imaplib.Time2Internaldate(time.mktime(current_date.timetuple())), str(msg).encode('utf-8'))
if response_code != 'OK':
print(f'Thread {thread_id}: Error while appending message #{n}: {response_code} {response_details}')
break