예제 #1
0
    def dispatch(self, data):
        """Parses an :emacs-rex command an returns lisp response."""
        command, form, package, thread, rid = read_lisp(data)
        self.package = package
        self.thread = thread
        self.id = rid
        # form is the lisp espression

        fn = form[0]
        args = form[1:]
        method_name = fn.replace(":", "_").replace("-", "_")
        logging.debug(method_name)
        logging.debug(args)
        for i, arg in enumerate(args):
            if hasattr(arg, 'unquote'):
                args[i] = arg.unquote()
        try:
            response = [
                symbol(":return"), {
                    ":ok": getattr(self, method_name)(*args)
                }, self.id
            ]
        except Exception as e:
            return write_lisp(
                [symbol(":debug"), 0, 1, [e, False], [], [], self.id])
        lisp_response = write_lisp(response)
        header = "{0:06x}".format(len(lisp_response))
        return header + lisp_response
예제 #2
0
    def get_mail_body(self, uid):
        import errno
        import exceptions

        status, items = self.connection.uid("FETCH", uid,
                                            '(FLAGS INTERNALDATE RFC822)')
        #print >>sys.stderr, "items", items

        text = items[0]

        number_flags_date_syntax, body = text

        #print >>sys.stderr, ">>>%s<<<" % number_flags_date_syntax

        if number_flags_date_syntax.find(r"\Deleted") > -1:  # speedup
            # "1848 (FLAGS (\Seen \Deleted) INTERNALDATE "25-May-2007 17:08:58 +0200" RFC822 {4118669}"
            flags_text = number_flags_date_syntax[:number_flags_date_syntax.rfind(
                "{")] + " \"\")"  # replace body by something small

            print >> sys.stderr, "flags_text", flags_text

            items = parse_flags(flags_text)
            flags = items[lisp.symbol("FLAGS")]
            if lisp.symbol("Deleted") in flags:
                raise exceptions.IOError(
                    errno.ENOENT, "No such file or directory 'uid#%s'" % uid)

        # ('47 (FLAGS (\\Seen) INTERNALDATE "11-Apr-2007 13:11:23 +0200" RFC822 {12482}',
        #'X-MimeOLE: Produced By Microsoft Exchange V6.5\r\nReceived: by FABAMAIL.fabagl.fabasoft.com \r\n\tid <*****@*****.**>;
        #print "---"
        #for item in items:
        return body
예제 #3
0
 def dispatch(self, data):
     """Parses an :emacs-rex command an returns lisp response."""
     command, form, package, thread, rid = read_lisp(data)
     self.package = package;
     self.thread = thread;
     self.id = rid;
     fn = form[0];
     args = form[1:]
     method_name = fn.replace(":", "_").replace("-", "_")
     logger.debug(method_name)
     logger.debug(args)
     for i, arg in enumerate(args):
         if hasattr(arg, 'unquote'):
             args[i] = arg.unquote()
     try:
         response = [
             symbol(":return"),
             {":ok": getattr(self, method_name)(*args)},
             self.id
         ]
     except Exception as e:
         return [
             symbol(":debug"), 0, 1,
             [e, False],
             [],
             [],
             self.id
         ]
     lisp_response = write_lisp(response)
     header = "{0:06x}".format(len(lisp_response))
     return header + lisp_response
예제 #4
0
파일: niceimap.py 프로젝트: dannymi/IMAPFS
    def get_mail_body(self, uid):
        import errno
        import exceptions

        status, items = self.connection.uid("FETCH", uid, "(FLAGS INTERNALDATE RFC822)")
        # print >>sys.stderr, "items", items

        text = items[0]

        number_flags_date_syntax, body = text

        # print >>sys.stderr, ">>>%s<<<" % number_flags_date_syntax

        if number_flags_date_syntax.find(r"\Deleted") > -1:  # speedup
            # "1848 (FLAGS (\Seen \Deleted) INTERNALDATE "25-May-2007 17:08:58 +0200" RFC822 {4118669}"
            flags_text = (
                number_flags_date_syntax[: number_flags_date_syntax.rfind("{")] + ' "")'
            )  # replace body by something small

            print >> sys.stderr, "flags_text", flags_text

            items = parse_flags(flags_text)
            flags = items[lisp.symbol("FLAGS")]
            if lisp.symbol("Deleted") in flags:
                raise exceptions.IOError(errno.ENOENT, "No such file or directory 'uid#%s'" % uid)

                # ('47 (FLAGS (\\Seen) INTERNALDATE "11-Apr-2007 13:11:23 +0200" RFC822 {12482}',
                #'X-MimeOLE: Produced By Microsoft Exchange V6.5\r\nReceived: by FABAMAIL.fabagl.fabasoft.com \r\n\tid <*****@*****.**>;
                # print "---"
                # for item in items:
        return body
