Last active
August 29, 2015 14:04
-
-
Save rtmca/3bde536433a0a8917372 to your computer and use it in GitHub Desktop.
POP3Reader for Sinfonier
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 | |
# -*- coding: utf-8 -*- | |
""" | |
The MIT License (MIT) | |
Copyright (c) 2014 sinfonier-project | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in | |
all copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
THE SOFTWARE. | |
""" | |
import poplib | |
import basesinfonierspout | |
import json | |
class POP3Reader(basesinfonierspout.BaseSinfonierSpout): | |
def __init__(self): | |
basesinfonierspout.BaseSinfonierSpout().__init__() | |
self.emailList = [] | |
def useropen(self): | |
self.pop3_server = self.getParam("pop3_server"); | |
self.email = self.getParam("pop3_email"); | |
self.password = self.getParam("pop3_password"); | |
Mailbox = poplib.POP3_SSL(self.pop3_server, '995') | |
Mailbox.user(self.email) | |
Mailbox.pass_(self.password) | |
self.emailList = [] | |
numMessages = len(Mailbox.list()[1]) | |
for i in range(numMessages): | |
emailList.append(Mailbox.retr(i+1)[1]) | |
Mailbox.quit() | |
def usernextTuple(self): | |
try: | |
json = "{\"emails\": [ " | |
first = True | |
for email in emailList: | |
if not first: | |
json = json + "," | |
first = False | |
json = json + "{\"data\": "+email+"}" | |
json = json + "]}" | |
self.setJson(json) | |
self.emit() | |
except StopIteration: | |
pass | |
POP3Reader.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment