Example #1
0
    def notify(self, resid, subject, author=None):
        self.subject = subject
        config = self.config['notification']
        if not config.getbool('smtp_enabled'):
            return
        from_email, from_name = '', ''
        if author and config.getbool('smtp_from_author'):
            from_email = self.get_smtp_address(author)
            if from_email:
                from_name = self.name_map.get(author, '')
                if not from_name:
                    mo = self.longaddr_re.search(author)
                    if mo:
                        from_name = mo.group(1)
        if not from_email:
            from_email = config.get('smtp_from')
            from_name = config.get('smtp_from_name') or self.env.project_name
        self.replyto_email = config.get('smtp_replyto')
        self.from_email = from_email or self.replyto_email
        self.from_name = from_name
        if not self.from_email and not self.replyto_email:
            message = tag(
                tag.p(_('Unable to send email due to identity crisis.')),
                # convert explicitly to `Fragment` to avoid breaking message
                # when passing `LazyProxy` object to `Fragment`
                tag.p(to_fragment(tag_(
                    "Neither %(from_)s nor %(reply_to)s are specified in the "
                    "configuration.",
                    from_=tag.strong("[notification] smtp_from"),
                    reply_to=tag.strong("[notification] smtp_replyto")))))
            raise TracError(message, _("SMTP Notification Error"))

        Notify.notify(self, resid)
Example #2
0
 def test_tracerror_with_fragment(self):
     message = tag('Powered by ',
                   tag.a('Trac', href='http://trac.edgewall.org/'))
     rv = to_fragment(TracError(message))
     self.assertEqual(Fragment, type(rv))
     self.assertEqual('Powered by <a href="http://trac.edgewall.org/">Trac'
                      '</a>', unicode(rv))
Example #3
0
    def notify(self, resid, subject, author=None):
        self.subject = subject
        config = self.config['notification']
        if not config.getbool('smtp_enabled'):
            return
        from_email, from_name = '', ''
        if author and config.getbool('smtp_from_author'):
            from_email = self.get_smtp_address(author)
            if from_email:
                from_name = self.name_map.get(author, '')
                if not from_name:
                    mo = self.longaddr_re.search(author)
                    if mo:
                        from_name = mo.group(1)
        if not from_email:
            from_email = config.get('smtp_from')
            from_name = config.get('smtp_from_name') or self.env.project_name
        self.replyto_email = config.get('smtp_replyto')
        self.from_email = from_email or self.replyto_email
        self.from_name = from_name
        if not self.from_email and not self.replyto_email:
            message = tag(
                tag.p(_('Unable to send email due to identity crisis.')),
                # convert explicitly to `Fragment` to avoid breaking message
                # when passing `LazyProxy` object to `Fragment`
                tag.p(to_fragment(tag_(
                    "Neither %(from_)s nor %(reply_to)s are specified in the "
                    "configuration.",
                    from_=tag.strong("[notification] smtp_from"),
                    reply_to=tag.strong("[notification] smtp_replyto")))))
            raise TracError(message, _("SMTP Notification Error"))

        Notify.notify(self, resid)
Example #4
0
 def test_tracerror_with_fragment(self):
     message = tag('Powered by ',
                   tag.a('Trac', href='http://trac.edgewall.org/'))
     rv = to_fragment(TracError(message))
     self.assertEqual(Fragment, type(rv))
     self.assertEqual('Powered by <a href="http://trac.edgewall.org/">Trac'
                      '</a>', unicode(rv))
Example #5
0
 def test_tracerror_with_tracerror_with_element(self):
     message = tag.p('Powered by ',
                     tag.a('Trac', href='http://trac.edgewall.org/'))
     rv = to_fragment(TracError(TracError(message)))
     self.assertEqual(Element, type(rv))
     self.assertEqual('<p>Powered by <a href="http://trac.edgewall.org/">'
                      'Trac</a></p>', unicode(rv))
Example #6
0
 def test_tracerror_with_tracerror_with_element(self):
     message = tag.p('Powered by ',
                     tag.a('Trac', href='http://trac.edgewall.org/'))
     rv = to_fragment(TracError(TracError(message)))
     self.assertEqual(Element, type(rv))
     self.assertEqual('<p>Powered by <a href="http://trac.edgewall.org/">'
                      'Trac</a></p>', unicode(rv))
Example #7
0
 def test_tgettext(self):
     rv = to_fragment(
         tgettext('Back to %(parent)s',
                  parent=tag.a('WikiStart', href='http://localhost/')))
     self.assertEqual(Fragment, type(rv))
     self.assertEqual('Back to <a href="http://localhost/">WikiStart</a>',
                      unicode(rv))
