feat: support mailing-list and monthly mail capture paths
This commit is contained in:
1 parent
543814cbd6
commit
1a451023f0
7 files changed
+165
-5
No files matched your search
@@ -9,6 +9,39 @@ import unittest
|
||||
m=runpy.run_path(str(Path(__file__).with_name('pages')))
|
||||
|
||||
class ProductivityTests(unittest.TestCase):
|
||||
def test_mail_path_priority_and_dates(self):
|
||||
import datetime,hashlib
|
||||
ident='06cb3a24-61f8-4a9f-a0bf-89eea9632f25'
|
||||
suffix=m['task_mail_suffix'];now=datetime.datetime(2030,2,1,tzinfo=datetime.timezone.utc)
|
||||
for marker in ('[hogehoge 00123]','Re: [hogehoge:123]','Fwd: [hogehoge#123]'):
|
||||
raw=('Subject: '+marker+' Title\r\n\r\nbody').encode()
|
||||
self.assertEqual(suffix(raw,ident,now),'hogehoge/123')
|
||||
raw=b'Subject: Plain\r\nDate: Sat, 31 Jan 2026 23:30:00 -0800\r\nMessage-ID: <id@example.invalid>\r\n\r\nbody'
|
||||
self.assertEqual(suffix(raw,ident,now),'2026/01/'+ident)
|
||||
noid=raw.replace(b'Message-ID: <id@example.invalid>\r\n',b'')
|
||||
self.assertEqual(suffix(noid,ident,now),'2026/01/'+hashlib.sha256(noid).hexdigest())
|
||||
for date in (b'',b'Date: broken\r\n'):
|
||||
raw=b'Subject: [../unsafe 123] Title\r\n'+date+b'\r\nbody'
|
||||
self.assertEqual(suffix(raw,ident,now),'2030/02/'+hashlib.sha256(raw).hexdigest())
|
||||
|
||||
def test_pending_mail_month_and_options_are_preserved(self):
|
||||
from unittest.mock import patch
|
||||
raw=b'Subject: Test\r\nMessage-ID: <same@example.invalid>\r\n\r\nbody'
|
||||
calls=[]
|
||||
def send(route,**kw):
|
||||
calls.append(kw['data'].copy())
|
||||
raise m['Failure']('offline')
|
||||
client=SimpleNamespace(base='https://example.invalid',json=send)
|
||||
profile=SimpleNamespace(data={'username':'test'},save=lambda:None)
|
||||
for month in ('2030/01','2030/02'):
|
||||
with patch.dict(m['tasks'].__globals__,task_mail_suffix=lambda raw,ident:month+'/'+ident),patch('sys.stdin',SimpleNamespace(buffer=io.BytesIO(raw))),contextlib.redirect_stderr(io.StringIO()),self.assertRaises(m['Failure']):
|
||||
m['tasks'](client,profile,['from-mail'])
|
||||
self.assertEqual(calls[0],calls[1])
|
||||
with patch('sys.stdin',SimpleNamespace(buffer=io.BytesIO(raw))),self.assertRaises(m['Failure']):
|
||||
m['tasks'](client,profile,['from-mail','--wiki-prefix','/changed'])
|
||||
self.assertEqual(len(calls),2)
|
||||
self.assertEqual(next(iter(profile.data['task_outbox'].values())),calls[0])
|
||||
|
||||
def test_mail_privacy_and_long_subject_override(self):
|
||||
raw=b'Subject: Test\r\nFrom: Person <person@example.invalid>\r\nMessage-ID: <id@example.invalid>\r\nContent-Type: text/plain; charset=utf-8\r\n\r\nPRIVATE BODY'
|
||||
title,notes,ident,body=m['task_mail'](raw)
|
||||
|
||||
Reference in new issue
Block a user