예제 #1
0
 def resolve_address(self, addr):
     r = {}
     pat = re.compile(re.escape(addr), re.I | re.UNICODE)
     preds = [EMailPredicate('addr:' + addr)]
     corpus = self.get_corpus()
     try:
         selection = Selection(corpus,
                               preds,
                               doc_preds=[DEFAULT_FILTER_WITH_SENT],
                               safe=False)
         for (i, doc) in selection.iter(timeout=1):
             msg = doc.get_msg()
             for (n, a) in unicode_getalladdrs(msg, 'from', 'to', 'cc'):
                 x = formataddr((n, a))
                 if not pat.search(x): continue
                 a = a.lower()
                 if a not in r:
                     r[a] = (1, x)
                 else:
                     (n, x) = r[a]
                     r[a] = (n + 1, x)
             if config.RESOLVE_ADDRESS_NADDRS <= (i + 1): break
     except SearchTimeout:
         pass
     # ambiguous?
     return sorted(r.itervalues(), reverse=True)
예제 #2
0
파일: kernel.py 프로젝트: yasusii/shaling
 def resolve_address(self, addr):
   r = {}
   pat = re.compile(re.escape(addr), re.I | re.UNICODE)
   preds = [ EMailPredicate('addr:'+addr) ]
   corpus = self.get_corpus()
   try:
     selection = Selection(corpus, preds,
                           doc_preds=[ DEFAULT_FILTER_WITH_SENT ],
                           safe=False)
     for (i,doc) in selection.iter(timeout=1):
       msg = doc.get_msg()
       for (n, a) in unicode_getalladdrs(msg, 'from', 'to', 'cc'):
         x = formataddr((n, a))
         if not pat.search(x): continue
         a = a.lower()
         if a not in r:
           r[a] = (1, x)
         else:
           (n, x) = r[a]
           r[a] = (n+1, x)
       if config.RESOLVE_ADDRESS_NADDRS <= (i+1): break
   except SearchTimeout:
     pass
   # ambiguous?
   return sorted(r.itervalues(), reverse=True)
예제 #3
0
파일: message.py 프로젝트: yasusii/shaling
def show_digest(term, idx, focused, doc, selection, labels):

    addrs = unicode_getalladdrs(doc.get_msg(), "from")
    if addrs:
        (gecos, addr) = addrs[0]
    else:
        (gecos, addr) = ("???", "???")

    # disptime - max 9chrs
    def disptime(t):
        import time

        if t == 0:
            return "      ???"
        d = int(time.time()) - t
        (yy0, mm0, dd0, hr0, mt0, sc0, day0, x, x) = time.localtime()
        (yy, mm, dd, hr, mt, sc, day, x, x) = time.localtime(t)
        if d < 0:
            return " (future)"
        if d < 86400 and dd == dd0:
            return "%02d:%02d   ." % (hr, mt)
        if d < 86400 * 2 and dd == dd0 - 1:
            return "%02d:%02d  .." % (hr, mt)
        if d < 86400 * 6:
            return "%02d:%02d %3s" % (hr, mt, WDAY[day])
        if d < 86400 * 365 and yy == yy0:
            return "%02d/%02d" % (mm, dd)
        return "%02d/%02d/%02d" % (yy % 100, mm, dd)

    # truncate
    def trunc(n, s0):
        length = 0
        for (i, c) in enumerate(s0):
            length += term.length(c)
            if n <= length + 2:
                return s0[: i + 1] + "." * (n - length)
        return s0

    # Creata a line bufffer.
    width = term.cols or 80
    line = "%3d:%s%9s  " % (idx + 1, " +"[int(focused)], disptime(doc.get_mtime()))
    t1 = trunc(20, (gecos or addr).strip())
    line += t1 + (" " * (20 - term.length(t1)))
    if labels:
        line += " [%s]" % (get_label_names(labels))
    line += " " + trunc(40, doc.get_title())
    left = width - len(line) - 4
    line += " >> " + doc.get_snippet(selection, maxchars=left, maxcontext=left)
    line = trunc(width - 4, line)

    # Output with highlights.
    color = get_message_color(labels)
    if focused:
        color += "+underline"
    term.display(highlight(term, selection, color, line) + "\n")
    return