예제 #5
0
    def get_mail_envelope(self, uid):  # SLOOOW
        #print >>sys.stderr, "get_mail_envelope UID", uid
        items = None
        if self.current_directory_contents is not None and uid in self.current_directory_contents:
            items_cachetime, items = self.current_directory_contents[
                uid]  # [x for x in self.current_directory_contents if x[lisp.symbol("UID")] == uid]

            if time.time() - items_cachetime >= timeout.timeout:  # too old
                items = None

        #items = None # FIXME

        for i in range(3):
            if items is None or items == []:  # FIXME the latter is weird... and not necessary anymore
                status, items = self.connection.uid(
                    "FETCH", uid, '(UID ENVELOPE RFC822.SIZE FLAGS)')
                #f = file("/tmp/uid-%s" % uid, "w")
                #import pickle
                #pickle.dump(items, f) # FIXME FIXME
                #f.close()

                items = [x for x in parse_items(items, True)]
                if items == []:  # weird, give it some time
                    time.sleep(1)
                else:
                    items = items[0]
                    break

        if items == []:  # not found
            raise exceptions.LookupError(
                "message with UID %s not found in mailbox \"%s\"" %
                (uid, self.current_directory))

        #print >>sys.stderr, "items ENV", items
        uid = items[lisp.symbol("UID")]
        size = items[lisp.symbol("RFC822.SIZE")]
        envelope = items[lisp.symbol("ENVELOPE")]
        flags = items[lisp.symbol("FLAGS")]
        """[
			'Wed, 10 Jan 2007 18:16:22 +0200', 
			'Some subject', 
			[['Long, Name', [], 'Silvio.Ziegelwanger', 'fabalabs.org']], 
			[['Long, Name', [], 'Long.Name', 'fabalabs.org']], 
			[['Long, Name', [], 'Long.Name', 'fabalabs.org']], 
			[['Milosavljevic, Danny', [], 'Danny.Milosavljevic', 'fabasoft.com'], ['Pesendorfer, Klaus', [], 'Klaus.Pesendorfer', 'fabasoft.com']],
			[],
			[],
			[],
			'<*****@*****.**>'
		]"""

        date, subject, from_, sender, reply_to, to_, cc, bcc, in_reply_to, message_id = envelope[:
                                                                                                 10]
        date = from_internaldate(date)

        return uid, flags, size, date, subject, from_, sender, reply_to, to_, cc, bcc, in_reply_to, message_id
예제 #6
0
파일: niceimap.py 프로젝트: dannymi/IMAPFS
    def get_mail_envelope(self, uid):  # SLOOOW
        # print >>sys.stderr, "get_mail_envelope UID", uid
        items = None
        if self.current_directory_contents is not None and uid in self.current_directory_contents:
            items_cachetime, items = self.current_directory_contents[
                uid
            ]  # [x for x in self.current_directory_contents if x[lisp.symbol("UID")] == uid]

            if time.time() - items_cachetime >= timeout.timeout:  # too old
                items = None

                # items = None # FIXME

        for i in range(3):
            if items is None or items == []:  # FIXME the latter is weird... and not necessary anymore
                status, items = self.connection.uid("FETCH", uid, "(UID ENVELOPE RFC822.SIZE FLAGS)")
                # f = file("/tmp/uid-%s" % uid, "w")
                # import pickle
                # pickle.dump(items, f) # FIXME FIXME
                # f.close()

                items = [x for x in parse_items(items, True)]
                if items == []:  # weird, give it some time
                    time.sleep(1)
                else:
                    items = items[0]
                    break

        if items == []:  # not found
            raise exceptions.LookupError(
                'message with UID %s not found in mailbox "%s"' % (uid, self.current_directory)
            )

            # print >>sys.stderr, "items ENV", items
        uid = items[lisp.symbol("UID")]
        size = items[lisp.symbol("RFC822.SIZE")]
        envelope = items[lisp.symbol("ENVELOPE")]
        flags = items[lisp.symbol("FLAGS")]
        """[
			'Wed, 10 Jan 2007 18:16:22 +0200', 
			'Some subject', 
			[['Long, Name', [], 'Silvio.Ziegelwanger', 'fabalabs.org']], 
			[['Long, Name', [], 'Long.Name', 'fabalabs.org']], 
			[['Long, Name', [], 'Long.Name', 'fabalabs.org']], 
			[['Milosavljevic, Danny', [], 'Danny.Milosavljevic', 'fabasoft.com'], ['Pesendorfer, Klaus', [], 'Klaus.Pesendorfer', 'fabasoft.com']],
			[],
			[],
			[],
			'<*****@*****.**>'
		]"""

        date, subject, from_, sender, reply_to, to_, cc, bcc, in_reply_to, message_id = envelope[:10]
        date = from_internaldate(date)

        return uid, flags, size, date, subject, from_, sender, reply_to, to_, cc, bcc, in_reply_to, message_id
