def _parallel(DEFAULT, host, port): sessions = DEFAULT['-s'] messages = DEFAULT['-m'] # Get the delay wait = delay.delay(DEFAULT) to_list = recipient_count.create_recipient(DEFAULT['-t'], DEFAULT['-r']) COUNT = 0 servers = [] time_elapse = 0 # Connect to servers for j in range(0, sessions): server = connect(DEFAULT, host, port) servers.append(server) # Send a <sessions> amount of messages parallel times = int(round(messages/sessions, 0)) for i in range(0, times): COUNT, _time = send_parallel(DEFAULT, sessions, COUNT, wait, to_list, servers, host, port) time_elapse += _time # Send the <rest> amount of the messages parallel rest = messages - times*sessions if rest > 0: COUNT, _time = send_parallel(DEFAULT, rest, COUNT, wait, to_list, servers, host, port) time_elapse += _time # If didn't close all the servers, close them now. if (DEFAULT['-d']): for i in range(0, sessions): disconnect(DEFAULT, servers[i], host, port) return COUNT, time_elapse
def _series(DEFAULT, host, port): COUNT = 0 time_xtra = 0 wait = delay.delay(DEFAULT) to_list = recipient_count.create_recipient(DEFAULT['-t'], DEFAULT['-r']) ## All the parameters that contains 'time' is to calculate the total time taken to Connect to server, Send mails, and Disconnect. time_st = time.time() # Connect to host server = connect(DEFAULT, host, port) # If no message's body specified, send the email with default-message-body for j in range(0, DEFAULT['-m']): # Create email and display counter _time_xtra = time.time() message = create_mail.create_mail(DEFAULT) COUNT += 1 display_options.display_counter(DEFAULT['-c'], COUNT) if (DEFAULT['-N']): to_list = recipient_count.change_recipient(DEFAULT['-t'], j) time_xtra += time.time() - _time_xtra # Send email send(DEFAULT, server, to_list, message, COUNT, host, port) # Delay time.sleep(wait) # If want to disconnect, quit server and reconnect for next message if (not DEFAULT['-d']) and (j < DEFAULT['-m']-1): disconnect(DEFAULT, server, host, port) server = connect(DEFAULT, host, port) disconnect(DEFAULT, server, host, port) time_elapse = time.time() - time_st - time_xtra return COUNT, time_elapse