This file is indexed.

/usr/share/pyshared/Mailnag/mailnag.py is in mailnag 0.5.2-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# mailnag.py
#
# Copyright 2011, 2012 Patrick Ulbrich <zulu99@gmx.net>
# Copyright 2011 Leighton Earl <leighton.earl@gmx.com>
# Copyright 2011 Ralf Hersel <ralf.hersel@gmx.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#

import os
from gi.repository import GObject, GLib
import time
import signal
import traceback

from common.config import read_cfg, cfg_exists, cfg_folder
from common.utils import set_procname, is_online
from common.accountlist import AccountList
from daemon.mailchecker import MailChecker
from daemon.idlers import Idlers

mainloop = None
mailchecker = None
idlers = None


def read_config():
	if not cfg_exists():
		return None
	else:
		return read_cfg()


def write_pid():
	pid_file = os.path.join(cfg_folder, 'mailnag.pid')
	f = open(pid_file, 'w')
	f.write(str(os.getpid()))
	f.close()


def delete_pid():
	pid_file = os.path.join(cfg_folder, 'mailnag.pid')
	if os.path.exists(pid_file):
		os.remove(pid_file)


# Workaround: 
# sometimes gnomeshell's notification server (org.freedesktop.Notifications implementation)
# doesn't seem to be up immediately upon session start, so prevent Mailnag from crashing 
# by checking if the org.freedesktop.Notifications DBUS interface is available yet.
# See https://github.com/pulb/mailnag/issues/48
def wait_for_notification_server():	
	import dbus
	bus = dbus.SessionBus()
	
	while True:	
		try:		
			notify = bus.get_object('org.freedesktop.Notifications', '/org/freedesktop/Notifications')
			iface = dbus.Interface(notify, 'org.freedesktop.Notifications')
			inf = iface.GetServerInformation()
			
			if inf[0] == u'gnome-shell':
				break
		except:
			pass
		
		print 'Waiting for GNOME-Shell notification server...'			
		time.sleep(5)


def wait_for_inet_connection():
	if not is_online():
		print 'Waiting for internet connection...'
		while not is_online():
			time.sleep(5)


def cleanup():
	# clean up resources
	if mailchecker != None:
		mailchecker.dispose()

	if idlers != None:
		idlers.dispose()
	
	delete_pid()


def sig_handler(signum, frame):
	if mainloop != None:
		mainloop.quit()


def main():
	global mainloop, mailchecker, idlers
	
	set_procname("mailnag")
	
	GObject.threads_init()
	
	signal.signal(signal.SIGTERM, sig_handler)
	
	try:
		# write Mailnag's process id to file
		write_pid()
		cfg = read_config()
		
		if (cfg == None):
			print 'Error: Cannot find configuration file. Please run mailnag_config first.'
			exit(1)
		
		wait_for_notification_server()		
		wait_for_inet_connection()
		
		accounts = AccountList()
		accounts.load_from_cfg(cfg, enabled_only = True)
		
		mailchecker = MailChecker(cfg)
		
		# immediate check, check *all* accounts
		try:		
			mailchecker.check(accounts)
		except:
			traceback.print_exc()
		
		idle_accounts = filter(lambda acc: acc.imap and acc.idle, accounts)
		non_idle_accounts = filter(lambda acc: (not acc.imap) or (acc.imap and not acc.idle), accounts)
		
		# start polling thread for POP3 accounts and
		# IMAP accounts without idle support
		if len(non_idle_accounts) > 0:
			def poll_func():
				try:
					mailchecker.check(non_idle_accounts)
				except:
					traceback.print_exc()
				return True
			
			check_interval = int(cfg.get('general', 'check_interval'))
			GObject.timeout_add_seconds(60 * check_interval, poll_func)
		
		# start idler threads for IMAP accounts with idle support
		if len(idle_accounts) > 0:
			def sync_func(account):
				try:
					mailchecker.check([account])
				except:
					traceback.print_exc()
			
			idlers = Idlers(idle_accounts, sync_func)
			idlers.run()
		
		mainloop = GObject.MainLoop()
		mainloop.run()
	except KeyboardInterrupt:
		pass # ctrl+c pressed
	finally:
		cleanup()


if __name__ == '__main__': main()