コード例 #1
0
 def sender(self):
     """ get the email address of the sender
     """
     sender = utils.get_header(self.msg(), 'Resent-From')
     if not sender:
         sender = utils.get_header(self.msg(), 'From')
     (sender_name, sender_address) = parseaddr(sender)
     return sender_address
コード例 #2
0
    def test_get_header_fixes_encoded_words_without_lwsp(self):
        self.assertEquals(
            'B\xc3\xa4rengraben <*****@*****.**>',
            utils.get_header(self.encoded_word_without_lwsp, 'To'))

        # Should not insert additional whitespace between encoded words
        self.assertEquals(
            'B\xc3\xa4rengrabenB\xc3\xa4rengraben <*****@*****.**>',
            utils.get_header(self.encoded_word_without_lwsp, 'From'))
コード例 #3
0
ファイル: inbound.py プロジェクト: 4teamwork/ftw.mail
 def sender(self):
     """ get the email address of the sender
     """
     sender = utils.get_header(self.msg(), 'Resent-From')
     if not sender:
         sender = utils.get_header(self.msg(), 'From')
         log.info("Picked sender from 'From' header")
     else:
         log.info("Picked sender from 'Resent-From' header")
     (sender_name, sender_address) = parseaddr(sender)
     return sender_address
コード例 #4
0
ファイル: inbound.py プロジェクト: 4teamwork/ftw.mail
 def recipient(self):
     """ get the email address of the recipient
     """
     # If recipient is supplied in request (by mta2plone), use that
     recipient = self.request.get('recipient')
     if not recipient:
         # Otherwise fall back to `Resent-To` or `To` headers
         recipient = utils.get_header(self.msg(), 'Resent-To')
         if not recipient:
             recipient = utils.get_header(self.msg(), 'To')
     (recipient_name, recipient_address) = parseaddr(recipient)
     return recipient_address
コード例 #5
0
 def test_from_and_to_addresses(self, browser):
     self.login(self.dossier_responsible, browser)
     self.create_task_via_browser(browser)
     mail = email.message_from_string(Mailing(self.portal).pop())
     self.assertEquals('*****@*****.**', mail.get('To'))
     self.assertEquals('Ziegler Robert <*****@*****.**>',
                       get_header(mail, 'From'))
コード例 #6
0
ファイル: to4501.py プロジェクト: 4teamwork/opengever.core
def fix_field_value(mail, field_name, header_name):
    """Try to fix a possibly incorrectly decoded value in a field by:
    - Checking whether it looks like a raw, undecoded header
    - Checking whether it is exactly the same as the corresponding raw header
      value (which means is hasn't been edited by a user)
    - If both of the above are true, re-decode it by fetching it from the
      original message again using `get_header`
    - If the new value is different, update it on the object, reindex the
      necessary indexes, and sync the filename to the title again if needed.
    """
    updated = False
    value = getattr(mail, field_name)
    if looks_incorrectly_decoded(value) and value == mail.msg[header_name]:
        new_value = get_header(mail.msg, header_name)

        # safe_decode_headers returns UTF8, Dexterity wants unicode
        new_value = new_value.decode('utf-8')

        if value != new_value:
            log.info("Fixing '{}' for mail {} ({} -> {})".format(
                field_name, mail.absolute_url(), repr(value), repr(new_value)))
            setattr(mail, field_name, new_value)
            if field_name == 'title':
                mail.update_filename()
            updated = True

    return updated
コード例 #7
0
def fix_field_value(mail, field_name, header_name):
    """Try to fix a possibly incorrectly decoded value in a field by:
    - Checking whether it looks like a raw, undecoded header
    - Checking whether it is exactly the same as the corresponding raw header
      value (which means is hasn't been edited by a user)
    - If both of the above are true, re-decode it by fetching it from the
      original message again using `get_header`
    - If the new value is different, update it on the object, reindex the
      necessary indexes, and sync the filename to the title again if needed.
    """
    updated = False
    value = getattr(mail, field_name)
    if looks_incorrectly_decoded(value) and value == mail.msg[header_name]:
        new_value = get_header(mail.msg, header_name)

        # safe_decode_headers returns UTF8, Dexterity wants unicode
        new_value = new_value.decode('utf-8')

        if value != new_value:
            log.info("Fixing '{}' for mail {} ({} -> {})".format(
                field_name, mail.absolute_url(), repr(value), repr(new_value)))
            setattr(mail, field_name, new_value)
            if field_name == 'title':
                mail.update_filename()
            updated = True

    return updated
