def _strip_paren(self, s): """Remove leading and trailing parentheses.""" if s[0] == '(': if s[-1] != ')': raise MismatchedNesting(s) s = s[1:-1] return s def _fetch_split(self, s): """Like split, but do not split within []. splitQuoted could be used instead, if it was changed to accept the 'quote' character. """ in_bracket = b = 0 for e in range(0, len(s)): if s[e] == ' ' and in_bracket == 0: yield s[b:e] b = e+1 elif s[e] == '[': in_bracket += 1 elif s[e] == ']': in_bracket -= 1 if s[b:] != '': yield s[b:] def _build_body_query(self, d): body_query = "%s(" % (d["body"],) for item, value in d.items(): if item == "peek" and value is not None: body_query += "%s=1, " % (value,) elif item == "section" and value is not None: body_query += '%s="%s", ' % (item, value,) elif item == "partial" and value is not None: min, max = value.split('.', 1) body_query += "%s=(%s,%s), " % (item, min, max) elif item == "part" and value is not None: if '.' in value: value, extra = value.split('.', 1) if '.' in extra: extra, extra2 = extra.split('.', 1) body_query += "%s=1, %s=1, %s=1, " % (value, extra, extra2) else: body_query += "%s=1, %s=1, " % (value, extra) else: body_query += "%s=1, " % (value,) elif item == "fielditems" and value is not None: body_query += "%s=%s, " % (item, splitQuoted(value),) body_query = "%s)" % (body_query[:-2],) return body_query macro_fetch_atts = ["ALL", "FULL", "FAST"] simple_fetch_atts = ["ENVELOPE", "FLAGS", "INTERNALDATE", "UID"] body_re = re.compile(r"(?P
BODY)(?:.(?P