summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFolker Bernitt <fbernitt@thoughtworks.com>2015-05-11 12:09:04 +0200
committerFolker Bernitt <fbernitt@thoughtworks.com>2015-05-11 12:09:04 +0200
commit36b3c5beee77b4376cb910b80b0dfb7380f39bfe (patch)
treeb4543e5007152b4263eb3536811ba221d9464f0d
parent981e1efffb59762773ac7861729d98c0860ee64b (diff)
Use maildir for folders like DRAFTS or SENT.
- Issues #337, #338 - Added example how to use maildir sub folders
-rw-r--r--service/pixelated/maintenance.py10
-rw-r--r--service/test/mailsets/common/.DRAFTS/cur/mbox00000006:2,S31
-rw-r--r--service/test/mailsets/common/.DRAFTS/new/.keep0
-rw-r--r--service/test/mailsets/common/.DRAFTS/tmp/.keep0
-rw-r--r--service/test/mailsets/common/.SENT/cur/mbox00000007:2,S9
-rw-r--r--service/test/mailsets/common/.SENT/new/.keep0
-rw-r--r--service/test/mailsets/common/.SENT/tmp/.keep0
-rw-r--r--service/test/unit/maintenance/test_commands.py1
8 files changed, 47 insertions, 4 deletions
diff --git a/service/pixelated/maintenance.py b/service/pixelated/maintenance.py
index bfa78da8..167a844a 100644
--- a/service/pixelated/maintenance.py
+++ b/service/pixelated/maintenance.py
@@ -147,19 +147,25 @@ def delete_all_mails(args):
return args
+def is_keep_file(mail):
+ return mail['subject'] is None
+
+
def add_mail_folder(account, maildir, folder_name, deferreds):
if folder_name not in account.mailboxes:
account.addMailbox(folder_name)
mbx = account.getMailbox(folder_name)
for mail in maildir:
+ if is_keep_file(mail):
+ continue
+
flags = (WithMsgFields.RECENT_FLAG,) if mail.get_subdir() == 'new' else ()
if 'S' in mail.get_flags():
flags = (WithMsgFields.SEEN_FLAG,) + flags
if 'R' in mail.get_flags():
flags = (WithMsgFields.ANSWERED_FLAG,) + flags
- mail.set_payload(mail.get_payload() + '\n' + folder_name)
deferreds.append(mbx.addMessage(mail.as_string(), flags=flags, notify_on_disk=False))
@@ -173,8 +179,6 @@ def load_mails(args, mail_paths):
for path in mail_paths:
maildir = Maildir(path, factory=None)
add_mail_folder(account, maildir, 'INBOX', deferreds)
- add_mail_folder(account, maildir, 'DRAFTS', deferreds)
- add_mail_folder(account, maildir, 'SENT', deferreds)
for mail_folder_name in maildir.list_folders():
mail_folder = maildir.get_folder(mail_folder_name)
add_mail_folder(account, mail_folder, mail_folder_name, deferreds)
diff --git a/service/test/mailsets/common/.DRAFTS/cur/mbox00000006:2,S b/service/test/mailsets/common/.DRAFTS/cur/mbox00000006:2,S
new file mode 100644
index 00000000..2ec1bf23
--- /dev/null
+++ b/service/test/mailsets/common/.DRAFTS/cur/mbox00000006:2,S
@@ -0,0 +1,31 @@
+Subject: a draft in progess
+From: alice@try.pixelated-project.org
+To: someone@try.pixelated-project.org
+X-Pixelated-encryption-status: true
+Date: Tue, 22 Apr 2015 11:58:22 +0000 (UTC)
+
+ Hack placidly amidst the noisy printers and remember what prizes there
+may be in Science. As fast as possible get a good terminal on a good system.
+Enter your data clearly but always encrypt your results. And listen to others,
+even the dull and ignorant, for they may be your customers. Avoid loud and
+aggressive persons, for they are sales reps.
+ If you compare your outputs with those of others, you may be surprised,
+for always there will be greater and lesser numbers than you have crunched.
+Keep others interested in your career, and try not to fumble; it can be a real
+hassle and could change your fortunes in time.
+ Exercise system control in your experiments, for the world is full of
+bugs. But let this not blind you to what virtue there is; many persons strive
+for linearity and everywhere papers are full of approximations. Strive for
+proportionality. Especially, do not faint when it occurs. Neither be cyclical
+about results; for in the face of all data analysis it is sure to be noticed.
+ Take with a grain of salt the anomalous data points. Gracefully pass
+them on to the youth at the next desk. Nurture some mutual funds to shield
+you in times of sudden layoffs. But do not distress yourself with imaginings
+-- the real bugs are enough to screw you badly. Murphy's Law runs the
+Universe -- and whether or not it is clear to you, no doubt <Curl>B*n dS = 0.
+ Therefore, grab for a piece of the pie, with whatever proposals you
+can conceive of to try. With all the crashed disks, skewed data, and broken
+line printers, you can still have a beautiful secretary. Be linear. Strive
+to stay employed.
+ -- Technolorata, "Analog"
+
diff --git a/service/test/mailsets/common/.DRAFTS/new/.keep b/service/test/mailsets/common/.DRAFTS/new/.keep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/service/test/mailsets/common/.DRAFTS/new/.keep
diff --git a/service/test/mailsets/common/.DRAFTS/tmp/.keep b/service/test/mailsets/common/.DRAFTS/tmp/.keep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/service/test/mailsets/common/.DRAFTS/tmp/.keep
diff --git a/service/test/mailsets/common/.SENT/cur/mbox00000007:2,S b/service/test/mailsets/common/.SENT/cur/mbox00000007:2,S
new file mode 100644
index 00000000..569a49d4
--- /dev/null
+++ b/service/test/mailsets/common/.SENT/cur/mbox00000007:2,S
@@ -0,0 +1,9 @@
+Subject: Reliability
+From: alice@try.pixelated-project.org
+To: gilb@try.pixelated-project.org
+Date: Tue, 11 Apr 2015 12:13:14 +0000 (UTC)
+
+Computers are unreliable, but humans are even more unreliable.
+Any system which depends on human reliability is unreliable.
+ -- Gilb
+
diff --git a/service/test/mailsets/common/.SENT/new/.keep b/service/test/mailsets/common/.SENT/new/.keep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/service/test/mailsets/common/.SENT/new/.keep
diff --git a/service/test/mailsets/common/.SENT/tmp/.keep b/service/test/mailsets/common/.SENT/tmp/.keep
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/service/test/mailsets/common/.SENT/tmp/.keep
diff --git a/service/test/unit/maintenance/test_commands.py b/service/test/unit/maintenance/test_commands.py
index f5c93dbc..6f993106 100644
--- a/service/test/unit/maintenance/test_commands.py
+++ b/service/test/unit/maintenance/test_commands.py
@@ -111,5 +111,4 @@ class TestCommands(unittest.TestCase):
def _mail_content(self, mail_file):
with open(mail_file, 'r') as fp:
m = email.message_from_file(fp)
- m.set_payload(m.get_payload() + '\nINBOX')
return m.as_string()