Exemplo n.º 1
0
    def process_message(self, peer, mailfrom, rcpttos, data):
        logging.info("Receiving message from {} to {}".format(
            mailfrom, rcpttos))
        email = Parser().parsestr(data)

        for name, cfg in self.inboxes.items():
            address = cfg['address']
            if not address in rcpttos: continue

            message = '**From:** {frm}\n**To:** {to}\n**Subject:** {subject}\n{body}'.format(
                frm=email['From'] or mailfrom,
                to=email['To'] or ', '.join(rcpttos),
                subject=email['Subject'],
                body=data)

            url = cfg['url']

            logging.info(
                "Matched address {}; Sending message to webhook {}".format(
                    address, url))
            mattersend.send(
                channel=None,
                message=message,
                url=url,
                username='******',
            )
Exemplo n.º 2
0
    def test_fileinfo(self):
        payload = mattersend.send(channel='town-square',
                                  filename='/home/test/source.coffee',
                                  fileinfo=True,
                                  just_return=True)

        content = r"```coffeescript\n%s```" % ('x' * 5000,)
        self.assertEqual(normalize_payload(payload),
                         r"""POST https://chat.mydomain.com/hooks/abcdefghi123456
{
    "attachments": [
        {
            "fallback": "%s",
            "fields": [
                {
                    "short": true,
                    "title": "Size",
                    "value": "4.9KiB"
                },
                {
                    "short": true,
                    "title": "Mime",
                    "value": "None"
                }
            ],
            "text": "%s",
            "title": "source.coffee"
        }
    ],
    "channel": "town-square",
    "text": ""
}""" % (content[:3501], content[:3501]))
Exemplo n.º 3
0
    def test_fileinfo(self):
        payload = mattersend.send(channel='town-square',
                                  filename='/home/test/source.coffee',
                                  fileinfo=True,
                                  just_return=True)

        content = r"```coffeescript\n%s```" % ('x' * 5000, )
        self.assertEqual(
            normalize_payload(payload),
            r"""POST https://chat.mydomain.com/hooks/abcdefghi123456
{
    "attachments": [
        {
            "fallback": "%s",
            "fields": [
                {
                    "short": true,
                    "title": "Size",
                    "value": "4.9KiB"
                },
                {
                    "short": true,
                    "title": "Mime",
                    "value": "None"
                }
            ],
            "text": "%s",
            "title": "source.coffee"
        }
    ],
    "channel": "town-square",
    "text": ""
}""" % (content[:3501], content[:3501]))
Exemplo n.º 4
0
    def test_simple_1(self):
        payload = mattersend.send(channel='town-square',
                                  message='test message',
                                  just_return=True)

        self.assertEqual(normalize_payload(payload),
                         r"""POST https://chat.mydomain.com/hooks/abcdefghi123456
{
    "channel": "town-square",
    "text": "test message"
}""")
Exemplo n.º 5
0
    def test_syntax_by_mime(self):
        payload = mattersend.send(channel='town-square',
                                  filename='/home/test/source.diff',
                                  just_return=True)

        self.assertEqual(normalize_payload(payload),
                         r"""POST https://chat.mydomain.com/hooks/abcdefghi123456
{
    "channel": "town-square",
    "text": "```diff\n```"
}""")
Exemplo n.º 6
0
    def test_syntax_by_ext(self):
        payload = mattersend.send(channel='town-square',
                                  filename='/home/test/source.coffee',
                                  just_return=True)

        self.assertEqual(normalize_payload(payload),
                         r"""POST https://chat.mydomain.com/hooks/abcdefghi123456
{
    "channel": "town-square",
    "text": "```coffeescript\n%s```"
}""" % ('x' * 5000))
Exemplo n.º 7
0
    def test_csv_dialect(self):
        payload = mattersend.send(channel='town-square',
                                  filename='/home/test/source.csv',
                                  tabular='excel',
                                  just_return=True)

        self.assertEqual(normalize_payload(payload),
                         r"""POST https://chat.mydomain.com/hooks/abcdefghi123456
{
    "channel": "town-square",
    "text": "| abc | def |\n| --- | --- |\n| foo | bar |"
}""")
Exemplo n.º 8
0
    def test_override_url(self):
        payload = mattersend.send(channel='town-square',
                                  message='test message',
                                  url='http://chat.net/hooks/abdegh12',
                                  just_return=True)

        self.assertEqual(normalize_payload(payload),
                         r"""POST http://chat.net/hooks/abdegh12
{
    "channel": "town-square",
    "text": "test message"
}""")
Exemplo n.º 9
0
    def test_filename_and_message(self):
        payload = mattersend.send(channel='town-square',
                                  filename='/etc/mime.types',
                                  message='test message',
                                  just_return=True)

        self.assertEqual(normalize_payload(payload),
                         r"""POST https://chat.mydomain.com/hooks/abcdefghi123456
{
    "channel": "town-square",
    "text": "test message\n\ntext/x-diff diff"
}""")
Exemplo n.º 10
0
    def test_override_url(self):
        payload = mattersend.send(channel='town-square',
                                  message='test message',
                                  url='http://chat.net/hooks/abdegh12',
                                  just_return=True)

        self.assertEqual(
            normalize_payload(payload), r"""POST http://chat.net/hooks/abdegh12
{
    "channel": "town-square",
    "text": "test message"
}""")
Exemplo n.º 11
0
    def test_simple_1(self):
        payload = mattersend.send(channel='town-square',
                                  message='test message',
                                  just_return=True)

        self.assertEqual(
            normalize_payload(payload),
            r"""POST https://chat.mydomain.com/hooks/abcdefghi123456
{
    "channel": "town-square",
    "text": "test message"
}""")
Exemplo n.º 12
0
    def test_fileinfo(self):
        payload = mattersend.send(channel='town-square',
                                  filename='/home/test/source.coffee',
                                  fileinfo=True,
                                  just_return=True)

        self.assertEqual(normalize_payload(payload),
                         r"""POST https://chat.mydomain.com/hooks/abcdefghi123456
{
    "channel": "town-square",
    "text": "| Filename | Size | Mime |\n| --- | --- | --- |\n| source.coffee | 4.9KiB | None |\n\n```coffeescript\n%s```"
}""" % ('x' * 5000))
Exemplo n.º 13
0
    def test_section(self):
        payload = mattersend.send(channel='town-square',
                                  message='test message',
                                  config_section='angrybot',
                                  just_return=True)

        self.assertEqual(normalize_payload(payload),
                         r"""POST https://chat.mydomain.com/hooks/abcdefghi123456
{
    "channel": "town-square",
    "icon_url": "https://chat.mydomain.com/static/emoji/1f620.png",
    "text": "test message",
    "username": "******"
}""")
Exemplo n.º 14
0
    def test_section(self):
        payload = mattersend.send(channel='town-square',
                                  message='test message',
                                  config_section='angrybot',
                                  just_return=True)

        self.assertEqual(
            normalize_payload(payload),
            r"""POST https://chat.mydomain.com/hooks/abcdefghi123456
{
    "channel": "town-square",
    "icon_url": "https://chat.mydomain.com/static/emoji/1f620.png",
    "text": "test message",
    "username": "******"
}""")
Exemplo n.º 15
0
    def test_syntax_mk(self):
        payload = mattersend.send(channel='town-square',
                                  filename='/home/test/Makefile',
                                  just_return=True)

        self.assertEqual(normalize_payload(payload),
                         r"""POST https://chat.mydomain.com/hooks/abcdefghi123456
{
    "attachments": [
        {
            "fallback": "```makefile\n```",
            "text": "```makefile\n```",
            "title": "Makefile"
        }
    ],
    "channel": "town-square",
    "text": ""
}""")
Exemplo n.º 16
0
    def test_syntax_mk(self):
        payload = mattersend.send(channel='town-square',
                                  filename='/home/test/Makefile',
                                  just_return=True)

        self.assertEqual(
            normalize_payload(payload),
            r"""POST https://chat.mydomain.com/hooks/abcdefghi123456
{
    "attachments": [
        {
            "fallback": "```makefile\n```",
            "text": "```makefile\n```",
            "title": "Makefile"
        }
    ],
    "channel": "town-square",
    "text": ""
}""")
Exemplo n.º 17
0
    def test_csv(self):
        payload = mattersend.send(channel='town-square',
                                  filename='/home/test/source.csv',
                                  tabular='sniff',
                                  just_return=True)

        self.assertEqual(normalize_payload(payload),
                         r"""POST https://chat.mydomain.com/hooks/abcdefghi123456
{
    "attachments": [
        {
            "fallback": "| abc | def |\n| --- | --- |\n| foo | bar |",
            "text": "| abc | def |\n| --- | --- |\n| foo | bar |",
            "title": "source.csv"
        }
    ],
    "channel": "town-square",
    "text": ""
}""")
Exemplo n.º 18
0
    def test_filename_and_message(self):
        payload = mattersend.send(channel='town-square',
                                  filename='/etc/mime.types',
                                  message='test message',
                                  just_return=True)

        self.assertEqual(
            normalize_payload(payload),
            r"""POST https://chat.mydomain.com/hooks/abcdefghi123456
{
    "attachments": [
        {
            "fallback": "text/x-diff diff",
            "text": "text/x-diff diff",
            "title": "mime.types"
        }
    ],
    "channel": "town-square",
    "text": "test message"
}""")
Exemplo n.º 19
0
    def test_csv_dialect(self):
        payload = mattersend.send(channel='town-square',
                                  filename='/home/test/source.csv',
                                  tabular='excel',
                                  just_return=True)

        self.assertEqual(
            normalize_payload(payload),
            r"""POST https://chat.mydomain.com/hooks/abcdefghi123456
{
    "attachments": [
        {
            "fallback": "| abc | def |\n| --- | --- |\n| foo | bar |",
            "text": "| abc | def |\n| --- | --- |\n| foo | bar |",
            "title": "source.csv"
        }
    ],
    "channel": "town-square",
    "text": ""
}""")
Exemplo n.º 20
0
 def test_send(self, mock_post):
     with self.assertRaises(RuntimeError):
         payload = mattersend.send(channel='town-square',
                                   message='test message',
                                   url='http://chat.net/hooks/fail')
Exemplo n.º 21
0
 def test_send(self, mock_post):
     with self.assertRaises(RuntimeError):
         payload = mattersend.send(channel='town-square',
                                   message='test message',
                                   url='http://chat.net/hooks/fail')
Exemplo n.º 22
0
 def test_send(self, mock_post):
     payload = mattersend.send(channel='town-square',
                               message='test message',
                               url='http://chat.net/hooks/abdegh12')
Exemplo n.º 23
0
 def test_send(self, mock_post):
     payload = mattersend.send(channel='town-square',
                               message='test message',
                               url='http://chat.net/hooks/abdegh12')