Exemple #1
0
    def test_email_references_header(self):
        c.user = M.User.by_username('test-admin')
        with mock.patch.object(mail_tasks.smtp_client, '_client') as _client:
            mail_tasks.sendsimplemail(fromaddr=str(c.user._id),
                                      toaddr='*****@*****.**',
                                      text=u'This is a test',
                                      reply_to=g.noreply,
                                      subject=u'Test subject',
                                      references=['a', 'b', 'c'],
                                      message_id=h.gen_message_id())
            assert_equal(_client.sendmail.call_count, 1)
            return_path, rcpts, body = _client.sendmail.call_args[0]
            body = body.split('\n')
            assert_in('From: "Test Admin" <*****@*****.**>', body)
            assert_in('References: <a> <b> <c>', body)

            _client.reset_mock()
            mail_tasks.sendmail(fromaddr=str(c.user._id),
                                destinations=[str(c.user._id)],
                                text=u'This is a test',
                                reply_to=g.noreply,
                                subject=u'Test subject',
                                references=u'ref',
                                message_id=h.gen_message_id())
            assert_equal(_client.sendmail.call_count, 1)
            return_path, rcpts, body = _client.sendmail.call_args[0]
            body = body.split('\n')
            assert_in('From: "Test Admin" <*****@*****.**>', body)
            assert_in('References: <ref>', body)
Exemple #2
0
    def test_email_references_header(self):
        c.user = M.User.by_username('test-admin')
        with mock.patch.object(mail_tasks.smtp_client, '_client') as _client:
            mail_tasks.sendsimplemail(
                fromaddr=str(c.user._id),
                toaddr='*****@*****.**',
                text=u'This is a test',
                reply_to=g.noreply,
                subject=u'Test subject',
                references=['a', 'b', 'c'],
                message_id=h.gen_message_id())
            assert_equal(_client.sendmail.call_count, 1)
            return_path, rcpts, body = _client.sendmail.call_args[0]
            body = body.split('\n')
            assert_in('From: "Test Admin" <*****@*****.**>', body)
            assert_in('References: <a> <b> <c>', body)

            _client.reset_mock()
            mail_tasks.sendmail(
                fromaddr=str(c.user._id),
                destinations=[str(c.user._id)],
                text=u'This is a test',
                reply_to=g.noreply,
                subject=u'Test subject',
                references=u'ref',
                message_id=h.gen_message_id())
            assert_equal(_client.sendmail.call_count, 1)
            return_path, rcpts, body = _client.sendmail.call_args[0]
            body = body.split('\n')
            assert_in('From: "Test Admin" <*****@*****.**>', body)
            assert_in('References: <ref>', body)
Exemple #3
0
    def test_email_sender_to_headers(self):
        c.user = M.User.by_username('test-admin')
        with mock.patch.object(mail_tasks.smtp_client, '_client') as _client:
            mail_tasks.sendsimplemail(fromaddr=str(c.user._id),
                                      toaddr='*****@*****.**',
                                      text=u'This is a test',
                                      reply_to=g.noreply,
                                      subject=u'Test subject',
                                      sender=u'*****@*****.**',
                                      message_id=h.gen_message_id())
            assert_equal(_client.sendmail.call_count, 1)
            return_path, rcpts, body = _client.sendmail.call_args[0]
            body = body.split('\n')
            assert_in('From: "Test Admin" <*****@*****.**>', body)
            assert_in('Sender: [email protected]', body)
            assert_in('To: [email protected]', body)

            _client.reset_mock()
            mail_tasks.sendmail(fromaddr=str(c.user._id),
                                destinations=[str(c.user._id)],
                                text=u'This is a test',
                                reply_to=u'*****@*****.**',
                                subject=u'Test subject',
                                sender=u'*****@*****.**',
                                message_id=h.gen_message_id())
            assert_equal(_client.sendmail.call_count, 1)
            return_path, rcpts, body = _client.sendmail.call_args[0]
            body = body.split('\n')
            assert_in('From: "Test Admin" <*****@*****.**>', body)
            assert_in('Sender: [email protected]', body)
            assert_in('To: [email protected]', body)