예제 #7
0
 def indentation_update(self):
     response = [symbol(":indentation-update"), [
         cons("def", 1),
         cons("class", 1),
         cons("if", 1),
         cons("else", 1),
         cons("while", 1),
         cons("for", 1),
         cons("try", 1),
         cons("except", 1),
         cons("finally", 1)
     ]]
     lisp_response = write_lisp(response)
     header = "{0:06x}".format(len(lisp_response))
     return header + lisp_response
예제 #8
0
 def indentation_update(self):
     response = [
         symbol(":indentation-update"),
         [
             cons("def", 1),
             cons("class", 1),
             cons("if", 1),
             cons("else", 1),
             cons("while", 1),
             cons("for", 1),
             cons("try", 1),
             cons("except", 1),
             cons("finally", 1)
         ]
     ]
     lisp_response = write_lisp(response)
     header = "{0:06x}".format(len(lisp_response))
     return header + lisp_response
예제 #9
0
파일: niceimap.py 프로젝트: dannymi/IMAPFS
    def cache_directory_attributes(self):
        self.current_directory_contents = {}  # uid -> [...]

        status, items = self.connection.uid("FETCH", "1:1000000000", "(UID FLAGS INTERNALDATE ENVELOPE RFC822.SIZE)")
        if status == "OK":
            if items == [None]:
                items = []  # ???

                # print >>sys.stderr, "cache_directory_attributes len items", len(items)

            self.current_directory_contents = {}
            for item in parse_items(items):
                uid = item[lisp.symbol("UID")]

                items_cachetime = time.time()
                self.current_directory_contents[uid] = items_cachetime, item
        else:
            self.current_directory_contents = None
예제 #10
0
    def cache_directory_attributes(self):
        self.current_directory_contents = {}  # uid -> [...]

        status, items = self.connection.uid(
            "FETCH", "1:1000000000",
            "(UID FLAGS INTERNALDATE ENVELOPE RFC822.SIZE)")
        if status == "OK":
            if items == [None]:
                items = []  # ???

            #print >>sys.stderr, "cache_directory_attributes len items", len(items)

            self.current_directory_contents = {}
            for item in parse_items(items):
                uid = item[lisp.symbol("UID")]

                items_cachetime = time.time()
                self.current_directory_contents[uid] = items_cachetime, item
        else:
            self.current_directory_contents = None
예제 #11
0
 def swank_connection_info(self):
     """Return connection info available"""
     machine = platform.machine().upper()
     version = platform.python_version()
     pid = os.getpid()
     host, ipaddr = self.socket.getsockname()
     return llist([
         symbol(':return'),
         llist([
             symbol(':ok'),
             llist([
                 symbol(':pid'), pid,
                 symbol(':style'),
                 lbool(False),
                 symbol(':encoding'),
                 llist([
                     symbol(':coding-systems'),
                     llist([
                         lstring('utf-8-unix'),
                         lstring('iso-latin-1-unix')
                     ])
                 ]),
                 symbol(':lisp-implementation'),
                 llist([
                     symbol(':type'),
                     lstring('ULISP'),
                     symbol(':name'),
                     lstring('ulisp'),
                     symbol(':version'),
                     lstring(version),
                     symbol(':program'),
                     lbool(False),
                 ]),
                 symbol(':machine'),
                 llist([
                     symbol(':instance'),
                     lstring("{0} [{1}]".format(host, ipaddr)),
                     symbol(':type'),
                     lstring(machine),
                     symbol(':version'),
                     lstring(machine)
                 ]),
                 symbol(':package'),
                 llist([
                     symbol(':name'),
                     lstring('python'),
                     symbol(':prompt'), self.prompt
                 ]),
                 symbol(':version'),
                 lstring('2012-07-13')
             ])
         ]), self.id
     ])
