#NEWLINE# def process_queue( q , quiet = False ) : #NEWLINE# #INDENT# if ( not quiet ) : #NEWLINE# #INDENT# print ( ( 'Processing: %s' % q ) ) #NEWLINE# #UNINDENT# if ( q . socks_proxy_type and q . socks_proxy_host and q . socks_proxy_port ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# import socks #NEWLINE# #UNINDENT# except ImportError : #NEWLINE# #INDENT# raise ImportError ( 'Queue has been configured with proxy settings, but no socks library was installed. Try to install PySocks via pypi.' ) #NEWLINE# #UNINDENT# proxy_type = { #NEWLINE# #INDENT# 'socks4' : socks . SOCKS4 , #NEWLINE# 'socks5' : socks . SOCKS5 , #NEWLINE# #UNINDENT# } . get ( q . socks_proxy_type ) #NEWLINE# socks . set_default_proxy ( proxy_type = proxy_type , addr = q . socks_proxy_host , port = q . socks_proxy_port ) #NEWLINE# socket . socket = socks . socksocket #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# socket . socket = socket . _socketobject #NEWLINE# #UNINDENT# email_box_type = ( settings . QUEUE_EMAIL_BOX_TYPE if settings . QUEUE_EMAIL_BOX_TYPE else q . email_box_type ) #NEWLINE# if ( email_box_type == 'pop3' ) : #NEWLINE# #INDENT# if ( q . email_box_ssl or settings . QUEUE_EMAIL_BOX_SSL ) : #NEWLINE# #INDENT# if ( not q . email_box_port ) : #NEWLINE# #INDENT# q . email_box_port = 995 #NEWLINE# #UNINDENT# server = poplib . POP3_SSL ( ( q . email_box_host or settings . QUEUE_EMAIL_BOX_HOST ) , int ( q . email_box_port ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not q . email_box_port ) : #NEWLINE# #INDENT# q . email_box_port = 110 #NEWLINE# #UNINDENT# server = poplib . POP3 ( ( q . email_box_host or settings . QUEUE_EMAIL_BOX_HOST ) , int ( q . email_box_port ) ) #NEWLINE# #UNINDENT# server . getwelcome ( ) #NEWLINE# server . user ( ( q . email_box_user or settings . QUEUE_EMAIL_BOX_USER ) ) #NEWLINE# server . pass_ ( ( q . email_box_pass or settings . QUEUE_EMAIL_BOX_PASSWORD ) ) #NEWLINE# messagesInfo = server . list ( ) [ 1 ] #NEWLINE# for msg in messagesInfo : #NEWLINE# #INDENT# msgNum = msg . split ( ' ' ) [ 0 ] #NEWLINE# msgSize = msg . split ( ' ' ) [ 1 ] #NEWLINE# full_message = '\n' . join ( server . retr ( msgNum ) [ 1 ] ) #NEWLINE# ticket = ticket_from_message ( message = full_message , queue = q , quiet = quiet ) #NEWLINE# if data : #NEWLINE# #INDENT# server . dele ( msgNum ) #NEWLINE# #UNINDENT# #UNINDENT# server . quit ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( email_box_type == 'imap' ) : #NEWLINE# #INDENT# if ( q . email_box_ssl or settings . QUEUE_EMAIL_BOX_SSL ) : #NEWLINE# #INDENT# if ( not q . email_box_port ) : #NEWLINE# #INDENT# q . email_box_port = 993 #NEWLINE# #UNINDENT# server = imaplib . IMAP4_SSL ( ( q . email_box_host or settings . QUEUE_EMAIL_BOX_HOST ) , int ( q . email_box_port ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( not q . email_box_port ) : #NEWLINE# #INDENT# q . email_box_port = 143 #NEWLINE# #UNINDENT# server = imaplib . IMAP4 ( ( q . email_box_host or settings . QUEUE_EMAIL_BOX_HOST ) , int ( q . email_box_port ) ) #NEWLINE# #UNINDENT# server . login ( ( q . email_box_user or settings . QUEUE_EMAIL_BOX_USER ) , ( q . email_box_pass or settings . QUEUE_EMAIL_BOX_PASSWORD ) ) #NEWLINE# server . select ( q . email_box_imap_folder ) #NEWLINE# ( status , data ) = server . search ( None , 'NOT' , 'DELETED' ) #NEWLINE# if data : #NEWLINE# #INDENT# msgnums = data [ 0 ] . split ( ) #NEWLINE# for num in msgnums : #NEWLINE# #INDENT# ( status , data ) = server . fetch ( num , '(RFC822)' ) #NEWLINE# ticket = ticket_from_message ( message = data [ 0 ] [ 1 ] , queue = q , quiet = quiet ) #NEWLINE# if ticket : #NEWLINE# #INDENT# server . store ( num , '+FLAGS' , '\\Deleted' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# server . expunge ( ) #NEWLINE# server . close ( ) #NEWLINE# server . logout ( )