コード例 #8
0
 def _update_title_from_message_subject(self):
     subject = utils.get_header(self.msg, 'Subject')
     if subject:
         # long headers may contain line breaks with tabs.
         # replace these by a space.
         subject = subject.replace('\n\t', ' ')
         self._title = subject.decode('utf8')
コード例 #9
0
ファイル: test_mail.py プロジェクト: 4teamwork/opengever.core
    def test_from_and_to_addresses(self, browser):
        browser.login().open(self.dossier, view="++add++opengever.task.task")
        browser.fill({"Title": "Test Task", "Responsible": "hugo.boss", "Task Type": "comment"})
        browser.css("#form-buttons-save").first.click()

        mail = email.message_from_string(Mailing(self.portal).pop())
        self.assertEquals("*****@*****.**", mail.get("To"))
        self.assertEquals("Test User <*****@*****.**>", get_header(mail, "From"))
コード例 #10
0
    def test_get_from_header_with_quotes(self):
        self.assertEquals(
            '"Mueller-Valser, Gabriela" <*****@*****.**>',
            self.from_header_with_quotes['From'])

        self.assertEquals(
            '"Mueller-Valser, Gabriela" <*****@*****.**>',
            utils.get_header(self.from_header_with_quotes, 'From'))
コード例 #11
0
ファイル: test_mail.py プロジェクト: 4teamwork/opengever.core
    def test_from_and_to_addresses(self, browser):
        self.login(self.dossier_responsible, browser)

        self.create_task_via_browser(browser)
        process_mail_queue()

        mail = email.message_from_string(Mailing(self.portal).pop())
        self.assertEquals('*****@*****.**', mail.get('To'))
        self.assertEquals('Ziegler Robert <*****@*****.**>', get_header(mail, 'From'))
コード例 #12
0
    def test_notifies_only_new_responsible_per_mail(self, browser):
        self.task = self.add_task(browser)
        Mailing(self.portal).reset()

        self.reassign(browser, 'hugo.boss', u'Bitte Abkl\xe4rungen erledigen.')
        self.assertEqual(1, len(Mailing(self.portal).get_messages()))

        mail = email.message_from_string(Mailing(self.portal).pop())
        self.assertEquals('*****@*****.**', get_header(mail, 'To'))
コード例 #13
0
    def test_notifies_only_new_responsible_per_mail(self, browser):
        self.task = self.add_task(browser)
        Mailing(self.portal).reset()

        self.reassign(browser, 'hugo.boss', u'Bitte Abkl\xe4rungen erledigen.')
        self.assertEqual(1, len(Mailing(self.portal).get_messages()))

        mail = email.message_from_string(Mailing(self.portal).pop())
        self.assertEquals(
            '*****@*****.**', get_header(mail, 'To'))
コード例 #14
0
ファイル: test_mail.py プロジェクト: lukasgraf/opengever.core
 def test_mail_dispatcher_respects_dispatcher_roles_even_if_its_a_group(self, browser):
     """By default only the responsible should be notified by mail, when
     a task gets added.
     """
     self.login(self.dossier_responsible, browser)
     browser.open(self.dossier, view='++add++opengever.task.task')
     self.create_task_via_browser(browser, inbox=True)
     self.assertEquals(1, len(Mailing(self.portal).get_messages()))
     mail = email.message_from_string(Mailing(self.portal).pop())
     self.assertEquals('*****@*****.**', get_header(mail, 'To'))
コード例 #15
0
 def test_mail_dispatcher_respects_dispatcher_roles(self, browser):
     """By default only the responsible should be notified by mail, when
     a task gets added.
     """
     self.login(self.dossier_responsible, browser)
     browser.open(self.dossier, view='++add++opengever.task.task')
     self.create_task_via_browser(browser)
     self.assertEquals(1, len(Mailing(self.portal).get_messages()))
     mail = email.message_from_string(Mailing(self.portal).pop())
     self.assertEquals('*****@*****.**', get_header(mail, 'To'))
コード例 #16
0
def get_author_by_email(mail):
    header_from = utils.get_header(mail.msg, 'From')
    email = extract_email(header_from)

    session = create_session()
    principal = session.query(User).filter(
        func.lower(User.email) == email).first()

    if principal is None:
        return header_from.decode('utf-8')
    return u'{0} {1}'.format(principal.lastname, principal.firstname)
コード例 #17
0
ファイル: test_mail.py プロジェクト: 4teamwork/opengever.core
    def test_mail_dispatcher_respects_dispatcher_roles(self, browser):
        """By default only the responsible should be notified by mail, when
        a task gets added.
        """
        browser.login().open(self.dossier, view="++add++opengever.task.task")
        browser.fill({"Title": "Test Task", "Responsible": "hugo.boss", "Task Type": "comment"})
        browser.css("#form-buttons-save").first.click()

        self.assertEquals(1, len(Mailing(self.portal).get_messages()))
        mail = email.message_from_string(Mailing(self.portal).pop())
        self.assertEquals("*****@*****.**", get_header(mail, "To"))
コード例 #18
0
def get_author_by_email(mail):
    header_from = utils.get_header(mail.msg, 'From')
    email = extract_email(header_from)

    session = create_session()
    principal = session.query(User).filter(
        func.lower(User.email) == email).first()

    if principal is None:
        return header_from.decode('utf-8')
    return u'{0} {1}'.format(principal.lastname, principal.firstname)
コード例 #19
0
    def test_notifies_only_new_responsible_per_mail(self, browser):
        process_mail_queue()
        Mailing(self.portal).reset()

        self.reassign(browser, self.meeting_user,
                      u'Bitte Abkl\xe4rungen erledigen.')
        process_mail_queue()

        self.assertEqual(1, len(Mailing(self.portal).get_messages()))

        mail = email.message_from_string(Mailing(self.portal).pop())
        self.assertEquals('*****@*****.**', get_header(mail, 'To'))
コード例 #20
0
    def test_notifies_only_new_responsible_per_mail(self, browser):
        process_mail_queue()
        Mailing(self.portal).reset()

        self.reassign(browser, self.meeting_user, u'Bitte Abkl\xe4rungen erledigen.')
        process_mail_queue()

        self.assertEqual(1, len(Mailing(self.portal).get_messages()))

        mail = email.message_from_string(Mailing(self.portal).pop())
        self.assertEquals(
            '*****@*****.**', get_header(mail, 'To'))
コード例 #21
0
    def get_header(self, name):
        """Returns a header value from the mail message.
        This method caches the retrieved values.
        """

        if getattr(self, '_header_cache', None) is None:
            self._reset_header_cache()

        if name not in self._header_cache:
            self._header_cache[name] = utils.get_header(self.msg, name)

        return self._header_cache[name]
コード例 #22
0
ファイル: indexer.py プロジェクト: hellfish2/opengever.core
def document_author(obj):
    """Return the sender address for the indexer document_author."""
    document_author = utils.get_header(obj.msg, 'From')

    # strip newlines
    document_author = document_author.replace('\n', '')

    if _is_bad_from(document_author):
        document_author = re.sub(r'<.*>', '', document_author).rstrip()

    document_author = document_author.replace('<', '&lt;')
    document_author = document_author.replace('>', '&gt;')
    return document_author
コード例 #23
0
    def test_from_and_to_addresses(self, browser):
        browser.login().open(self.dossier, view='++add++opengever.task.task')
        browser.fill({'Title': 'Test Task',
                      'Task Type': 'comment'})

        form = browser.find_form_by_field('Responsible')
        form.find_widget('Responsible').fill(self.org_unit.id() + ':hugo.boss')
        browser.css('#form-buttons-save').first.click()

        mail = email.message_from_string(Mailing(self.portal).pop())
        self.assertEquals('*****@*****.**', mail.get('To'))
        self.assertEquals(
            'Test User <*****@*****.**>', get_header(mail, 'From'))
コード例 #24
0
ファイル: indexer.py プロジェクト: hellfish2/opengever.core
def document_author(obj):
    """Return the sender address for the indexer document_author."""
    document_author = utils.get_header(obj.msg, 'From')

    # strip newlines
    document_author = document_author.replace('\n', '')

    if _is_bad_from(document_author):
        document_author = re.sub(r'<.*>', '', document_author).rstrip()

    document_author = document_author.replace('<', '&lt;')
    document_author = document_author.replace('>', '&gt;')
    return document_author
コード例 #25
0
def initalize_title(mail, event):

    if not IOGMail(mail).title:
        subject = utils.get_header(mail.msg, 'Subject')
        if subject:
            # long headers may contain line breaks with tabs.
            # replace these by a space.
            subject = subject.replace('\n\t', ' ')
            value = subject.decode('utf8')
        else:
            value = translate(ftw_mf(u'no_subject', default=u'[No Subject]'),
                              context=getSite().REQUEST)

        IOGMail(mail).title = value
        mail.title = value