예제 #12
0
 def swank_connection_info(self):
     """Return connection info available"""
     machine = platform.machine().upper()
     version = platform.python_version()
     pid = os.getpid()
     host, ipaddr = self.socket.getsockname()
     return llist([
         symbol(':return'), llist([
             symbol(':ok'), llist([
                 symbol(':pid'), pid, symbol(':style'), lbool(False),
                 symbol(':encoding'), llist([
                     symbol(':coding-systems'), llist([
                         lstring('utf-8-unix'),
                         lstring('iso-latin-1-unix')
                     ])
                 ]),
                 symbol(':lisp-implementation'), llist([
                     symbol(':type'), lstring('PYTHON'),
                     symbol(':name'), lstring('python'),
                     symbol(':version'), lstring(version),
                     symbol(':program'), lbool(False),
                 ]),
                 symbol(':machine'), llist([
                     symbol(':instance'), lstring("{0} [{1}]".format(host,ipaddr)),
                     symbol(':type'), lstring(machine),
                     symbol(':version'), lstring(machine)
                 ]),
                 symbol(':package'), llist([
                     symbol(':name'), lstring('python'),
                     symbol(':prompt'), self.prompt
                 ]),
                 symbol(':version'), lstring('2012-07-13')
             ])
         ]), self.id
     ])
예제 #13
0
            for item in parse_items(items):
                uid = item[lisp.symbol("UID")]

                items_cachetime = time.time()
                self.current_directory_contents[uid] = items_cachetime, item
        else:
            self.current_directory_contents = None

    def chdir(self, path):
        status, foo = self.connection.select(path, readonly=True)
        if status != "OK":
            print exceptions.OSError(2, "No such file or directory: '%s'" %
                                     "a")  # TODO more

    def unlink_message(self, uid):
        status, foo = self.connection.uid("STORE", uid, "+FLAGS",
                                          r"(\Deleted)")
        if status != "OK":
            raise exceptions.OSError(2, "No such file or directory: '%s'" %
                                     "a")  # TODO more


if __name__ == "__main__":
    assert (parse_flags(
        "1848 (FLAGS (\Deleted) INTERNALDATE \"25-May-2007 17:08:58 +0200\" RFC822 \"\")"
    ) == {
        lisp.symbol("FLAGS"): [lisp.symbol("Deleted")],
        lisp.symbol("INTERNALDATE"): "25-May-2007 17:08:58 +0200",
        lisp.symbol("RFC822"): ""
    })
예제 #14
0
파일: niceimap.py 프로젝트: dannymi/IMAPFS
                items = []  # ???

                # print >>sys.stderr, "cache_directory_attributes len items", len(items)

            self.current_directory_contents = {}
            for item in parse_items(items):
                uid = item[lisp.symbol("UID")]

                items_cachetime = time.time()
                self.current_directory_contents[uid] = items_cachetime, item
        else:
            self.current_directory_contents = None

    def chdir(self, path):
        status, foo = self.connection.select(path, readonly=True)
        if status != "OK":
            print exceptions.OSError(2, "No such file or directory: '%s'" % "a")  # TODO more

    def unlink_message(self, uid):
        status, foo = self.connection.uid("STORE", uid, "+FLAGS", r"(\Deleted)")
        if status != "OK":
            raise exceptions.OSError(2, "No such file or directory: '%s'" % "a")  # TODO more


if __name__ == "__main__":
    assert parse_flags('1848 (FLAGS (\Deleted) INTERNALDATE "25-May-2007 17:08:58 +0200" RFC822 "")') == {
        lisp.symbol("FLAGS"): [lisp.symbol("Deleted")],
        lisp.symbol("INTERNALDATE"): "25-May-2007 17:08:58 +0200",
        lisp.symbol("RFC822"): "",
    }