Example #8
0
 def test_tgettext(self):
     rv = to_fragment(tgettext('Back to %(parent)s',
                               parent=tag.a('WikiStart',
                                            href='http://localhost/')))
     self.assertEqual(Fragment, type(rv))
     self.assertEqual('Back to <a href="http://localhost/">WikiStart</a>',
                      unicode(rv))
Example #9
0
 def test_tracerror_with_tgettext(self):
     e = TracError(
         tgettext('Back to %(parent)s',
                  parent=tag.a('WikiStart', href='http://localhost/')))
     rv = to_fragment(e)
     self.assertEqual(Fragment, type(rv))
     self.assertEqual('Back to <a href="http://localhost/">WikiStart</a>',
                      str(rv))
Example #10
0
 def test_element(self):
     rv = to_fragment(tag.p('blah'))
     self.assertEqual(Element, type(rv))
     self.assertEqual('<p>blah</p>', unicode(rv))
Example #11
0
 def test_fragment(self):
     rv = to_fragment(tag('blah'))
     self.assertEqual(Fragment, type(rv))
     self.assertEqual('blah', unicode(rv))
Example #12
0
 def test_error_with_error_with_fragment(self):
     v1 = ValueError(tag('invalid literal for int(): ', tag.b('blah')))
     rv = to_fragment(ValueError(v1))
     self.assertEqual(Fragment, type(rv))
     self.assertEqual('invalid literal for int(): <b>blah</b>', unicode(rv))
Example #13
0
 def test_unicode(self):
     rv = to_fragment('blah')
     self.assertEqual(Fragment, type(rv))
     self.assertEqual('blah', str(rv))
Example #14
0
 def test_tracerror_with_gettext(self):
     e = TracError(gettext('%(size)s bytes', size=0))
     rv = to_fragment(e)
     self.assertEqual(Fragment, type(rv))
     self.assertEqual('0 bytes', unicode(rv))
Example #15
0
 def test_gettext(self):
     rv = to_fragment(gettext('%(size)s bytes', size=0))
     self.assertEqual(Fragment, type(rv))
     self.assertEqual('0 bytes', unicode(rv))
Example #16
0
 def test_error_with_error_with_fragment(self):
     v1 = ValueError(tag('invalid literal for int(): ', tag.b('blah')))
     rv = to_fragment(ValueError(v1))
     self.assertEqual(Fragment, type(rv))
     self.assertEqual('invalid literal for int(): <b>blah</b>', unicode(rv))
Example #17
0
 def test_error(self):
     rv = to_fragment(ValueError('invalid literal for int(): blah'))
     self.assertEqual(Fragment, type(rv))
     self.assertEqual('invalid literal for int(): blah', unicode(rv))
Example #18
0
 def test_tracerror(self):
     rv = to_fragment(TracError('blah'))
     self.assertEqual(Fragment, type(rv))
     self.assertEqual('blah', unicode(rv))
Example #19
0
 def test_error(self):
     rv = to_fragment(ValueError('invalid literal for int(): blah'))
     self.assertEqual(Fragment, type(rv))
     self.assertEqual('invalid literal for int(): blah', unicode(rv))
Example #20
0
 def test_ioerror(self):
     rv = to_fragment(self._ioerror('./notfound'))
     self.assertEqual(Fragment, type(rv))
     self.assertEqual("[Errno 2] No such file or directory: './notfound'",
                      unicode(rv))
Example #21
0
 def test_gettext(self):
     rv = to_fragment(gettext('%(size)s bytes', size=0))
     self.assertEqual(Fragment, type(rv))
     self.assertEqual('0 bytes', unicode(rv))
Example #22
0
 def test_element(self):
     rv = to_fragment(tag.p('blah'))
     self.assertEqual(Element, type(rv))
     self.assertEqual('<p>blah</p>', unicode(rv))
Example #23
0
 def test_tracerror_with_gettext(self):
     e = TracError(gettext('%(size)s bytes', size=0))
     rv = to_fragment(e)
     self.assertEqual(Fragment, type(rv))
     self.assertEqual('0 bytes', unicode(rv))
Example #24
0
 def test_tracerror(self):
     rv = to_fragment(TracError('blah'))
     self.assertEqual(Fragment, type(rv))
     self.assertEqual('blah', unicode(rv))
Example #25
0
 def test_error_with_ioerror(self):
     e = self._ioerror('./notfound')
     rv = to_fragment(ValueError(e))
     self.assertEqual(Fragment, type(rv))
     self.assertEqual("[Errno 2] No such file or directory: './notfound'",
                      unicode(rv))
Example #26
0
 def test_fragment(self):
     rv = to_fragment(tag('blah'))
     self.assertEqual(Fragment, type(rv))
     self.assertEqual('blah', unicode(rv))