Last active
December 7, 2015 15:10
-
-
Save ssplatt/4e4ec1b19050eaf1f272 to your computer and use it in GitHub Desktop.
push local mailbox mail to zulip
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import zulip | |
import mailbox | |
client = zulip.Client(email="[email protected]", | |
api_key="111222aaabbb", | |
site="https://zulip.server.tld/api/") | |
mailbox_loc = '/var/mail/user' | |
inbox = mailbox.mbox(mailbox_loc) | |
for key in inbox.iterkeys(): | |
try: | |
message = inbox[key] | |
except: | |
continue | |
content = "" | |
content += "To: {}".format(message['to']) | |
content += "\nFrom: {}".format(message['from']) | |
content += "\nSubject: {}".format(message['subject']) | |
if message.is_multipart(): | |
for payload in message.get_payload(): | |
content += "\nBody: {}".format(payload.get_payload()) | |
else: | |
content += "\nBody: {}".format(message.get_payload()) | |
# Send a stream message | |
client.send_message({ | |
"type": "stream", | |
"to": "channel", | |
"subject": "email", | |
"content": content | |
}) | |
# Remove original message | |
inbox.lock() | |
inbox.discard(key) | |
inbox.flush() | |
inbox.unlock() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment