This repository has been archived by the owner on Jul 11, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Enable email-comments #521
Open
Dekue
wants to merge
24
commits into
liqd:develop
Choose a base branch
from
Dekue:develop
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 18 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
417f60a
update
Dekue 29c8bc0
update
Dekue 23d54fa
Merge branch 'develop' of https://github.com/Dekue/adhocracy.git into…
Dekue 66b06e2
enables comments via email
Dekue 929cb46
enables comments via email
Dekue b7f80f3
Delete adhocracy
Dekue 99fef80
sinks-update for better view of notification emails about new comments
Dekue 7bd647e
Merge branch 'develop' of https://github.com/Dekue/adhocracy.git into…
Dekue 114f243
Update sinks.py
Dekue 29e829a
Update sinks.py
Dekue 974783d
Update localwatch.py
Dekue f1b5313
Update util.py
Dekue 8e94887
Deleted Ddebris function completely. Had no use.
Dekue 305a6eb
Updated notification info for email-comment replies
Dekue 1109a8e
Checks if the same comment was posted by the same user to the same topic
Dekue 7ff76f2
Merge branch 'develop' of https://github.com/Dekue/adhocracy.git into…
Dekue deffe82
updated secret-usage; reintegrated derbis function vor comparison
Dekue 235f9df
deleted useless import
Dekue d703e8f
Added IMAP-reconnetion if connection was lost, changed
Dekue b85cfd5
enhanced functions for MUAs: remove notification-quote + updated tests
Dekue f9bb5d0
FIX: crypto secret reenabled
Dekue 1fe5bbe
Update parseincoming.py
Dekue 58f9a70
Voting now works in HTML-messages.
Dekue 1df28b2
bug-fixes for voting, HTML-headings, images in emails with signatures
Dekue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,6 +102,17 @@ use = egg:adhocracy | |
full_stack = true | ||
static_files = true | ||
|
||
# INSTALL: To enable set email_src to 'local' or 'imap', IMAP-SSL is essential. | ||
# If 'imap_account = user' fails, try complete address: '[email protected]'. | ||
# Set local_user to determine the mbox/Maildir-folders you want to watch. | ||
email_src = none | ||
local_user = user | ||
imap_domain = imap.emailprovider.tld | ||
imap_account = user | ||
imap_password = password | ||
imap_directory = inbox | ||
imap_port = 993 | ||
|
||
cache_dir = ${parts.buildout.directory}/var/data | ||
beaker.session.key = adhocracy_state | ||
{% python | ||
|
@@ -465,4 +476,4 @@ format = %(asctime)s %(levelname)-5.5s [%(name)s] %(message)s | |
# Custom OVERRIDE adhocracy settings | ||
############################################################## | ||
|
||
${parts.adhocracy['settings_override']} | ||
${parts.adhocracy['settings_override']} |
This file contains 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
Submodule buildout.python
deleted from
44b473
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import os | ||
from pylons import config | ||
import getpass | ||
import logging | ||
import Queue | ||
from sqlalchemy.orm import sessionmaker, scoped_session | ||
from adhocracy.model import meta | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def mail_watch(): | ||
''' | ||
This is a script executed by the adhocracy emailcommentworker | ||
Its target is to listen to new mails (Maildir and mbox or IMAP) | ||
and identify if they are comment replies. If so the jobs | ||
will be executed in a queue. | ||
''' | ||
esrc = config.get("email_src") | ||
|
||
if esrc == "imap" or esrc == "local": | ||
ecq = Queue.Queue() | ||
|
||
Session = sessionmaker(bind=meta.engine, autoflush=True) | ||
meta.Session = scoped_session(Session) | ||
|
||
from adhocracy.lib.emailcomments import parseincoming | ||
if esrc == "imap": | ||
from adhocracy.lib.emailcomments import imap | ||
idler = imap.Idler(ecq) | ||
idler.start() | ||
elif esrc == "local": | ||
from adhocracy.lib.emailcomments import localwatch | ||
username = config.get("local_user") | ||
if not username: | ||
log.error("no user set in config") | ||
log.info("emailcomments are disabled") | ||
return | ||
if username: | ||
path_md = os.path.join("/home", username, "Maildir") | ||
path_mb = os.path.join("/var/mail", username) | ||
if os.path.exists("/usr/include/linux/inotify.h"): | ||
if util.create_filesystem(path_md): | ||
localwatch.watch_new_mail(path_md, path_mb, ecq) | ||
else: | ||
return | ||
else: | ||
log.error("kernel module inotify is not installed") | ||
log.info("emailcomments are disabled") | ||
return | ||
else: | ||
log.error("user cannot be determined") | ||
log.info("emailcomments are disabled") | ||
return | ||
|
||
while True: | ||
message = ecq.get() | ||
parseincoming.handle_inc_mail(message) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import imaplib2 | ||
import email | ||
from email.parser import HeaderParser | ||
import os | ||
import logging | ||
import threading | ||
import time | ||
from pylons import config | ||
from adhocracy.lib.emailcomments import util | ||
from adhocracy.lib import queue | ||
|
||
# cfg | ||
IMAP_DOMAIN = config.get('imap_domain') | ||
IMAP_USERNAME = config.get('imap_account') | ||
IMAP_PASSWORD = config.get('imap_password') | ||
COMMENTS_DIR = config.get('imap_directory') | ||
IMAP_PORT = config.get('imap_port') | ||
MAX_INTERVAL = 60 * 64 # max. reconnect-interval (seconds - 60 * 2^n possible) | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class Idler(threading.Thread): | ||
|
||
def __init__(self, ecq): | ||
threading.Thread.__init__(self) | ||
self.ecq = ecq | ||
|
||
def run(self): | ||
'''(re)connects to IMAP and waits for new mail''' | ||
recon_interval = 30 | ||
while True: | ||
try: | ||
self.conn = imaplib2.IMAP4_SSL(IMAP_DOMAIN, IMAP_PORT) | ||
self.conn.login(IMAP_USERNAME, IMAP_PASSWORD) | ||
self.conn.select(COMMENTS_DIR) | ||
except Exception as e: | ||
log.info("IMAP-connection could not be established because:") | ||
log.info(e) | ||
if recon_interval < MAX_INTERVAL: | ||
recon_interval = recon_interval * 2 | ||
minutes = recon_interval / 60 | ||
log.info("reconnect in {0} minute(s)".format(minutes)) | ||
time.sleep(recon_interval) | ||
continue | ||
|
||
recon_interval = 30 | ||
|
||
while True: | ||
try: | ||
self.dosync() | ||
self.conn.idle() | ||
except self.conn.abort: | ||
log.info("IMAP-connection lost, reconnecting...") | ||
|
||
def dosync(self): | ||
'''executed if a new mail arrives''' | ||
typ, data = self.conn.search(None, 'UNSEEN') | ||
if data[0]: | ||
for num in data[0].split(): | ||
typ, data = self.conn.fetch(num, '(RFC822)') | ||
header_data = data[0][1] | ||
parser = HeaderParser() | ||
message = parser.parsestr(header_data) | ||
log.info("new IMAP mail") | ||
self.ecq.put(message) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This just outputs the reconnecting message. Is it actually reconnecting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like I missed to add a
break
to the while loop due to rare occurences of lost connections in testing. Will change that.