Exemple #4
0
    def test_send_email_nonascii(self):
        with mock.patch.object(mail_tasks.smtp_client, '_client') as _client:
            mail_tasks.sendmail(fromaddr=u'"По" <*****@*****.**>',
                                destinations=['*****@*****.**'],
                                text=u'Громады стройные теснятся',
                                reply_to=g.noreply,
                                subject=u'По оживлённым берегам',
                                message_id=h.gen_message_id())
            assert_equal(_client.sendmail.call_count, 1)
            return_path, rcpts, body = _client.sendmail.call_args[0]
            body = body.split('\n')

            assert_equal(rcpts, ['*****@*****.**'])
            assert_in('Reply-To: %s' % g.noreply, body)

            # The address portion must not be encoded, only the name portion can be.
            # Also it is apparently not necessary to have the double-quote separators present
            # when the name portion is encoded.  That is, the encoding below is
            # just По and not "По"
            assert_in('From: =?utf-8?b?0J/Qvg==?= <*****@*****.**>', body)
            assert_in(
                'Subject: =?utf-8?b?0J/QviDQvtC20LjQstC70ZHQvdC90YvQvCDQsdC10YDQtdCz0LDQvA==?=',
                body)
            assert_in('Content-Type: text/plain; charset="utf-8"', body)
            assert_in('Content-Transfer-Encoding: base64', body)
            assert_in(b64encode(u'Громады стройные теснятся'.encode('utf-8')),
                      body)
Exemple #5
0
    def test_send_email_nonascii(self):
        with mock.patch.object(mail_tasks.smtp_client, '_client') as _client:
            mail_tasks.sendmail(
                fromaddr='"По" <*****@*****.**>',
                destinations=['*****@*****.**'],
                text='Громады стройные теснятся',
                reply_to=g.noreply,
                subject='По оживлённым берегам',
                message_id=h.gen_message_id())
            assert_equal(_client.sendmail.call_count, 1)
            return_path, rcpts, body = _client.sendmail.call_args[0]
            body = body.split('\n')

            assert_equal(rcpts, ['*****@*****.**'])
            assert_in('Reply-To: %s' % g.noreply, body)

            # The address portion must not be encoded, only the name portion can be.
            # Also py2 and py3 vary in handling of double-quote separators when the name portion is encoded
            unquoted_cyrillic_No = '=?utf-8?b?0J/Qvg==?='  # По
            quoted_cyrillic_No = '=?utf-8?b?ItCf0L4i?='  # "По"
            assert ('From: {} <*****@*****.**>'.format(quoted_cyrillic_No) in body or
                    'From: {} <*****@*****.**>'.format(unquoted_cyrillic_No) in body), body
            assert_in(
                'Subject: =?utf-8?b?0J/QviDQvtC20LjQstC70ZHQvdC90YvQvCDQsdC10YDQtdCz0LDQvA==?=', body)
            assert_in('Content-Type: text/plain; charset="utf-8"', body)
            assert_in('Content-Transfer-Encoding: base64', body)
            assert_in(six.ensure_text(b64encode('Громады стройные теснятся'.encode('utf-8'))), body)
Exemple #6
0
    def test_email_sender_to_headers(self):
        c.user = M.User.by_username('test-admin')
        with mock.patch.object(mail_tasks.smtp_client, '_client') as _client:
            mail_tasks.sendsimplemail(
                fromaddr=str(c.user._id),
                toaddr='*****@*****.**',
                text=u'This is a test',
                reply_to=g.noreply,
                subject=u'Test subject',
                sender=u'*****@*****.**',
                message_id=h.gen_message_id())
            assert_equal(_client.sendmail.call_count, 1)
            return_path, rcpts, body = _client.sendmail.call_args[0]
            body = body.split('\n')
            assert_in('From: "Test Admin" <*****@*****.**>', body)
            assert_in('Sender: [email protected]', body)
            assert_in('To: [email protected]', body)

            _client.reset_mock()
            mail_tasks.sendmail(
                fromaddr=str(c.user._id),
                destinations=[str(c.user._id)],
                text=u'This is a test',
                reply_to=u'*****@*****.**',
                subject=u'Test subject',
                sender=u'*****@*****.**',
                message_id=h.gen_message_id())
            assert_equal(_client.sendmail.call_count, 1)
            return_path, rcpts, body = _client.sendmail.call_args[0]
            body = body.split('\n')
            assert_in('From: "Test Admin" <*****@*****.**>', body)
            assert_in('Sender: [email protected]', body)
            assert_in('To: [email protected]', body)
Exemple #7
0
    def test_send_email_nonascii(self):
        with mock.patch.object(mail_tasks.smtp_client, '_client') as _client:
            mail_tasks.sendmail(
                fromaddr=u'"По" <*****@*****.**>',
                destinations=['*****@*****.**'],
                text=u'Громады стройные теснятся',
                reply_to=g.noreply,
                subject=u'По оживлённым берегам',
                message_id=h.gen_message_id())
            assert_equal(_client.sendmail.call_count, 1)
            return_path, rcpts, body = _client.sendmail.call_args[0]
            body = body.split('\n')

            assert_equal(rcpts, ['*****@*****.**'])
            assert_in('Reply-To: %s' % g.noreply, body)

            # The address portion must not be encoded, only the name portion can be.
            # Also it is apparently not necessary to have the double-quote separators present
            # when the name portion is encoded.  That is, the encoding below is
            # just По and not "По"
            assert_in('From: =?utf-8?b?0J/Qvg==?= <*****@*****.**>', body)
            assert_in(
                'Subject: =?utf-8?b?0J/QviDQvtC20LjQstC70ZHQvdC90YvQvCDQsdC10YDQtdCz0LDQvA==?=', body)
            assert_in('Content-Type: text/plain; charset="utf-8"', body)
            assert_in('Content-Transfer-Encoding: base64', body)
            assert_in(
                b64encode(u'Громады стройные теснятся'.encode('utf-8')), body)
Exemple #8
0
 def test_send_email_with_disabled_destination_user(self):
     c.user = M.User.by_username('test-admin')
     destination_user = M.User.by_username('test-user-1')
     destination_user.preferences['email_address'] = '*****@*****.**'
     destination_user.disabled = True
     ThreadLocalORMSession.flush_all()
     with mock.patch.object(mail_tasks.smtp_client, '_client') as _client:
         mail_tasks.sendmail(fromaddr=str(c.user._id),
                             destinations=[str(destination_user._id)],
                             text=u'This is a test',
                             reply_to=g.noreply,
                             subject=u'Test subject',
                             message_id=h.gen_message_id())
         assert_equal(_client.sendmail.call_count, 0)
Exemple #9
0
 def test_send_email_with_disabled_destination_user(self):
     c.user = M.User.by_username('test-admin')
     destination_user = M.User.by_username('test-user-1')
     destination_user.preferences['email_address'] = '*****@*****.**'
     destination_user.disabled = True
     ThreadLocalORMSession.flush_all()
     with mock.patch.object(mail_tasks.smtp_client, '_client') as _client:
         mail_tasks.sendmail(
             fromaddr=str(c.user._id),
             destinations=[str(destination_user._id)],
             text=u'This is a test',
             reply_to=g.noreply,
             subject=u'Test subject',
             message_id=h.gen_message_id())
         assert_equal(_client.sendmail.call_count, 0)
 def test_send_email_with_disabled_user(self):
     c.user = M.User.by_username('test-admin')
     c.user.disabled = True
     destination_user = M.User.by_username('test-user-1')
     destination_user.preferences['email_address'] = '*****@*****.**'
     ThreadLocalORMSession.flush_all()
     with mock.patch.object(mail_tasks.smtp_client, '_client') as _client:
         mail_tasks.sendmail(fromaddr=str(c.user._id),
                             destinations=[str(destination_user._id)],
                             text=u'This is a test',
                             reply_to=u'*****@*****.**',
                             subject=u'Test subject',
                             message_id=h.gen_message_id())
         assert_equal(_client.sendmail.call_count, 1)
         return_path, rcpts, body = _client.sendmail.call_args[0]
         body = body.split('\n')
         assert_in('From: [email protected]', body)
 def test_send_email_with_disabled_user(self):
     c.user = M.User.by_username('test-admin')
     c.user.disabled = True
     destination_user = M.User.by_username('test-user-1')
     destination_user.preferences['email_address'] = '*****@*****.**'
     ThreadLocalORMSession.flush_all()
     with mock.patch.object(mail_tasks.smtp_client, '_client') as _client:
         mail_tasks.sendmail(
             fromaddr=str(c.user._id),
             destinations=[ str(destination_user._id) ],
             text=u'This is a test',
             reply_to=u'*****@*****.**',
             subject=u'Test subject',
             message_id=h.gen_message_id())
         assert_equal(_client.sendmail.call_count, 1)
         return_path, rcpts, body = _client.sendmail.call_args[0]
         body = body.split('\n')
         assert_in('From: [email protected]', body)
    def test_send_email_ascii_with_user_lookup(self):
        c.user = M.User.by_username('test-admin')
        with mock.patch.object(mail_tasks.smtp_client, '_client') as _client:
            mail_tasks.sendmail(
                fromaddr=str(c.user._id),
                destinations=[ str(c.user._id) ],
                text=u'This is a test',
                reply_to=u'*****@*****.**',
                subject=u'Test subject',
                message_id=h.gen_message_id())
            assert_equal(_client.sendmail.call_count, 1)
            return_path, rcpts, body = _client.sendmail.call_args[0]
            body = body.split('\n')

            assert_equal(rcpts, [c.user.get_pref('email_address')])
            assert_in('Reply-To: [email protected]', body)
            assert_in('From: "Test Admin" <*****@*****.**>', body)
            assert_in('Subject: Test subject', body)
            # plain
            assert_in('This is a test', body)
            # html
            assert_in('<div class="markdown_content"><p>This is a test</p></div>', body)
Exemple #13
0
    def test_send_email_ascii_with_user_lookup(self):
        c.user = M.User.by_username('test-admin')
        with mock.patch.object(mail_tasks.smtp_client, '_client') as _client:
            mail_tasks.sendmail(
                fromaddr=str(c.user._id),
                destinations=[ str(c.user._id) ],
                text=u'This is a test',
                reply_to=u'*****@*****.**',
                subject=u'Test subject',
                message_id=h.gen_message_id())
            assert_equal(_client.sendmail.call_count, 1)
            return_path, rcpts, body = _client.sendmail.call_args[0]
            body = body.split('\n')

            assert_equal(rcpts, [c.user.get_pref('email_address')])
            assert_in('Reply-To: [email protected]', body)
            assert_in('From: "Test Admin" <*****@*****.**>', body)
            assert_in('Subject: Test subject', body)
            # plain
            assert_in('This is a test', body)
            # html
            assert_in('<div class="markdown_content"><p>This is a test</p></div>', body)
Exemple #14
0
def clone(
    cloned_from_path,
    cloned_from_name,
    cloned_from_url,
    copy_hooks=False):
    try:
        from allura import model as M
        c.app.repo.init_as_clone(
            cloned_from_path,
            cloned_from_name,
            cloned_from_url,
            copy_hooks)
        M.Notification.post_user(
            c.user, c.app.repo, 'created',
            text='Repository %s/%s created' % (
                c.project.shortname, c.app.config.options.mount_point))
        if not c.project.suppress_emails:
            sendmail(
                destinations=[str(c.user._id)],
                fromaddr=u'SourceForge.net <*****@*****.**>',
                reply_to=u'*****@*****.**',
                subject=u'SourceForge Repo Clone Complete',
                message_id=h.gen_message_id(),
                text=u''.join([
                    u'Your cloned repository %s in project %s is now ready for use.\n\n',
                    u'Old repository url: %s \n\n',
                    u'New repository checkout command: %s \n\n',
                    u'You and any other developers should do a fresh checkout using the ',
                    u'new repository location.\n'
                ]) % (c.app.config.options.mount_point, c.project.shortname, cloned_from_url, c.app.repo.clone_command('rw')))
    except:
        sendmail(
            destinations=['*****@*****.**'],
            fromaddr=u'SourceForge.net <*****@*****.**>',
            reply_to=u'*****@*****.**',
            subject=u'SourceForge Repo Clone Failure',
            message_id=h.gen_message_id(),
            text=u''.join([
                u'Forking/cloning repo %s in project %s from %s failed.\n',
                u'\n',
                u'%s',
            ]) % (c.app.config.options.mount_point, c.project.shortname, cloned_from_url, traceback.format_exc()))
        if not c.project.suppress_emails:
            sendmail(
                destinations=[str(c.user._id)],
                fromaddr=u'SourceForge.net <*****@*****.**>',
                reply_to=u'*****@*****.**',
                subject=u'SourceForge Repo Clone Failed',
                message_id=h.gen_message_id(),
                text=u''.join([
                    u'Forking/cloning repo %s in project %s from %s failed. ',
                    u'The SourceForge engineering team has been notified.\n',
                ]) % (c.app.config.options.mount_point, c.project.shortname, cloned_from_url))