コード例 #26
0
def readable_ogds_author(item, author):
    if getattr(item, 'portal_type', None) == 'ftw.mail.mail':
        if getattr(item, 'msg', None):
            # Object
            author = get_header(item.msg, 'From')
        else:
            # Brain
            author = item.document_author

    if not isinstance(author, unicode):
        if author is not None:
            author = author.decode('utf-8')
        else:
            author = ''

    return Actor.lookup(author).get_label()
コード例 #27
0
    def test_mail_dispatcher_respects_dispatcher_roles(self, browser):
        """By default only the responsible should be notified by mail, when
        a task gets added.
        """
        browser.login().open(self.dossier, view='++add++opengever.task.task')
        browser.fill({'Title': 'Test Task',
                      'Task Type': 'comment'})

        form = browser.find_form_by_field('Responsible')
        form.find_widget('Responsible').fill(self.org_unit.id() + ':hugo.boss')
        browser.css('#form-buttons-save').first.click()

        self.assertEquals(1, len(Mailing(self.portal).get_messages()))
        mail = email.message_from_string(Mailing(self.portal).pop())
        self.assertEquals(
            '*****@*****.**', get_header(mail, 'To'))
コード例 #28
0
ファイル: mail.py プロジェクト: hellfish2/opengever.core
def initalize_title(mail, event):

    if not IOGMail(mail).title:
        subject = utils.get_header(mail.msg, 'Subject')
        if subject:
            # long headers may contain line breaks with tabs.
            # replace these by a space.
            subject = subject.replace('\n\t', ' ')
            value = subject.decode('utf8')
        else:
            value = translate(
                ftw_mf(u'no_subject', default=u'[No Subject]'),
                context=getSite().REQUEST)

        IOGMail(mail).title = value
        mail.title = value
コード例 #29
0
ファイル: helper.py プロジェクト: 4teamwork/opengever.core
def readable_ogds_author(item, author):
    if getattr(item, 'portal_type', None) == 'ftw.mail.mail':
        if getattr(item, 'msg', None):
            # Object
            author = get_header(item.msg, 'From')
        else:
            # Brain
            author = item.document_author

    if not isinstance(author, unicode):
        if author is not None:
            author = author.decode('utf-8')
        else:
            author = ''

    return Actor.lookup(author).get_label()
コード例 #30
0
 def test_get_header(self):
     self.assertEquals('', utils.get_header(self.msg_empty, 'Subject'))
     self.assertEquals('Lorem Ipsum',
                       utils.get_header(self.msg_ascii, 'Subject'))
     self.assertEquals('Die B\xc3\xbcrgschaft',
                       utils.get_header(self.msg_latin1, 'Subject'))
     self.assertEquals('Friedrich H\xc3\xb6lderlin <*****@*****.**>',
                       utils.get_header(self.msg_latin1, 'To'))
     self.assertEquals('Die B\xc3\xbcrgschaft',
                       utils.get_header(self.msg_utf8, 'Subject'))
     self.assertEquals('Friedrich H\xc3\xb6lderlin <*****@*****.**>',
                       utils.get_header(self.msg_utf8, 'To'))
コード例 #31
0
ファイル: test_mail.py プロジェクト: 4teamwork/opengever.core
    def test_mail_dispatcher_respects_dispatcher_roles_even_if_its_a_group(self, browser):
        """By default only the responsible should be notified by mail, when
        a task gets added.
        """

        inbox_group = self.org_unit.inbox_group
        inbox_group.users.append(self.hugo)
        inbox_group.users.append(self.franz)

        browser.login().open(self.dossier, view="++add++opengever.task.task")
        browser.fill(
            {"Title": "Test Task", "Issuer": "inbox:client1", "Responsible": "franz.michel", "Task Type": "comment"}
        )
        browser.css("#form-buttons-save").first.click()

        self.assertEquals(1, len(Mailing(self.portal).get_messages()))
        mail = email.message_from_string(Mailing(self.portal).pop())
        self.assertEquals("*****@*****.**", get_header(mail, "To"))
コード例 #32
0
def initalize_title(mail, event):
    title = IOGMail(mail).title
    if not title or title == NO_SUBJECT_FALLBACK_ID:
        subject = utils.get_header(mail.msg, 'Subject')
        if subject:
            # long headers may contain line breaks with tabs.
            # replace these by a space.
            subject = subject.replace('\n\t', ' ')
            value = subject.decode('utf8')
        else:
            value = translate(
                ftw_mf(NO_SUBJECT_FALLBACK_ID,
                       default=NO_SUBJECT_TITLE_FALLBACK.decode('utf-8')),
                context=getSite().REQUEST)

        IOGMail(mail).title = value

    mail.update_filename()
コード例 #33
0
ファイル: mail.py プロジェクト: 4teamwork/opengever.core
def initalize_title(mail, event):
    title = IOGMail(mail).title
    if not title or title == NO_SUBJECT_FALLBACK_ID:
        subject = utils.get_header(mail.msg, 'Subject')
        if subject:
            # long headers may contain line breaks with tabs.
            # replace these by a space.
            subject = subject.replace('\n\t', ' ')
            value = subject.decode('utf8')
        else:
            value = translate(
                ftw_mf(NO_SUBJECT_FALLBACK_ID,
                       default=NO_SUBJECT_TITLE_FALLBACK.decode('utf-8')),
                context=getSite().REQUEST)

        IOGMail(mail).title = value

    mail.update_filename()
コード例 #34
0
ファイル: mail.py プロジェクト: 4teamwork/ftw.mail
    def get_header(self, name, isdate=False):
        """Returns a header value from the mail message.
        If it is a date, it returns a DateTime.
        This method caches the retrieved values.
        """

        if getattr(self, '_header_cache', None) is None:
            self._reset_header_cache()

        if name not in self._header_cache:
            if isdate:
                ts = utils.get_date_header(self.msg, name)
                if ts is not None:
                    self._header_cache[name] = DateTime(ts)
                else:
                    self._header_cache[name] = ""
            else:
                self._header_cache[name] = utils.get_header(self.msg, name)

        return self._header_cache[name]
コード例 #35
0
ファイル: helper.py プロジェクト: hellfish2/opengever.core
def readable_ogds_author(item, author):
    if getattr(item, 'portal_type', None) == 'ftw.mail.mail':
        if getattr(item, 'msg', None):
            # Object
            author = get_header(item.msg, 'From')
        else:
            # Brain
            author = item.document_author
    if not isinstance(author, unicode):
        if author is not None:
            author = author.decode('utf-8')
        else:
            author = ''
    if IPropertiedUser.providedBy(author) or IMemberData.providedBy(author):
        author = author.getId()
    info = getUtility(IContactInformation)
    if info.is_user(author) or info.is_contact(author) or info.is_inbox(
            author):
        return info.describe(author)
    else:
        return author
コード例 #36
0
ファイル: helper.py プロジェクト: pemzurigo/opengever.core
def readable_ogds_author(item, author):
    if getattr(item, 'portal_type', None) == 'ftw.mail.mail':
        if getattr(item, 'msg', None):
            # Object
            author = get_header(item.msg, 'From')
        else:
            # Brain
            author = item.document_author
    if not isinstance(author, unicode):
        if author is not None:
            author = author.decode('utf-8')
        else:
            author = ''
    if IPropertiedUser.providedBy(author) or IMemberData.providedBy(author):
        author = author.getId()
    info = getUtility(IContactInformation)
    if info.is_user(author) or info.is_contact(
            author) or info.is_inbox(author):
        return info.describe(author)
    else:
        return author
コード例 #37
0
    def test_mail_dispatcher_respects_dispatcher_roles_even_if_its_a_group(self, browser):
        """By default only the responsible should be notified by mail, when
        a task gets added.
        """

        inbox_group = self.org_unit.inbox_group
        inbox_group.users.append(self.hugo)
        inbox_group.users.append(self.franz)

        browser.login().open(self.dossier, view='++add++opengever.task.task')
        browser.fill({'Title': 'Test Task',
                      'Task Type': 'comment'})
        form = browser.find_form_by_field('Responsible')
        form.find_widget('Responsible').fill(
            self.org_unit.id() + ':franz.michel')
        form.find_widget('Issuer').fill('inbox:client1')

        browser.css('#form-buttons-save').first.click()

        self.assertEquals(1, len(Mailing(self.portal).get_messages()))
        mail = email.message_from_string(Mailing(self.portal).pop())
        self.assertEquals(
            '*****@*****.**', get_header(mail, 'To'))
コード例 #38
0
 def get_header(self, name):
     return utils.get_header(self.msg(), name)