示例#1
0
def smtp_source2(params):

	# Analyze the command
	params, _time = read_command(params)
	command = ' '.join(params)
	if (_time):
		start_t = time()
		os.system(command)
		elapse = time() - start_t
		display_options.display_time(_time, elapse)
	else:
		os.system(command)
示例#2
0
def smtp_sauce(params):
	
	# Options dictionary
	INITIAL = {'default_body': 'Text goes here.',
			'logfile': '',
			'-4' : False, 
			'-6' : False, 
			'-a' : '',
			'-A' : False,
			'-c' : False,
			'-C' : 0,
			'-d' : False, 
			'-f' : 'foo', 
			'-F' : '',
			'-l' : 0,
			'-log': False,
			'-L' : False,
			'-o' : False,
			'-ra': '', 
			'-rl': [0, 0], 
			'-R' : [0, 0],
			'-m' : 1, 
			'-M' : '', 
			'-N' : False,
			'-r' : 1, 
			'-s' : 1, 
			'-S' : '', 
			'-t' : ['foo'],
			'-T' : 0,
			'-tm': False,
			'-v' : 0,
			'-w' : 0}

	DEFAULT = INITIAL	#Initialize default values
	COUNT = 0
	LOGFILE = "smtp.log"

	# Create 'from' address from the host
	hostname = gethostname()
	DEFAULT['-f'] = '%s@%s' % (DEFAULT['-f'], hostname)
	DEFAULT['-t'][0] = '%s@%s' % (DEFAULT['-t'][0], hostname)

	host, port = read_command(params, DEFAULT)
	old_val, syschange = windowsize.change_default(DEFAULT['-T'])	# Change TCP windowsize
	if DEFAULT['-log']:
		logpath = os.path.join(os.getcwd(), LOGFILE)
		DEFAULT['logfile'] = open(logpath, 'w')
	# Create and send mails
	if DEFAULT['-s'] > 1:
		COUNT, time_elapse = send_mail._parallel(DEFAULT, host, port)
	else:
		COUNT, time_elapse = send_mail._series(DEFAULT, host, port)

	
	windowsize.restore_default(DEFAULT['-T'], old_val, syschange)	# Restore TCP windowsize

	# Print counter and timer
	if (DEFAULT['-c']):
		os.system('echo %s' % COUNT)
	display_options.display_time(DEFAULT['-tm'], time_elapse)
	if DEFAULT['-log']:
		DEFAULT['logfile'].close()
	return 0