예제 #4
0
파일: message.py 프로젝트: yasusii/shaling
def show_digest(term, idx, focused, doc, selection, labels):

    addrs = unicode_getalladdrs(doc.get_msg(), 'from')
    if addrs:
        (gecos, addr) = addrs[0]
    else:
        (gecos, addr) = ('???', '???')

    # disptime - max 9chrs
    def disptime(t):
        import time
        if t == 0:
            return '      ???'
        d = int(time.time()) - t
        (yy0, mm0, dd0, hr0, mt0, sc0, day0, x, x) = time.localtime()
        (yy, mm, dd, hr, mt, sc, day, x, x) = time.localtime(t)
        if d < 0:
            return ' (future)'
        if d < 86400 and dd == dd0:
            return '%02d:%02d   .' % (hr, mt)
        if d < 86400 * 2 and dd == dd0 - 1:
            return '%02d:%02d  ..' % (hr, mt)
        if d < 86400 * 6:
            return '%02d:%02d %3s' % (hr, mt, WDAY[day])
        if d < 86400 * 365 and yy == yy0:
            return '%02d/%02d' % (mm, dd)
        return '%02d/%02d/%02d' % (yy % 100, mm, dd)

    # truncate
    def trunc(n, s0):
        length = 0
        for (i, c) in enumerate(s0):
            length += term.length(c)
            if n <= length + 2:
                return s0[:i + 1] + '.' * (n - length)
        return s0

    # Creata a line bufffer.
    width = term.cols or 80
    line = '%3d:%s%9s  ' % (idx + 1, ' +'[int(focused)],
                            disptime(doc.get_mtime()))
    t1 = trunc(20, (gecos or addr).strip())
    line += t1 + (' ' * (20 - term.length(t1)))
    if labels:
        line += ' [%s]' % (get_label_names(labels))
    line += ' ' + trunc(40, doc.get_title())
    left = width - len(line) - 4
    line += ' >> ' + doc.get_snippet(selection, maxchars=left, maxcontext=left)
    line = trunc(width - 4, line)

    # Output with highlights.
    color = get_message_color(labels)
    if focused:
        color += '+underline'
    term.display(highlight(term, selection, color, line) + '\n')
    return
예제 #5
0
 def func(msg, labels):
   for (_,a) in unicode_getalladdrs(msg, *flds):
     if '@' in a:
       i = a.index('@')
       (user,domain) = (a[:i].lower(), a[i+1:].lower())
     else:
       (user,domain) = (a, '?')
     if user0 and user0 != user: continue
     if (not domain0 or domain0 == domain or 
         domain0.startswith('*') and domain.endswith(domain0[1:])):
       return not neg
   return neg
예제 #6
0
파일: message.py 프로젝트: yasusii/shaling
def setup_template_string(
    fromaddr, addrs_to, addrs_cc, addrs_bcc, is_group, subject, labels, headermsgs, includemsgs, forwardlocs
):
    width = 80

    def fold_header(items, sep=", "):
        lines = []
        line = ""
        for x in items:
            if not line:
                line = x
            elif width < len(line) + len(sep) + len(x):
                lines.append(line + sep)
                line = "\t" + x
            else:
                line += sep + x
        if line:
            lines.append(line)
        return "\n".join(lines)

    if forwardlocs:
        # Append 'Fwd:' if necessary.
        for m in headermsgs:
            # Take the subject of the first message.
            if not subject and m["subject"]:
                subject = "Fwd: " + unicode_header(m["subject"])
                break
    else:
        # Append 'Re:' if necessary.
        for m in headermsgs:
            # Take the subject if not set.
            if not subject and m["subject"]:
                subject = unicode_header(m["subject"])
                if not re.match("\s*re:", subject, re.I):
                    subject = "Re: " + subject
                break
        # Add extra recipients.
        for m in headermsgs:
            if m["mail-reply-to"]:
                addrs_to.extend(unicode_getall(m, "mail-reply-to"))
            elif m["reply-to"]:
                addrs_to.extend(unicode_getall(m, "reply-to"))
            else:
                addrs_to.append(unicode_header(m["from"]))
            if is_group:
                addrs_cc.extend(formataddr((n, a)) for (n, a) in unicode_getalladdrs(m, "to", "cc"))
    #
    msgids = set()
    refids = set()
    if headermsgs:
        for msg in headermsgs:
            if msg["message-id"]:
                msgids.add(msg["message-id"])
            if msg["references"]:
                for x in msg.get_all("references"):
                    refids.update(get_msgids(x))
    #
    lines = []
    lines.append("From: %s" % fromaddr)
    lines.append("To: %s" % fold_header(addrs_to))
    lines.append("Cc: %s" % fold_header(addrs_cc))
    lines.append("Bcc: %s" % fold_header(addrs_bcc))
    lines.append("Label: %s" % get_label_names(labels))
    lines.append("Subject: %s" % subject)
    if headermsgs:
        lines.append("References: %s" % fold_header(msgids.union(refids), " "))
        lines.append("In-Reply-To: %s" % fold_header(msgids, " "))
    if forwardlocs:
        lines.append("X-Forward-Msg: %s" % (", ".join(forwardlocs)))
    lines.append("")
    if includemsgs:
        for msg in includemsgs:
            from0 = unicode_header(msg["from"]) or "unknown person"
            date0 = unicode_header(msg["date"]) or "unknown date"
            subject0 = unicode_header(msg["subject"]) or "unknown subject"
            quoted_lines = []
            charset = msg.get_content_charset()
            for (i, mpart, level) in enum_message_parts(msg, favor="text/plain"):
                if mpart.get_content_maintype() == "text":
                    text = get_body_text(mpart, charset)
                    quoted_lines.extend(text.splitlines())
            lines.extend(config.quotemsg(from0, date0, subject0, quoted_lines))

    return "\n".join(lines) + "\n"
