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='******',
            )
Example #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]))
Example #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]))
Example #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"
}""")
Example #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```"
}""")
Example #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))
Example #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 |"
}""")
Example #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"
}""")
Example #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"
}""")
Example #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"
}""")
Example #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"
}""")
Example #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))
Example #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": "******"
}""")
Example #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": "******"
}""")
Example #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": ""
}""")
Example #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": ""
}""")
Example #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": ""
}""")
Example #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"
}""")
Example #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": ""
}""")
Example #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')
Example #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')
Example #22
0
 def test_send(self, mock_post):
     payload = mattersend.send(channel='town-square',
                               message='test message',
                               url='http://chat.net/hooks/abdegh12')
Example #23
0
 def test_send(self, mock_post):
     payload = mattersend.send(channel='town-square',
                               message='test message',
                               url='http://chat.net/hooks/abdegh12')