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)
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)
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()
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
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
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
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()
def filter_tags(ts): hidden_tags = frozenset(config.get('hidden_tags').split(' ')) for t in ts: if t not in hidden_tags: yield t
def __init__(self): db = notmuch.Database() self.query = notmuch.Query(db, config.get('query')) self.query.set_sort(notmuch.Query.SORT.OLDEST_FIRST)
def action_mail_client(self, action, data): self.release() subprocess.Popen(shlex.split(config.get("mail_client")))
def filter_tags(ts): hidden_tags = frozenset(config.get('hidden_tags').split(' ')) for t in ts: if t not in hidden_tags: yield t
def __init__(self): db = notmuch.Database() self.query = notmuch.Query(db, config.get('query')) self.query.set_sort(notmuch.Query.SORT.OLDEST_FIRST)