From b2334df7a677047749d411dda4cd4cd58474ee8a Mon Sep 17 00:00:00 2001 From: Duda Dornelles Date: Wed, 15 Oct 2014 16:39:32 +0200 Subject: getting rid of "pixelated" in the names of many classes - redundant --- service/pixelated/adapter/listener.py | 48 --------------- service/pixelated/adapter/mail_sender.py | 33 +++++++++++ service/pixelated/adapter/mailbox.py | 53 +++++++++++++++++ .../pixelated/adapter/mailbox_indexer_listener.py | 48 +++++++++++++++ service/pixelated/adapter/mailboxes.py | 68 ++++++++++++++++++++++ service/pixelated/adapter/pixelated_mail_sender.py | 33 ----------- service/pixelated/adapter/pixelated_mailbox.py | 53 ----------------- service/pixelated/adapter/pixelated_mailboxes.py | 68 ---------------------- 8 files changed, 202 insertions(+), 202 deletions(-) delete mode 100644 service/pixelated/adapter/listener.py create mode 100644 service/pixelated/adapter/mail_sender.py create mode 100644 service/pixelated/adapter/mailbox.py create mode 100644 service/pixelated/adapter/mailbox_indexer_listener.py create mode 100644 service/pixelated/adapter/mailboxes.py delete mode 100644 service/pixelated/adapter/pixelated_mail_sender.py delete mode 100644 service/pixelated/adapter/pixelated_mailbox.py delete mode 100644 service/pixelated/adapter/pixelated_mailboxes.py (limited to 'service/pixelated/adapter') diff --git a/service/pixelated/adapter/listener.py b/service/pixelated/adapter/listener.py deleted file mode 100644 index 67d75df7..00000000 --- a/service/pixelated/adapter/listener.py +++ /dev/null @@ -1,48 +0,0 @@ -# -# Copyright (c) 2014 ThoughtWorks, Inc. -# -# Pixelated is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Pixelated is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PCULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Pixelated. If not, see . - - -class MailboxListener(object): - """ Listens for new mails, keeping the index updated """ - - SEARCH_ENGINE = None - - @classmethod - def listen(cls, account, mailbox_name, soledad_querier): - listener = MailboxListener(mailbox_name, soledad_querier) - if listener not in account.getMailbox(mailbox_name).listeners: - account.getMailbox(mailbox_name).addListener(listener) - - def __init__(self, mailbox_name, soledad_querier): - self.mailbox_name = mailbox_name - self.querier = soledad_querier - - def newMessages(self, exists, recent): - indexed_idents = set(self.SEARCH_ENGINE.search('tag:' + self.mailbox_name.lower())) - soledad_idents = self.querier.idents_by_mailbox(self.mailbox_name) - - missing_idents = soledad_idents.difference(indexed_idents) - - self.SEARCH_ENGINE.index_mails(self.querier.mails(missing_idents)) - - def __eq__(self, other): - return other and other.mailbox_name == self.mailbox_name - - def __hash__(self): - return self.mailbox_name.__hash__() - - def __repr__(self): - return 'MailboxListener: ' + self.mailbox_name diff --git a/service/pixelated/adapter/mail_sender.py b/service/pixelated/adapter/mail_sender.py new file mode 100644 index 00000000..1802a9d5 --- /dev/null +++ b/service/pixelated/adapter/mail_sender.py @@ -0,0 +1,33 @@ +# +# Copyright (c) 2014 ThoughtWorks, Inc. +# +# Pixelated is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pixelated is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Pixelated. If not, see . +import smtplib + +from pixelated.support.functional import flatten + + +class MailSender(): + def __init__(self, account_email_address, smtp_client=None): + self.account_email_address = account_email_address + self.smtp_client = smtp_client or smtplib.SMTP('localhost', 4650) + + def sendmail(self, mail): + recipients = flatten([mail.to, mail.cc, mail.bcc]) + + self.smtp_client.sendmail( + self.account_email_address, + recipients, + mail.to_smtp_format() + ) diff --git a/service/pixelated/adapter/mailbox.py b/service/pixelated/adapter/mailbox.py new file mode 100644 index 00000000..b5f2e6ea --- /dev/null +++ b/service/pixelated/adapter/mailbox.py @@ -0,0 +1,53 @@ +# +# Copyright (c) 2014 ThoughtWorks, Inc. +# +# Pixelated is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pixelated is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Pixelated. If not, see . + + +class Mailbox: + + def __init__(self, mailbox_name, querier): + self.mailbox_name = mailbox_name + self.mailbox_tag = mailbox_name.lower() + self.querier = querier + + def mails(self): + _mails = self.querier.all_mails_by_mailbox(self.mailbox_name) + + result = [] + for mail in _mails: + result.append(mail) + return result + + def mails_by_tags(self, tags): + if 'all' in tags or self.mailbox_tag in tags: + return self.mails() + return [mail for mail in self.mails() if len(mail.tags.intersection(tags)) > 0] + + def mail(self, mail_id): + for message in self.mails(): + if message.ident == mail_id: + return message + + def add(self, mail): + return self.querier.create_mail(mail, self.mailbox_name) + + def remove(self, ident): + mail = self.querier.mail(ident) + mail.remove_all_tags() + self.querier.remove_mail(mail) + + @classmethod + def create(cls, mailbox_name, soledad_querier): + return Mailbox(mailbox_name, soledad_querier) diff --git a/service/pixelated/adapter/mailbox_indexer_listener.py b/service/pixelated/adapter/mailbox_indexer_listener.py new file mode 100644 index 00000000..a7309118 --- /dev/null +++ b/service/pixelated/adapter/mailbox_indexer_listener.py @@ -0,0 +1,48 @@ +# +# Copyright (c) 2014 ThoughtWorks, Inc. +# +# Pixelated is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pixelated is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PCULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Pixelated. If not, see . + + +class MailboxIndexerListener(object): + """ Listens for new mails, keeping the index updated """ + + SEARCH_ENGINE = None + + @classmethod + def listen(cls, account, mailbox_name, soledad_querier): + listener = MailboxIndexerListener(mailbox_name, soledad_querier) + if listener not in account.getMailbox(mailbox_name).listeners: + account.getMailbox(mailbox_name).addListener(listener) + + def __init__(self, mailbox_name, soledad_querier): + self.mailbox_name = mailbox_name + self.querier = soledad_querier + + def newMessages(self, exists, recent): + indexed_idents = set(self.SEARCH_ENGINE.search('tag:' + self.mailbox_name.lower())) + soledad_idents = self.querier.idents_by_mailbox(self.mailbox_name) + + missing_idents = soledad_idents.difference(indexed_idents) + + self.SEARCH_ENGINE.index_mails(self.querier.mails(missing_idents)) + + def __eq__(self, other): + return other and other.mailbox_name == self.mailbox_name + + def __hash__(self): + return self.mailbox_name.__hash__() + + def __repr__(self): + return 'MailboxListener: ' + self.mailbox_name diff --git a/service/pixelated/adapter/mailboxes.py b/service/pixelated/adapter/mailboxes.py new file mode 100644 index 00000000..241a8050 --- /dev/null +++ b/service/pixelated/adapter/mailboxes.py @@ -0,0 +1,68 @@ +# +# Copyright (c) 2014 ThoughtWorks, Inc. +# +# Pixelated is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pixelated is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Pixelated. If not, see . +from pixelated.adapter.mailbox import Mailbox +from pixelated.adapter.mailbox_indexer_listener import MailboxIndexerListener + + +class Mailboxes(): + + def __init__(self, account, soledad_querier): + self.account = account + self.querier = soledad_querier + for mailbox_name in account.mailboxes: + MailboxIndexerListener.listen(self.account, mailbox_name, soledad_querier) + + def _create_or_get(self, mailbox_name): + mailbox_name = mailbox_name.upper() + if mailbox_name not in self.account.mailboxes: + self.account.addMailbox(mailbox_name) + MailboxIndexerListener.listen(self.account, mailbox_name, self.querier) + return Mailbox.create(mailbox_name, self.querier) + + def inbox(self): + return self._create_or_get('INBOX') + + def drafts(self): + return self._create_or_get('DRAFTS') + + def trash(self): + return self._create_or_get('TRASH') + + def sent(self): + return self._create_or_get('SENT') + + def mailboxes(self): + return [self._create_or_get(leap_mailbox_name) for leap_mailbox_name in self.account.mailboxes] + + def mails_by_tag(self, query_tags): + mails = [] + for mailbox in self.mailboxes(): + mails.extend(mailbox.mails_by_tags(query_tags)) + + return mails + + def move_to_trash(self, mail_id): + mail = self.querier.mail(mail_id) + mail.remove_all_tags() + mail.set_mailbox(self.trash().mailbox_name) + mail.save() + return mail + + def mail(self, mail_id): + for mailbox in self.mailboxes(): + mail = mailbox.mail(mail_id) + if mail: + return mail diff --git a/service/pixelated/adapter/pixelated_mail_sender.py b/service/pixelated/adapter/pixelated_mail_sender.py deleted file mode 100644 index bae86cd2..00000000 --- a/service/pixelated/adapter/pixelated_mail_sender.py +++ /dev/null @@ -1,33 +0,0 @@ -# -# Copyright (c) 2014 ThoughtWorks, Inc. -# -# Pixelated is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Pixelated is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Pixelated. If not, see . -import smtplib - -from pixelated.support.functional import flatten - - -class PixelatedMailSender(): - def __init__(self, account_email_address, smtp_client=None): - self.account_email_address = account_email_address - self.smtp_client = smtp_client or smtplib.SMTP('localhost', 4650) - - def sendmail(self, mail): - recipients = flatten([mail.to, mail.cc, mail.bcc]) - - self.smtp_client.sendmail( - self.account_email_address, - recipients, - mail.to_smtp_format() - ) diff --git a/service/pixelated/adapter/pixelated_mailbox.py b/service/pixelated/adapter/pixelated_mailbox.py deleted file mode 100644 index 283567db..00000000 --- a/service/pixelated/adapter/pixelated_mailbox.py +++ /dev/null @@ -1,53 +0,0 @@ -# -# Copyright (c) 2014 ThoughtWorks, Inc. -# -# Pixelated is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Pixelated is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Pixelated. If not, see . - - -class PixelatedMailbox: - - def __init__(self, mailbox_name, querier): - self.mailbox_name = mailbox_name - self.mailbox_tag = mailbox_name.lower() - self.querier = querier - - def mails(self): - _mails = self.querier.all_mails_by_mailbox(self.mailbox_name) - - result = [] - for mail in _mails: - result.append(mail) - return result - - def mails_by_tags(self, tags): - if 'all' in tags or self.mailbox_tag in tags: - return self.mails() - return [mail for mail in self.mails() if len(mail.tags.intersection(tags)) > 0] - - def mail(self, mail_id): - for message in self.mails(): - if message.ident == mail_id: - return message - - def add(self, mail): - return self.querier.create_mail(mail, self.mailbox_name) - - def remove(self, ident): - mail = self.querier.mail(ident) - mail.remove_all_tags() - self.querier.remove_mail(mail) - - @classmethod - def create(cls, mailbox_name, soledad_querier): - return PixelatedMailbox(mailbox_name, soledad_querier) diff --git a/service/pixelated/adapter/pixelated_mailboxes.py b/service/pixelated/adapter/pixelated_mailboxes.py deleted file mode 100644 index 79c007cb..00000000 --- a/service/pixelated/adapter/pixelated_mailboxes.py +++ /dev/null @@ -1,68 +0,0 @@ -# -# Copyright (c) 2014 ThoughtWorks, Inc. -# -# Pixelated is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# Pixelated is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with Pixelated. If not, see . -from pixelated.adapter.pixelated_mailbox import PixelatedMailbox -from pixelated.adapter.listener import MailboxListener - - -class PixelatedMailBoxes(): - - def __init__(self, account, soledad_querier): - self.account = account - self.querier = soledad_querier - for mailbox_name in account.mailboxes: - MailboxListener.listen(self.account, mailbox_name, soledad_querier) - - def _create_or_get(self, mailbox_name): - mailbox_name = mailbox_name.upper() - if mailbox_name not in self.account.mailboxes: - self.account.addMailbox(mailbox_name) - MailboxListener.listen(self.account, mailbox_name, self.querier) - return PixelatedMailbox.create(mailbox_name, self.querier) - - def inbox(self): - return self._create_or_get('INBOX') - - def drafts(self): - return self._create_or_get('DRAFTS') - - def trash(self): - return self._create_or_get('TRASH') - - def sent(self): - return self._create_or_get('SENT') - - def mailboxes(self): - return [self._create_or_get(leap_mailbox_name) for leap_mailbox_name in self.account.mailboxes] - - def mails_by_tag(self, query_tags): - mails = [] - for mailbox in self.mailboxes(): - mails.extend(mailbox.mails_by_tags(query_tags)) - - return mails - - def move_to_trash(self, mail_id): - mail = self.querier.mail(mail_id) - mail.remove_all_tags() - mail.set_mailbox(self.trash().mailbox_name) - mail.save() - return mail - - def mail(self, mail_id): - for mailbox in self.mailboxes(): - mail = mailbox.mail(mail_id) - if mail: - return mail -- cgit v1.2.3