예제 #1
0
	def check(self, accounts):
		with self._mailcheck_lock:
			print 'Checking %s email account(s) at: %s' % (len(accounts), time.asctime())
			self._pid.kill() # kill all zombies	

			if not is_online():
				print 'Error: No internet connection'
				return
			
			self._mail_list = self._mailsyncer.sync(accounts)
			
			unseen_mails = []
			new_mails = []
		
			script_data = ""
			script_data_mailcount = 0
			
			for mail in self._mail_list:
				if self._reminder.contains(mail.id): # mail was fetched before
					if self._reminder.unseen(mail.id): # mail was not marked as seen
						unseen_mails.append(mail)
						if self._firstcheck:
							new_mails.append(mail)
				
				else: # mail is fetched the first time
					unseen_mails.append(mail)
					new_mails.append(mail)
					script_data += ' "<%s> %s"' % (mail.sender, mail.subject)
					script_data_mailcount += 1
			
			script_data = str(script_data_mailcount) + script_data
		
			if len(self._mail_list) == 0:
				# no mails (e.g. email client has been launched) -> close notifications
				for n in self._notifications.itervalues():
					n.close()
				self._notifications = {}
			elif len(new_mails) > 0:
				if self._cfg.get('general', 'notification_mode') == '1':
					self._notify_summary(unseen_mails)
				else:
					self._notify_single(new_mails)
				
				# play sound if it is enabled in mailnags settings and 
				# gnome-shell notifications aren't disabled
				if (self._cfg.get('general', 'playsound') == '1') and \
					(self._gsettings.get_int('saved-session-presence') != 2):
					gstplay(get_data_file(self._cfg.get('general', 'soundfile')))

			self._reminder.save(self._mail_list)
			self._run_user_scripts("on_mail_check", script_data) # process user scripts
			sys.stdout.flush() # write stdout to log file
			self._firstcheck = False
		
		return
예제 #2
0
	def check(self, firstcheck = False):
		with self.mailcheck_lock:
			print 'Checking email accounts at:', time.asctime()
			self.pid.kill() # kill all zombies
		
			if firstcheck: # Manual firststart
				self.reminder.load()	

			self.mail_list = self.mails.get_mail('desc') # get all mails from all inboxes
		
			unseen_mails = []
			new_mails = []
		
			script_data = ""
			script_data_mailcount = 0
			
			for mail in self.mail_list:
				if self.reminder.contains(mail.id): # mail was fetched before
					if self.reminder.unseen(mail.id): # mail was not marked as seen
						unseen_mails.append(mail)
						if firstcheck: # first check after startup
							new_mails.append(mail)
				
				else: # mail is fetched the first time
					unseen_mails.append(mail)
					new_mails.append(mail)
					script_data += ' "<%s> %s"' % (mail.sender, mail.subject)
					script_data_mailcount += 1
			
			script_data = str(script_data_mailcount) + script_data
		
			if len(self.mail_list) == 0:
				 # no mails (e.g. email client has been launched) -> close notifications
				for n in self.notifications.itervalues():
					n.close()
				self.notifications = {}
			elif len(new_mails) > 0:
				if self.cfg.get('general', 'notification_mode') == '1':
					self.notify_summary(unseen_mails)
				else:
					self.notify_single(new_mails)

				if self.cfg.get('general', 'playsound') == '1': # play sound?
					gstplay(get_data_file(self.cfg.get('general', 'soundfile')))

			self.reminder.save(self.mail_list)

		self.run_user_scripts("on_mail_check", script_data) # process user scripts
		
		sys.stdout.flush() # write stdout to log file
		return True