示例#1
0
 def __init__(self):
     db = notmuch.Database()
     self.query = notmuch.Query(db, config.get('query'))
     if config.get('sort') == "oldest":
         self.query.set_sort(notmuch.Query.SORT.OLDEST_FIRST)
     else:
         self.query.set_sort(notmuch.Query.SORT.NEWEST_FIRST)
示例#2
0
def summary(messages):
    messages_result = []
    for msg in messages:
        tags = tags_prefix(filter_tags(msg.get_tags()))
        date = msg.get_date()
        date_relatively = pretty_date(date)
        # ToDo: Make date format changeable
        date_absolutely = datetime.datetime.fromtimestamp(date).strftime(
            "%H:%M %d.%m.%Y")
        sender = pretty_sender(msg.get_header('from'))
        sender_name = sender[0]
        sender_addr = sender[1]
        subject = ellipsize(msg.get_header('subject'))
        text = ''
        try:
            t = msg.get_part(1).decode()
            t = t.lstrip('\n')
            text += t[0:min(len(t), int(config.get('message_length')))] + '...'
        except:
            text += '<UNKNOWN CHARSET>'

        format = config.get('notification_format')
        result = ''
        skip = False
        for i in range(len(format)):
            if skip:
                skip = False
                continue
            if format[i] == '%' and i + 1 < len(format) and not (
                    i > 0 and format[i - 1] == '\\'):
                skip = True
                cmd = format[i + 1]
                if cmd == 'T':
                    result += tags
                elif cmd == 't':
                    result += subject
                elif cmd == 'S':
                    result += sender_addr
                elif cmd == 's':
                    result += sender_name
                elif cmd == 'D':
                    result += date_absolutely
                elif cmd == 'd':
                    result += date_relatively
                elif cmd == 'c':
                    result += text
            else:
                result += format[i]
        messages_result.append(result)
    return '\n'.join(messages_result)
示例#3
0
 def on_startup(self, data):
     config.load()
     Notify.init('notifymuch')
     self.notification = Notify.Notification.new('', '', self.ICON)
     self.notification.set_category('email.arrived')
     if config.get("mail_client"):
         self.notification.add_action(
                 'mail-client',
                 'Run mail client',
                 self.action_mail_client)
     self.notification.connect('closed', lambda e: self.quit())
     self.hold()
示例#4
0
def exclude_recently_seen(messages):
    os.makedirs(CACHE_DIR, exist_ok=True)
    recency_interval = int(config.get('recency_interval_hours')) * 60 * 60
    with shelve.open(LAST_SEEN_FILE) as last_seen:
        now = time.time()
        for k in last_seen.keys():
            if now - last_seen[k] > recency_interval:
                del last_seen[k]
        for message in messages:
            m_id = message.get_message_id()
            if m_id not in last_seen:
                last_seen[m_id] = now
                yield message
示例#5
0
def exclude_recently_seen(messages):
    os.makedirs(CACHE_DIR, exist_ok=True)
    recency_interval = int(config.get('recency_interval_hours')) * 60 * 60
    with shelve.open(LAST_SEEN_FILE) as last_seen:
        now = time.time()
        for k in last_seen.keys():
            if now - last_seen[k] > recency_interval:
                del last_seen[k]
        for message in messages:
            m_id = message.get_message_id()
            if m_id not in last_seen:
                last_seen[m_id] = now
                yield message
示例#6
0
def exclude_recently_seen(messages):
    try:
        os.makedirs(CACHE_DIR)
    except OSError as e:
        if e.errno == 17:
            print('The directory CACHE_DIR exists.')
    recency_interval = int(config.get('recency_interval_hours')) * 60 * 60
    with shelve.open(LAST_SEEN_FILE) as last_seen:
        now = time.time()
        for k in last_seen.keys():
            if now - last_seen[k] > recency_interval:
                del last_seen[k]
        for message in messages:
            m_id = message.get_message_id()
            if m_id not in last_seen:
                last_seen[m_id] = now
                yield message
示例#7
0
    def on_startup(self, data):
        config.load()
        Notify.init('notifymuch')

        # Use GTK to look up the icon to properly fallback to 'mail-unread'.
        icon = Gtk.IconTheme.get_default().lookup_icon(
                self.ICON,
                self.ICON_SIZE,
                0)
        self.icon_filename = icon.get_filename()

        self.notification = Notify.Notification.new('', '', self.icon_filename)
        self.notification.set_category('email.arrived')
        if config.get("mail_client"):
            self.notification.add_action(
                    'mail-client',
                    'Run mail client',
                    self.action_mail_client)
        self.notification.connect('closed', lambda e: self.quit())
        self.hold()
示例#8
0
def filter_tags(ts):
    hidden_tags = frozenset(config.get('hidden_tags').split(' '))
    for t in ts:
        if t not in hidden_tags:
            yield t
示例#9
0
 def __init__(self):
     db = notmuch.Database()
     self.query = notmuch.Query(db, config.get('query'))
     self.query.set_sort(notmuch.Query.SORT.OLDEST_FIRST)
示例#10
0
 def action_mail_client(self, action, data):
     self.release()
     subprocess.Popen(shlex.split(config.get("mail_client")))
示例#11
0
def filter_tags(ts):
    hidden_tags = frozenset(config.get('hidden_tags').split(' '))
    for t in ts:
        if t not in hidden_tags:
            yield t
示例#12
0
 def __init__(self):
     db = notmuch.Database()
     self.query = notmuch.Query(db, config.get('query'))
     self.query.set_sort(notmuch.Query.SORT.OLDEST_FIRST)