diff options
author | Patrick Maia <pmaia@thoughtworks.com> | 2014-09-17 02:02:28 -0300 |
---|---|---|
committer | Patrick Maia <pmaia@thoughtworks.com> | 2014-09-17 13:53:25 -0300 |
commit | 95b0e2e6f834804630bf9d091b156ac68ff20583 (patch) | |
tree | 9bff8ebac2134cf23fd2bcd92f1a9500d8dd5ebf /service/pixelated/adapter/pixelated_mailbox.py | |
parent | c272f64293bb0157eb7eb1ebba899935f8ed2c3a (diff) |
74 - moves move_to_trash logic to PixelatedMailboxes and adds some tests
Diffstat (limited to 'service/pixelated/adapter/pixelated_mailbox.py')
-rw-r--r-- | service/pixelated/adapter/pixelated_mailbox.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/service/pixelated/adapter/pixelated_mailbox.py b/service/pixelated/adapter/pixelated_mailbox.py index 7d2a1fa5..a6dc4116 100644 --- a/service/pixelated/adapter/pixelated_mailbox.py +++ b/service/pixelated/adapter/pixelated_mailbox.py @@ -14,7 +14,9 @@ # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. +from pixelated.support.id_gen import gen_pixelated_uid from pixelated.adapter.pixelated_mail import PixelatedMail +from pixelated.adapter.status import Status from pixelated.adapter.tag_service import TagService from crochet import wait_for @@ -45,7 +47,7 @@ class PixelatedMailbox: result = [] for mail in mails: mail._collection = mails - pixelated_mail = PixelatedMail.from_leap_mail(mail, self.leap_mailbox) + pixelated_mail = PixelatedMail.from_leap_mail(mail) self.add_mailbox_tag_if_not_there(pixelated_mail) result.append(pixelated_mail) return result @@ -60,13 +62,18 @@ class PixelatedMailbox: if message.ident == mail_id: return message - def add_mail(self, mail): - original_flags = mail.leap_mail.getFlags() - self.leap_mailbox.addMessage(mail.raw_message(), original_flags) + def add(self, mail): + leap_id = self._do_add_async(mail) + new_id = gen_pixelated_uid(self.leap_mailbox.mbox, leap_id) + return new_id @wait_for(timeout=3.0) - def add(self, mail): - return self.leap_mailbox.messages.add_msg(mail.to_smtp_format()) + def _do_add_async(self, mail): + return self.leap_mailbox.messages.add_msg(mail.raw_message()) + + def remove(self, mail): + mail.leap_mail.setFlags((Status.PixelatedStatus.DELETED,), 1) + self.leap_mailbox.expunge() @classmethod def create(cls, account, mailbox_name='INBOX'): |