<commit_before>#########################################################################
# Filename: mod_gmail.py
# Description: This module reads email from a gmail account via IMAP. It
#	       support keywords searches and looking for specific senders
# Copyright (C) 2011-2012 AntiTree
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or 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 Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# SpicyMango written by: <NAME>, <NAME>, <NAME>
# Website: http://code.google.com/p/spicymango/
# Download: svn co http://spicymango.googlecode.com/svn/trunk/ spicymango/
#
#########################################################################

import thread,sys
sys.path.append("..")
from src.core import *
from src.output import *
import imaplib, email
#import json, urllib2, urllib, time

#Read in code to dynamically get the module name.
execfile('src/getname')

#Get configuration options
interval = int(check_config("MOD_GMAIL_INTERVAL="))
gmail = check_config("MOD_GMAIL_EMAIL=")
password  = check_config("MOD_GMAIL_PASSWORD=")

def main(gmail, password, mailbox, *args):
	global interval
	while True:
		body = ""
		mail = imaplib.IMAP4_SSL('imap.gmail.com')
		mail.login(gmail, password)
		try: 
		  mail.select(mailbox)
  		except
		  print_error(module, "Incorrect mailbox named: %s" % mailbox)<commit_msg>added catch for connection resets<commit_after>#########################################################################
# Filename: mod_gmail.py
# Description: This module reads email from a gmail account via IMAP. It
#	       support keywords searches and looking for specific senders
# Copyright (C) 2011-2012 AntiTree
#
#    This program is free software: you can redistribute it and/or modify
#    it under the terms of the GNU Affero General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or 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 Affero General Public License for more details.
#
#    You should have received a copy of the GNU Affero General Public License
#    along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# SpicyMango written by: <NAME>, <NAME>, <NAME>
# Website: http://code.google.com/p/spicymango/
# Download: svn co http://spicymango.googlecode.com/svn/trunk/ spicymango/
#
#########################################################################

import thread,sys
sys.path.append("..")
from src.core import *
from src.output import *
import imaplib, email
#import json, urllib2, urllib, time

#Read in code to dynamically get the module name.
execfile('src/getname')

#Get configuration options
interval = int(check_config("MOD_GMAIL_INTERVAL="))
gmail = check_config("MOD_GMAIL_EMAIL=")
password  = check_config("MOD_GMAIL_PASSWORD=")

def main(gmail, password, mailbox, *args):
	global interval
	while True:
		body = ""
		try: 
		  mail = imaplib.IMAP4_SSL('imap.gmail.com')
		  mail.login(gmail, password)
		except:
   		  print_error(module, "Connection reset by gmail...Trying again")
		  break
		try: 
		  mail.select(mailbox)
  		except:
		  print_error(module, "Incorrect mailbox named: %s" % mailbox)
{'fraction_non_alphanumeric': 0.1613484302624807, 'fraction_numerical': 0.005661348430262481, 'mean_word_length': 4.4363636363636365, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3786321', 'n_tokens_mistral': 1159, 'n_tokens_neox': 1114, 'n_words': 408}