summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKali Kaneko <kali@futeisha.org>2015-02-05 10:46:57 -0400
committerKali Kaneko <kali@futeisha.org>2015-02-11 11:57:10 -0400
commit26662f2a713a96f22884601801d466a06e309cb2 (patch)
treedd86347bdec5a632c716a4dcfb6342396ebe8a71 /src
parent32ad66e33bac3f8105b5898fdeff33a74a7e2974 (diff)
Add ability to trigger processing on SIGUSR1 (Related: #2591)
Diffstat (limited to 'src')
-rw-r--r--src/leap/mx/mail_receiver.py28
1 files changed, 22 insertions, 6 deletions
diff --git a/src/leap/mx/mail_receiver.py b/src/leap/mx/mail_receiver.py
index 2d91fda..5fa3863 100644
--- a/src/leap/mx/mail_receiver.py
+++ b/src/leap/mx/mail_receiver.py
@@ -15,9 +15,13 @@
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
"""
-MailReceiver service definition
+MailReceiver service definition. This service monitors the incoming mail and
+process it.
+
+The MailReceiver service is configured to process incoming any skipped mail
+every half an hour, and also on service start. It can be forced to start
+processing by sending SIGUSR1 to the process.
If there's a user facing problem when processing an email, it will be
bounced back to the sender.
@@ -29,9 +33,9 @@ User facing problems could be:
Any other problem is a bug, which will be logged. Until the bug is
fixed, the email will stay in there waiting.
"""
-
import os
import uuid as pyuuid
+import signal
import json
import email.utils
@@ -43,10 +47,12 @@ from email.MIMEText import MIMEText
from email.Utils import formatdate
from email.header import decode_header
-from twisted.application.service import Service
+from twisted.application.service import Service, IService
from twisted.internet import inotify, defer, task, reactor
from twisted.python import filepath, log
+from zope.interface import implements
+
from leap.soledad.common.crypto import (
EncryptionSchemes,
ENC_JSON_KEY,
@@ -129,8 +135,9 @@ def async_check_output(args, msg):
class MailReceiver(Service):
"""
- Service that monitors incoming email and processes it
+ Service that monitors incoming email and processes it.
"""
+ implements(IService)
INCOMING_KEY = 'incoming'
ERROR_DECRYPTING_KEY = "errdecr"
@@ -144,13 +151,17 @@ class MailReceiver(Service):
:param mail_couch_url: URL prefix for the couchdb where mail
should be stored
:type mail_couch_url: str
+
:param users_cdb: CouchDB instance from where to get the uuid
- and pubkey for a user
+ and pubkey for a user
:type users_cdb: ConnectedCouchDB
+
:param directories: list of directories to monitor
:type directories: list of tuples (path: str, recursive: bool)
+
:param bounce_from: Email address of the bouncer
:type bounce_from: str
+
:param bounce_subject: Subject line used in the bounced mail
:type bounce_subject: str
"""
@@ -164,6 +175,11 @@ class MailReceiver(Service):
self._bounce_from = bounce_from
self._bounce_subject = bounce_subject
+ def _signal_handler(sig_num, stack_frame):
+ self._process_skipped()
+
+ signal.signal(signal.SIGUSR1, _signal_handler)
+
def startService(self):
"""
Starts the MailReceiver service