예제 #7
0
파일: message.py 프로젝트: yasusii/shaling
def setup_template_string(fromaddr, addrs_to, addrs_cc, addrs_bcc, is_group,
                          subject, labels, headermsgs, includemsgs,
                          forwardlocs):
    width = 80

    def fold_header(items, sep=', '):
        lines = []
        line = ''
        for x in items:
            if not line:
                line = x
            elif width < len(line) + len(sep) + len(x):
                lines.append(line + sep)
                line = '\t' + x
            else:
                line += sep + x
        if line:
            lines.append(line)
        return '\n'.join(lines)

    if forwardlocs:
        # Append 'Fwd:' if necessary.
        for m in headermsgs:
            # Take the subject of the first message.
            if not subject and m['subject']:
                subject = 'Fwd: ' + unicode_header(m['subject'])
                break
    else:
        # Append 'Re:' if necessary.
        for m in headermsgs:
            # Take the subject if not set.
            if not subject and m['subject']:
                subject = unicode_header(m['subject'])
                if not re.match('\s*re:', subject, re.I):
                    subject = 'Re: ' + subject
                break
        # Add extra recipients.
        for m in headermsgs:
            if m['mail-reply-to']:
                addrs_to.extend(unicode_getall(m, 'mail-reply-to'))
            elif m['reply-to']:
                addrs_to.extend(unicode_getall(m, 'reply-to'))
            else:
                addrs_to.append(unicode_header(m['from']))
            if is_group:
                addrs_cc.extend(
                    formataddr((n, a))
                    for (n, a) in unicode_getalladdrs(m, 'to', 'cc'))
    #
    msgids = set()
    refids = set()
    if headermsgs:
        for msg in headermsgs:
            if msg['message-id']:
                msgids.add(msg['message-id'])
            if msg['references']:
                for x in msg.get_all('references'):
                    refids.update(get_msgids(x))
    #
    lines = []
    lines.append('From: %s' % fromaddr)
    lines.append('To: %s' % fold_header(addrs_to))
    lines.append('Cc: %s' % fold_header(addrs_cc))
    lines.append('Bcc: %s' % fold_header(addrs_bcc))
    lines.append('Label: %s' % get_label_names(labels))
    lines.append('Subject: %s' % subject)
    if headermsgs:
        lines.append('References: %s' % fold_header(msgids.union(refids), ' '))
        lines.append('In-Reply-To: %s' % fold_header(msgids, ' '))
    if forwardlocs:
        lines.append('X-Forward-Msg: %s' % (', '.join(forwardlocs)))
    lines.append('')
    if includemsgs:
        for msg in includemsgs:
            from0 = unicode_header(msg['from']) or 'unknown person'
            date0 = unicode_header(msg['date']) or 'unknown date'
            subject0 = unicode_header(msg['subject']) or 'unknown subject'
            quoted_lines = []
            charset = msg.get_content_charset()
            for (i, mpart, level) in enum_message_parts(msg,
                                                        favor='text/plain'):
                if mpart.get_content_maintype() == 'text':
                    text = get_body_text(mpart, charset)
                    quoted_lines.extend(text.splitlines())
            lines.extend(config.quotemsg(from0, date0, subject0, quoted_lines))

    return '\n'.join(lines) + '\n'