Exemple #1
0
def parse_attributes(text):
    stream = StringIO()
    stream.write(text)
    stream.seek(0)
    premonition_stream_1 = lisp.premonition_stream(stream)
    items = lisp.parse(premonition_stream_1)
    return items
Exemple #2
0
def decode_folders(folders):
    for folder_text in folders:
        #print "folder_text", folder_text
        stream = StringIO()
        stream.write(folder_text)
        # (\HasNoChildren) "/" "Gel&APY-schte Objekte" <type 'str'>
        stream.seek(0)
        premonition_stream_1 = lisp.premonition_stream(stream)
        assert (premonition_stream_1.peek() == "(")
        premonition_stream_1.consume()
        flags = lisp.parse(premonition_stream_1)

        assert (premonition_stream_1.peek() == " ")
        premonition_stream_1.consume()

        separator = lisp.parse_string_literal(premonition_stream_1)
        assert (separator == "/")  # limitation

        assert (premonition_stream_1.peek() == " ")
        premonition_stream_1.consume()

        if premonition_stream_1.peek() == "\"":
            name = lisp.parse_string_literal(premonition_stream_1)
        else:  # weird.
            name = premonition_stream_1.consume_rest()

        name = "".join(unescape_imap_name(name))

        #flags, separator, name = data
        yield flags, separator, name
Exemple #3
0
def parse_attributes(text):
    stream = StringIO()
    stream.write(text)
    stream.seek(0)
    premonition_stream_1 = lisp.premonition_stream(stream)
    items = lisp.parse(premonition_stream_1)
    return items
Exemple #4
0
def decode_folders(folders):
    for folder_text in folders:
        # print "folder_text", folder_text
        stream = StringIO()
        stream.write(folder_text)
        # (\HasNoChildren) "/" "Gel&APY-schte Objekte" <type 'str'>
        stream.seek(0)
        premonition_stream_1 = lisp.premonition_stream(stream)
        assert premonition_stream_1.peek() == "("
        premonition_stream_1.consume()
        flags = lisp.parse(premonition_stream_1)

        assert premonition_stream_1.peek() == " "
        premonition_stream_1.consume()

        separator = lisp.parse_string_literal(premonition_stream_1)
        assert separator == "/"  # limitation

        assert premonition_stream_1.peek() == " "
        premonition_stream_1.consume()

        if premonition_stream_1.peek() == '"':
            name = lisp.parse_string_literal(premonition_stream_1)
        else:  # weird.
            name = premonition_stream_1.consume_rest()

        name = "".join(unescape_imap_name(name))

        # flags, separator, name = data
        yield flags, separator, name
Exemple #5
0
def parse_items(all_items, just_one_item_p=False):
    #re_items = re.compile(r"^([0-9][0-9]*) (.*)$")
    #match = re_items.match(items)
    #assert(match)
    #print >>sys.stderr,"group(1)", match.group(1), uid, type(uid)
    #assert(int(match.group(1)) == int(uid))
    #items = match.group(2)

    stream = StringIO()

    # all_items arbitrary item, literal, ... parts
    for items in all_items:
        if isinstance(items, str) and items.startswith(
                "Some messages in the mailbox had previously been expunged and could not be returned"
        ):
            # Some messages in the mailbox had previously been expunged and could not be returned. <type 'str'>

            pass
            #raise ParseError()

        if items is None:  # ???
            # ('46 (ENVELOPE ("Wed, 11 Apr 2007 13:08:38 +0200" {35}', 'Neues "Local-Index-Service" Projekt') <type 'tuple'>

            print >> sys.stderr, "error: one item is None: all_items = ", all_items
            raise ParseError()

        if isinstance(items, tuple):  # has literal parts
            #print >>sys.stderr, "tuple", items
            coalesced_result = ""
            is_literal = False
            for tuple_item in items:
                if not is_literal:
                    i = tuple_item.rfind("{")
                    if i > -1:
                        tuple_item = tuple_item[:i]
                        is_literal = True
                else:
                    # is_literal
                    is_literal = False

                    tuple_item = lisp_escaped_quoted_string(tuple_item)

                stream.write(tuple_item)
        else:
            stream.write(items)

    stream.seek(0)

    #import pickle
    #pickle.dump(stream.getvalue(), open('/tmp/save.p','w')) # FIXME

    #print >>sys.stderr, ">>>", stream.getvalue(), "<<<"

    premonition_stream_1 = lisp.premonition_stream(stream)
    #assert(premonition_stream_1.peek() == "(")
    #premonition_stream_1.consume()

    items = lisp.parse(premonition_stream_1)
    # items = [1, [\UID, 0807, \FLAGS, [\Seen], ...], 2, [\UID, 0808, \FLAGS, [\Seen], ...]]

    items = pair(items)
    # items = [(1, [\UID, 0807, \FLAGS, [\Seen], ...]), (2, [\UID, 0808, \FLAGS, [\Seen], ...], ...)]
    """
		(ENVELOPE
			("Wed, 10 Jan 2007 18:16:22 +0200" "subject" (
				("Long, Name" NIL "Name.Long" "fabalabs.org")
			)
			(
				("Long, Name" NIL "Name.Long" "fabalabs.org")
			)
			(
				("Long, Name" NIL "Name.Long" "fabalabs.org")
			)
			(
				("Milosavljevic, Danny" NIL "Danny.Milosavljevic" "fabasoft.com")
				("Pesendorfer, Klaus" NIL "Klaus.Pesendorfer" "fabasoft.com")
				("Lechner, Jakob" NIL "Jakob.Lechner" "fabasoft.com")
			)
			NIL
			NIL
			NIL
			"<*****@*****.**>"))
	"""

    #items [\UID, \10525, \ENVELOPE, ['Wed, 10 Jan 2007 18:16:22 +0200', 'subject' ..

    #print >>sys.stderr, "items", items # [0]
    #assert(items[0][0] in ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"])
    #items.next()

    if not just_one_item_p:
        items = items[1:]

    for number, item in items:
        #print >>sys.stderr, "item", item
        #print >>sys.stderr, "yield", dict(pair(item)) # FIXME
        yield dict(pair(item))
Exemple #6
0
def parse_items(all_items, just_one_item_p=False):
    # re_items = re.compile(r"^([0-9][0-9]*) (.*)$")
    # match = re_items.match(items)
    # assert(match)
    # print >>sys.stderr,"group(1)", match.group(1), uid, type(uid)
    # assert(int(match.group(1)) == int(uid))
    # items = match.group(2)

    stream = StringIO()

    # all_items arbitrary item, literal, ... parts
    for items in all_items:
        if isinstance(items, str) and items.startswith(
            "Some messages in the mailbox had previously been expunged and could not be returned"
        ):
            # Some messages in the mailbox had previously been expunged and could not be returned. <type 'str'>

            pass
            # raise ParseError()

        if items is None:  # ???
            # ('46 (ENVELOPE ("Wed, 11 Apr 2007 13:08:38 +0200" {35}', 'Neues "Local-Index-Service" Projekt') <type 'tuple'>

            print >> sys.stderr, "error: one item is None: all_items = ", all_items
            raise ParseError()

        if isinstance(items, tuple):  # has literal parts
            # print >>sys.stderr, "tuple", items
            coalesced_result = ""
            is_literal = False
            for tuple_item in items:
                if not is_literal:
                    i = tuple_item.rfind("{")
                    if i > -1:
                        tuple_item = tuple_item[:i]
                        is_literal = True
                else:
                    # is_literal
                    is_literal = False

                    tuple_item = lisp_escaped_quoted_string(tuple_item)

                stream.write(tuple_item)
        else:
            stream.write(items)

    stream.seek(0)

    # import pickle
    # pickle.dump(stream.getvalue(), open('/tmp/save.p','w')) # FIXME

    # print >>sys.stderr, ">>>", stream.getvalue(), "<<<"

    premonition_stream_1 = lisp.premonition_stream(stream)
    # assert(premonition_stream_1.peek() == "(")
    # premonition_stream_1.consume()

    items = lisp.parse(premonition_stream_1)
    # items = [1, [\UID, 0807, \FLAGS, [\Seen], ...], 2, [\UID, 0808, \FLAGS, [\Seen], ...]]

    items = pair(items)
    # items = [(1, [\UID, 0807, \FLAGS, [\Seen], ...]), (2, [\UID, 0808, \FLAGS, [\Seen], ...], ...)]
    """
		(ENVELOPE
			("Wed, 10 Jan 2007 18:16:22 +0200" "subject" (
				("Long, Name" NIL "Name.Long" "fabalabs.org")
			)
			(
				("Long, Name" NIL "Name.Long" "fabalabs.org")
			)
			(
				("Long, Name" NIL "Name.Long" "fabalabs.org")
			)
			(
				("Milosavljevic, Danny" NIL "Danny.Milosavljevic" "fabasoft.com")
				("Pesendorfer, Klaus" NIL "Klaus.Pesendorfer" "fabasoft.com")
				("Lechner, Jakob" NIL "Jakob.Lechner" "fabasoft.com")
			)
			NIL
			NIL
			NIL
			"<*****@*****.**>"))
	"""

    # items [\UID, \10525, \ENVELOPE, ['Wed, 10 Jan 2007 18:16:22 +0200', 'subject' ..

    # print >>sys.stderr, "items", items # [0]
    # assert(items[0][0] in ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"])
    # items.next()

    if not just_one_item_p:
        items = items[1:]

    for number, item in items:
        # print >>sys.stderr, "item", item
        # print >>sys.stderr, "yield", dict(pair(item)) # FIXME
        yield dict(pair(item))