diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/leap/bitmask/cli/mail.py | 29 | ||||
-rw-r--r-- | src/leap/bitmask/core/dispatcher.py | 12 | ||||
-rw-r--r-- | src/leap/bitmask/core/mail_services.py | 17 |
3 files changed, 56 insertions, 2 deletions
diff --git a/src/leap/bitmask/cli/mail.py b/src/leap/bitmask/cli/mail.py index b6d6cd1..933f72a 100644 --- a/src/leap/bitmask/cli/mail.py +++ b/src/leap/bitmask/cli/mail.py @@ -35,6 +35,7 @@ SUBCOMMANDS: disable Stop service status Display status about service get_token Returns token for the mail service + add_msg Add a msg file to a mailbox '''.format(name=command.appname) @@ -74,6 +75,34 @@ SUBCOMMANDS: return self._send(command.default_dict_printer) + def add_msg(self, raw_args): + parser = argparse.ArgumentParser( + description='Bitmask email status', + prog='%s %s %s' % tuple(sys.argv[:3])) + parser.add_argument('-u', '--userid', default='', + help='Select the userid of the mail') + parser.add_argument('-m', '--mailbox', default='', + help='Select the mailbox to add the email') + parser.add_argument('file', nargs=1, + help='file where the mail is stored') + subargs = parser.parse_args(raw_args) + + if subargs.userid: + userid = subargs.userid + else: + userid = self.cfg.get('bonafide', 'active', default=None) + + mailbox = '' + if subargs.mailbox: + mailbox = subargs.mailbox + + with open(subargs.file[0], 'r') as msgfile: + rawmsg = msgfile.read() + + self.data += ['add_msg', userid, mailbox, rawmsg] + + return self._send(command.default_dict_printer) + def mixnet_status(self, raw_args): parser = argparse.ArgumentParser( description='Bitmask mixnet status', diff --git a/src/leap/bitmask/core/dispatcher.py b/src/leap/bitmask/core/dispatcher.py index 1e364ec..508a925 100644 --- a/src/leap/bitmask/core/dispatcher.py +++ b/src/leap/bitmask/core/dispatcher.py @@ -282,6 +282,18 @@ class MailCmd(SubCommand): d = mail.do_mixnet_status(userid, address) return d + @register_method('dict') + def do_ADD_MSG(self, mail, *parts, **kw): + try: + userid = parts[2] + mailbox = parts[3] + msg = parts[4] + except IndexError: + raise DispatchError( + 'wrong number of arguments: expected 3, got none') + d = mail.do_add_msg(userid, msg, mailbox) + return d + class WebUICmd(SubCommand): diff --git a/src/leap/bitmask/core/mail_services.py b/src/leap/bitmask/core/mail_services.py index 043f848..584aa8b 100644 --- a/src/leap/bitmask/core/mail_services.py +++ b/src/leap/bitmask/core/mail_services.py @@ -614,6 +614,16 @@ class StandardMailService(service.MultiService, HookableService): token = self._service_tokens.get(userid) return {'user': userid, 'token': token} + def do_add_msg(self, userid, raw_msg, mailbox=None): + if not mailbox: + mailbox = INBOX_NAME + + account = self._get_account(userid) + d = account.get_collection_by_mailbox(mailbox) + d.addCallback(lambda collection: collection.add_msg(raw_msg)) + d.addCallback(lambda _: {'added': True}) + return d + # access to containers def get_soledad_session(self, userid): @@ -642,13 +652,16 @@ class StandardMailService(service.MultiService, HookableService): json.dump(token_dict, ftokens) def _maybe_start_pixelated(self, passthrough, userid, soledad, keymanager): - incoming = self.getServiceNamed('incoming_mail') - account = incoming.getServiceNamed(userid).account + account = self._get_account(userid) if HAS_MUA and pixelizer.HAS_PIXELATED: pixelizer.start_pixelated_user_agent( userid, soledad, keymanager, account) return passthrough + def _get_account(self, userid): + incoming = self.getServiceNamed('incoming_mail') + return incoming.getServiceNamed(userid).account + class IMAPService(service.Service): |