summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKali Kaneko <kali@futeisha.org>2015-02-05 10:46:57 -0400
committerdrebs <drebs@leap.se>2015-02-05 13:20:02 -0200
commit91404f56d200ba01130ff208169d45f615f8a094 (patch)
treed0d1f15a5ab19b023990257b07871b578cf589e4
parente660453542889fc8285217f008803c9701f1b778 (diff)
Add ability to trigger processing on SIGUSR1 (Related: #2591)
-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