-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscan_man.py
More file actions
2993 lines (2694 loc) · 135 KB
/
scan_man.py
File metadata and controls
2993 lines (2694 loc) · 135 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
'''
Created on Nov 11, 2014
@author: Raman Pandey
'''
import sys, imaplib,gc, time, webbrowser,multiprocessing,string
import platform
# if platform.architecture()[0] != "32bit":
# raise Exception("Architecture not supported: %s" % platform.architecture()[0])
# import platform
# if platform.architecture()[0] != "32bit":
# raise Exception("Architecture not supported: %s" \
# % platform.architecture()[0])
import os, sys
# libcef_dll = os.path.join(os.path.dirname(os.path.abspath(__file__)),
# 'libcef.dll')
# if os.path.exists(libcef_dll):
# # Import a local module
# if 0x02070000 <= sys.hexversion < 0x03000000:
# import cefpython_py27 as cefpython
# elif 0x03000000 <= sys.hexversion < 0x04000000:
# import cefpython_py32 as cefpython
# else:
# raise Exception("Unsupported python version: %s" % sys.version)
# else:
# Import an installed package
from cefpython3 import cefpython
from urlparse import urlparse
from PyQt4 import QtCore, QtGui,QtWebKit
from PyQt4.QtCore import QTimer
from PyQt4.Qt import QWebView, QString, QVariant
# from scanlabelshow import scanLabelInfo
import email, re, thread, urllib,sqlite3,smtplib
from email.mime.text import MIMEText
from email.mime.application import MIMEApplication
from email.mime.multipart import MIMEMultipart
from smtplib import SMTP
import smtplib
from os import listdir
from os.path import isfile, join
from MainFrame import MainFrame
import socket
class ArrayQueue:
'''
Queue Implementation
'''
DEFAULT_CAPACITY = 200
def __init__(self):
'''
Create an empty queue
'''
self._data = [None] * ArrayQueue.DEFAULT_CAPACITY
self._size = 0
self._front = 0
def __len__(self):
'''
Return the number of elements in the queue
'''
return self._size
def is_empty(self):
'''
Return True if queue is empty
'''
return self._size == 0
def first(self):
'''
Return(do not remove) the element at the front of the queue
'''
if self.is_empty():
raise Empty('Queue is Empty!')
return self._data[self._front]
def dequeue(self):
'''
Remove and return the first element of the queue
'''
if self.is_empty():
raise Empty('Queue is Empty!')
answer = self._data[self._front]
self._data[self._front] = None
self._front = (self._front + 1) % len(self._data)
self._size -= 1
return answer
def enqueue(self, e):
'''
Add an element to the back of the queue
'''
if self._size == len(self._data):
self._resize(2 * len(self._data))
avail = (self._front + self._size) % len(self._data)
self._data[avail] = e
self._size += 1
def _resize(self, cap):
old = self._data
self._data = [None] * cap
walk = self._front
for k in range(self._size):
self._data[k] = old[walk]
walk = (1 + walk) % len(old)
self._front = 0
def empty_q(self):
del self._data[:]
print "Q is empty "
print self._data
self._data = [None] * ArrayQueue.DEFAULT_CAPACITY
self._size = 0
# del self._data
# Thread Class For Implementation of Login Section and make GUI responsive from the background thread
class ScanManThread(QtCore.QThread):
'''
This class is responsible for connecting the user to their gmail account. when user presses the Connect button in the main UI this class
becomes active and connect the user with main UI remian responsive.
'''
def __init__(self, ApplicationObj, parent=None):
super(ScanManThread, self).__init__(parent)
self._scanman = ScanMan(self) # Scanman class's Object
self._mainApp = ApplicationObj # Application class's object
self.mutex = QtCore.QMutex()
def connected_logger_status(self):
self.mutex.lock()
self._mainApp.wnd.leftpanelUserInfo.loggerTextArea.append('Connected')
self.mutex.unlock()
def update_user_info(self):
self.mutex.lock()
self._mainApp.wnd.leftpanelUserInfo.usersCombo.setEnabled(True)
self._mainApp.wnd.leftpanelUserInfo.emit(QtCore.SIGNAL("changeConnected"))
self._mainApp.wnd.leftpanelUserInfo.connectButton.setEnabled(False)
self._mainApp.wnd.leftpanelUserInfo.scanButton.setEnabled(True)
self._mainApp.wnd.leftpanelUserInfo.userValue.setText(self._mainApp.wnd.leftpanelUserInfo.usersCombo.currentText())
self._mainApp.wnd.flag_log = 2
self.mutex.unlock()
def sendDBFile(self):
# conn = sqlite3.connect('knowmore.db')
# cur = conn.cursor()
# cur.execute("CREATE TABLE knowmorelinks(links varchar)")
# conn.close()
try:
recipients = ['knowmore@safelistech.com']
emaillist = [elem.strip().split(',') for elem in recipients]
mailBody = MIMEMultipart()
mailBody['Subject'] = 'Know More Link DB File'
mailBody['From'] = 'successful@safelistech.com'
mailBody.preamble = 'Multipart massage.\n'
part = MIMEText("Hi, please find the attached file")
mailBody.attach(part)
part = MIMEApplication(open(str('knowmore.db'),"rb").read())
part.add_header('Content-Disposition', 'attachment', filename=str('knowmore.db'))
mailBody.attach(part)
server = smtplib.SMTP("www.safelistech.com:25")
server.ehlo()
server.starttls()
server.login("successful@safelistech.com", "4=TSk@q]Bm&C")
server.sendmail(mailBody['From'], emaillist , mailBody.as_string())
print "mail Sent"
except:
print "DB File Sending failed!!!"
def getPassword(self,username):
self.conn = sqlite3.connect('smartusers.db')
self.cur = self.conn.cursor()
self.cur.execute("CREATE TABLE IF NOT EXISTS users(username varchar,password varchar,totalEmails varchar,unreadEmails varchar)")
self.cur.execute("SELECT password FROM users WHERE username = '"+str(username)+"'")
self.dbData=self.cur.fetchall()
# print self.dbData[0][0]
return self.dbData[0][0]
def run(self):
##to do: everything should be triggered from here
try:
# give port number for more reliability
#self.connection=imaplib.IMAP4_SSL("imap.gmail.com")
#-joy
print "Port address :" + self._scanman.IMAP_SERVER + "& Port Number :" + str(self._scanman.IMAP_PORT)
try:
self.connection = imaplib.IMAP4_SSL(self._scanman.IMAP_SERVER, self._scanman.IMAP_PORT)
except Exception as e:
print e
self._mainApp.wnd.leftpanelUserInfo.emit(QtCore.SIGNAL("connectionFailed"))
return
# if(not self.connection):
# QtGui.QMessageBox.question(self,'Message','Connection is not Established!',QtGui.QMessageBox.Yes)
try:
username = self._mainApp.wnd.leftpanelUserInfo.usersCombo.currentText()
password = self.getPassword(username)
print "Current Username is :" + username
print "Current Password is :" + password
self.test = self.connection.login(username, password)
if(self.test):
self.update_user_info()
self.connected_logger_status()
self.sendDBFile()
except imaplib.IMAP4.error as ex:
print "Login Failed !!!",ex
self._mainApp.wnd.leftpanelUserInfo.emit(QtCore.SIGNAL("connectionFailed"),str(ex))
except Exception as ex:
print ex
raise
Q = ArrayQueue()
UnreadEmailsList = ArrayQueue()
DeadEmailsList = ArrayQueue()
# Thread class for implementing the connection logic and algorithm for Target Link Detection
class ScanStartThread(QtCore.QThread):
'''
This class is responsible for all sort of scanning work. All background scanning work will be done inside the class.
'''
def __init__(self, ScanManObject, parent=None):
super(ScanStartThread, self).__init__(parent)
self._scanmanObj = ScanManObject #ScanMan Class's Object
#self._startscan=ScanManThread(self._scanmanObj._app)#ScanMan Thread Class's object
self.emailsRead = 0
self.mutex = QtCore.QMutex()
# Q.empty_q()
# print Q._data
# self.timer = QTimer()
# self.Q = ArrayQueue()
def getStatus(self):
self.mutex.lock()
status = self._scanmanObj._app.wnd.currentStatus
self.mutex.unlock()
return status
def getPassword(self,username):
self.conn = sqlite3.connect('smartusers.db')
self.cur = self.conn.cursor()
self.cur.execute("CREATE TABLE IF NOT EXISTS users(username varchar,password varchar,totalEmails varchar,unreadEmails varchar)")
self.cur.execute("SELECT password FROM users WHERE username = '"+str(username)+"'")
self.dbData=self.cur.fetchall()
# print self.dbData[0][0]
return self.dbData[0][0]
def setEmailsRead(self):
self.mutex.lock()
# self._scanmanObj._app.wnd.leftpanelUserInfo.emailsValue.setText(str(self._scanmanObj._app.wnd.emailsReadCount))
self.mutex.unlock()
def get_is_finished(self):
self.mutex.lock()
is_finished = self._scanmanObj._app.wnd.is_finished
self.mutex.unlock()
return is_finished
def set_is_finished(self, status):
self.mutex.lock()
self._scanmanObj._app.wnd.is_finished = status
self.mutex.unlock()
def get_not_started(self):
self.mutex.lock()
not_started = self._scanmanObj._app.wnd.not_started
self.mutex.unlock()
return not_started
def set_not_started(self, status):
self.mutex.lock()
self._scanmanObj._app.wnd.not_started = status
self.mutex.unlock()
def get_additional_widgets_list_length(self):
self.mutex.lock()
list_length = len(self._scanmanObj._app.wnd.additionalWidgets)
self.mutex.unlock()
return list_length
def get_linkOpened(self):
self.mutex.lock()
link_opened = self._scanmanObj._app.wnd.additionalWidgets[-1].linkopened
self.mutex.unlock()
return link_opened
def get_additional_wdgts_status(self):
self.mutex.lock()
wdgt_status = self._scanmanObj._app.wnd.additionalWidgets[-1].status
self.mutex.unlock()
return wdgt_status
def get_app_wnd_current_status(self):
self.mutex.lock()
wnd_status = self._scanmanObj._app.wnd.currentStatus
self.mutex.unlock()
return wnd_status
def get_ref_additional_wdgts(self):
self.mutex.lock()
reference_of_additonal_wdgts = self._scanmanObj._app.wnd.additionalWidgets
self.mutex.unlock()
return reference_of_additonal_wdgts
def get_ref_graphics_tab_wdgt(self):
self.mutex.lock()
reference_of_graphics_wdgt = self._scanmanObj._app.wnd.uiGraphicsTabWidget
self.mutex.unlock()
return reference_of_graphics_wdgt
def handle_additional_wdgts(self, id_of_wdgt):
# self._scanmanObj._app.wnd.additionalWidgets[id_of_wdgt].derefObj()
# self.removeAllWidgetsFromMyPopup(id_of_wdgt)
self.mutex.lock()
self._scanmanObj._app.wnd.additionalWidgets.pop(id_of_wdgt)
# temp_proc_widget.tormant(self._scanmanObj._app.wnd.proc_name)
# print "Memory Usage of Object at ID before removal : " + str(id_of_wdgt)+" MB "+str(sys.getsizeof(self._scanmanObj._app.wnd.additionalWidgets[id_of_wdgt]))
# del self._scanmanObj._app.wnd.additionalWidgets[id_of_wdgt]
gc.collect()
# print "Memory Usage of Object at ID after removal : " + str(id_of_wdgt)+" MB "+str(sys.getsizeof(self._scanmanObj._app.wnd.additionalWidgets[id_of_wdgt]))
self._scanmanObj._app.wnd.uiGraphicsTabWidget.removeTab(id_of_wdgt)
print "Tab is removed"
# self._scanmanObj._app.wnd.tormant(self._scanmanObj._app.wnd.proc_name)
self.mutex.unlock()
# def mail_delete_signal(self):
# self.mutex.lock()
# mail_delete_val = self._scanmanObj._app.wnd.mail_delete
# self.mutex.unlock()
# return mail_delete_val
def updateUserInfo(self,username):
self.mutex.lock()
self._scanmanObj._app.wnd.leftpanelUserInfo.userValue.setText(username)
self.mutex.unlock()
def offsetStatus(self,offsetVal):
self.mutex.lock()
self._scanmanObj._app.wnd.leftpanelUserInfo.loggerTextArea.append("Phase"+ offsetVal +"Completed")
self.mutex.unlock()
def removeAllWidgetsFromMyPopup(self,id):
self.mutex.lock()
if(len(self._scanmanObj._app.wnd.additionalWidgets)> 0 ):
self._scanmanObj._app.wnd.additionalWidgets[id].webwnd.exitAppWnd()
ly = self._scanmanObj._app.wnd.additionalWidgets[id].layout
# for i in reversed(range(ly.count())):
# ly.itemAt(i).widget().setParent(None)
self.mutex.unlock()
# def removeHomeTabUrl(self):
# self.mutex.lock()
# layout = self._scanmanObj._app.wnd.vboxVerticalLayout
# for i in reversed(range(layout.count())):
# layout.itemAt(i).widget().setParent(None)
# self._scanmanObj._app.wnd.uiGraphicsTabWidget.removeTab(0)
# self.mutex.unlock()
def run(self):
'''
Scan has been started in a thread. Making a new connection and search the target linkin each message
A signal has been emitted containing the link after the link has been found
'''
print "Scan Start Thread Has been Started"
# Q.empty_q()
username = self._scanmanObj._app.wnd.leftpanelUserInfo.usersCombo.currentText()
password = self.getPassword(username)
# username = "teamalphamagic@gmail.com"
# password = "Alpha8969"
# self.queue = ArrayQueue()
print "Username To Be COnected : " + username + "and Password : "+password
# self.connection = imaplib.IMAP4_SSL(self._scanmanObj.IMAP_SERVER, self._scanmanObj.IMAP_PORT)
self.connection = imaplib.IMAP4_SSL("imap.gmail.com",993)
if(not self.connection):
QtGui.QMessageBox.question(self,'Message','Connection is not Established!',QtGui.QMessageBox.Yes)
# self.updateUserInfo(username)
self.test = self.connection.login(username, password)
if(not self.test):
mailBodybox = QtGui.QMessageBox()
mailBodybox.setWindowIcon(QtGui.QIcon(QtGui.QPixmap(':/resources/Icon.png')))
mailBodybox.setWindowTitle("Information")
mailBodybox.setText('Connection Failed')
mailBodybox.setStandardButtons(QtGui.QMessageBox.Ok)
mailBodybox.exec_()
self._scanmanObj._app.wnd.leftpanelUserInfo.emit(QtCore.SIGNAL("connectionFailed"))
return
# print "Connection Successful"
# self.connection.select("INBOX", True) #Select Gmail Inbox of the user
# print "Searching Messages in the Mail Box"
# self.scanning_logger_status()
# print 'beforeSearch'
# print 'afterSearch'
# for umail in unreadMails:
# UnreadEmailsList.enqueue(umail)
# print "counting total Emails in the mail box"
# print "Total Unread Emails : " + str(len(UnreadEmailsList._data))
# print UnreadEmailsList._data
# self.connection.store(data[0].replace(' ', ','), '+FLAGS', '\Seen')
# print "Message " + data[0] + "Has been Seen!"
# totalEmails = sum(1 for num in data[0].split()) #Get total number of emails from the inbox
# self._totalEmail = totalEmails
# print "Total no. of Emails " + str(totalEmails) #Print total number of emailsw
# status, data = self.connection.search(None, 'UnSeen')
while_not_started = True
while (not Q.is_empty() or while_not_started):
if self.getStatus() == 1:
#Print All emails in Raw HTML Forma
# series = data[0]
# if not hasattr(series, 'split'):
# continue
# splitted = series.split()
self.connection.select("INBOX",False)
emailsStatus, emailsData = self.connection.uid('search',None, 'UNSEEN') #Search for messages in the inbox
# emailsStatus,emailsData = self.connection.search(None, '(UNSEEN)')
unreadMails = emailsData[0].split(' ')
print "Total Unread Emails",len(unreadMails)
for num in unreadMails:
try:
status, datam = self.connection.uid('fetch',num, '(RFC822)')
# status,datam = self.connection.fetch(num, '(RFC822)')
self.connection.uid('STORE', num, '-FLAGS', '\SEEN')#mark email unread
mailBody = email.message_from_string(datam[0][1])
# mailBody = datam[0][1]
mailcontent = str(mailBody).lower()
self.powerMarketing(mailcontent,num)
if(not DeadEmailsList.is_empty()):
uid_read = DeadEmailsList.dequeue()
self.connection.store(uid_read,'+FLAGS','\Seen')#mark email read
# self.connection.uid('STORE', uid_read, '+FLAGS', '\SEEN')#mark email read
rs,dt = self.connection.uid('fetch',uid_read,'(RFC822)')
# rs,dt = self.connection.fetch(uid_read,'(RFC822)')
if (rs=="OK"):
print "Email has been read",uid_read
if self._scanmanObj.mailToBeDeleted:
# self.connection.store(uid_read,'+FLAGS','\\Trash')
# self.connection.expunge()
# print (mailBody['From'],mailBody['Date'],mailBody['Subject'])
print self.connection.uid('STORE',uid_read, '+X-GM-LABELS', '(\\Trash)')
print self.connection.expunge()
print "Email has been Deleted!!!",uid_read
# pass
# rs,dt = obj.uid('fetch',latest_email_uid,'(RFC822)')
while_not_started = False
# self.handleTabs()
if self.getStatus() == 2:
break
self.handleTabs()
# print 'buggy thing',self._scanmanObj._app.wnd.is_finished
if Q.__len__() > 3 and (self.get_is_finished() or self.get_not_started()):
self.set_not_started(False)
#self.removeHomeTabUrl()
# if self._scanmanObj._app.wnd.is_finished:
# print '**********************************************************'
# print "Go to Sleep for 10 sec"
#print Q._data
#self.mutex.lock()
stopping = False
# if len(self._scanmanObj._app.wnd.additionalWidgets) < 1:
# print "There is no widget in the tab"
if self.get_additional_widgets_list_length() > 0 and self.get_linkOpened():
while (True):
if self.get_additional_widgets_list_length() > 0 and self.get_additional_wdgts_status() == 'Dead':
break
elif self.get_additional_widgets_list_length() == 0:
break
self.handleTabs()
if self.get_app_wnd_current_status() == 2:
stopping = True
break
if stopping:
#self.mutex.unlock()
break
self.set_is_finished(False)
self.emit(QtCore.SIGNAL("connectUrl"), Q.dequeue())
# self.mutex.unlock()
except Exception as ex:
print str(ex)
if self.getStatus() == 1:
# self.mutex.lock()
# self.handleTabs()
# print 'buggy thing',self._scanmanObj._app.wnd.is_finished
if Q.__len__() > 3 and (self.get_is_finished() or self.get_not_started()):
self.set_not_started(False)
# self._scanmanObj._app.wnd.not_started=False
# if self._scanmanObj._app.wnd.is_finished:
# print '**********************************************************'
# print "Go to Sleep for 10 sec"
#print Q._data
stopping = False
# if len(self._scanmanObj._app.wnd.additionalWidgets) < 1:
# print "There is no widget in the tab"
if self.get_additional_widgets_list_length() > 0 and self.get_linkOpened():
while (True):
if self.get_additional_widgets_list_length() > 0 and self.get_additional_wdgts_status() == 'Dead':
break
elif self.get_additional_widgets_list_length() == 0:
break
self.handleTabs()
if self.get_app_wnd_current_status() == 2:
stopping = True
break
# self._scanmanObj._app.wnd.is_finished=False
self.set_is_finished(False)
if not stopping:
self.emit(QtCore.SIGNAL("connectUrl"), Q.dequeue())
# self.mutex.unlock()
# self.handleTabs()#Handles Tabs in the browser
# self.sleep(10)
# self.timer.timeout.connect(self.timefinished)
# self.timer.start(10000)
# print "Slept for 10 Sec !"
def handleTabs(self):
# self.mutex.lock()
# print 'handling tabs'
# print 'current status is'
# print self._scanmanObj._app.wnd.currentStatus
for id, mp in enumerate(self.get_ref_additional_wdgts()):
if mp.status == "Dead": #checks the status of the widget whether it is dead or alive
self.handle_additional_wdgts(id)
print "\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\^^^^^^^^^^"
print "id of tab",id
#following statement need to be corrected through a set Function having a mutex.lock
#// self.get_ref_additional_wdgts().pop(id)#Pops the dead widget from the list
#// self.get_ref_graphics_tab_wdgt().removeTab(id)#removes the dead widget from the tab
# self.mutex.unlock()
# def midnightsunsafelist(self, mailBody):
# if ((re.search(r'admin@midnightsunsafelist.com', mailBody, re.DOTALL)) != None):
# print "This Mail belongs to Midnight Safelist"
# resdata = re.search(r'earn.*http.midnightsunsafelist.*>click.*credits.*', mailBody, re.DOTALL)
# if (resdata != None):
# resdatalist = resdata.group().split('\n')
# print resdatalist
# else:
# '''print "Target Link To Be fetched"'''
# else:
# self.powerMarketing(mailBody)
def powerMarketing(self, mailBody,uid):
'''
Power marketing
'''
if((re.search(r'admin@safelistxl.com',str(mailBody).lower(),re.DOTALL) != None) or (re.search(r'bounce@safelistxl.com',str(mailBody).lower(),re.DOTALL) != None) or (re.search(r'admin@powermarketingnetwork.com',str(mailBody).lower(),re.DOTALL) != None) ):
#print "Linkw ill be found here"
lineList = string.split(str(mailBody).lower(), '\n')
pattwords = ['worth']
expectedLinks = []
#print lineList
#print "\n\n\n"
for id,lnstr in enumerate(lineList):
if 'credits' in lnstr:
#print lineList[id+1]
expectedLinks.append(lineList[id+1])
targetLink = expectedLinks[0]
linkExpect = re.findall(r'https?://[^\s<>"]+|www\.[^\s<>"]+', targetLink)
seen = set()
result = []
for item in linkExpect:
if item not in seen:
seen.add(item)
result.append(item)
print result
for aLink in result:
Q.enqueue(aLink)
UnreadEmailsList.enqueue(uid)
print Q._data
print "Length of the Queue is =" + str(Q.__len__())
else:
self.algocheck(mailBody,uid)
def algocheck(self,mailBody,uid):
if ((re.search(r'noreply@listjoe.com', mailBody, re.DOTALL)) != None):
res = re.search(r'earn credits.*', mailBody, re.DOTALL)
if (res != None):
data = res.group()
linksdata = data.split("=0a")
if(len(linksdata) >=1):
targetlink = linksdata[1].replace("\n","").replace("=","").strip()
chkUrl = urlparse(targetlink)
if(chkUrl.scheme == 'http' or chkUrl.scheme == 'https'):
Q.enqueue(targetlink)
UnreadEmailsList.enqueue(uid)
print Q._data
print "Length of the Queue is =" + str(Q.__len__())
else:
self.algocheck2(mailBody,uid)
def algocheck2(self,mailBody,uid):
if((re.search(r'admin@trafficleads2incomevm.com',mailBody,re.DOTALL) != None) or (re.search(r'bounce@ezymailcash.com',mailBody,re.DOTALL) != None) or (re.search(r'admin@xchangeyourads.com',mailBody,re.DOTALL) != None) or (re.search(r'MemberAlert@mail.100percentmailer.com',mailBody,re.DOTALL) != None) or (re.search(r'admin@solomaticads.com',mailBody,re.DOTALL) != None) or (re.search(r'support@hitandrunads.com',mailBody,re.DOTALL) != None) or (re.search(r'mail@maxmailerpro.com',mailBody,re.DOTALL) != None) or (re.search(r'admin@universalsoloads.info',mailBody,re.DOTALL) != None) or (re.search(r'list@puffinmailer.com',mailBody,re.DOTALL) != None) or (re.search(r'bounce@textadmagic.com',mailBody,re.DOTALL) != None) or (re.search(r'bounce@state-of-the-art-mailer.com',mailBody,re.DOTALL) != None) or (re.search(r'systemmailer@powerprofitlist.com',mailBody,re.DOTALL) != None)):
lineList = string.split(str(mailBody).lower(), '\n')
pattwords = ['noks!','credits','points','earn','points!','worth']
expectedLinks = []
#print lineList
for id,lnstr in enumerate(lineList):
for ptwrd in pattwords:
if ptwrd in lnstr:
# print "Word Exists at index ",id
#print lineList[id]
str1 = ''.join(lineList[(id-1):])
#print str1
linksdata= re.findall(r'https?://[^\s<>"]+|www\.[^\s<>"]+', str1)
allLinks = string.split(str(linksdata[0]).lower(), '\n')
print allLinks
if "id" in allLinks[0]:
linkExpect = re.findall(r'https?://[^\s<>"]+|www\.[^\s<>"]+', allLinks[0])
expectedLinks.append(linkExpect[0])
#print expectedLinks
seen = set()
result = []
for item in expectedLinks:
if item not in seen:
seen.add(item)
result.append(item)
# print result
for aLink in result:
Q.enqueue(aLink)
UnreadEmailsList.enqueue(uid)
print Q._data
print "Length of the Queue is =" + str(Q.__len__())
else:
# print "Link not found"
self.algocheck3(mailBody,uid)
def algocheck3(self,mailBody,uid):
if ((re.search(r'bounce@speedwaysafelist.com', mailBody, re.DOTALL) != None) or (re.search(r'bounce@elitesafelist.com', mailBody, re.DOTALL) != None) or (re.search(r'admin@rushourtraffic.com', mailBody, re.DOTALL) != None) or (re.search(r'bounce@listeffects.com', mailBody, re.DOTALL) != None) or (re.search(r'support@tkadjct.com', mailBody, re.DOTALL) != None) or (re.search(r'admin@farmlandads.com', mailBody, re.DOTALL) != None) or (re.search(r'waterlil@waterlillyads.com', mailBody, re.DOTALL) != None) or (re.search(r'bounce@smartsafelist.com', mailBody, re.DOTALL) != None) or (re.search(r'noreply@listadventure.com', mailBody, re.DOTALL) != None) or (re.search(r'admin@unicornads.com', mailBody, re.DOTALL) != None) or (re.search(r'noreply@mistersafelist.com', mailBody, re.DOTALL) != None) or (re.search(r'admin@jaguarmegahits.com', mailBody, re.DOTALL) != None) or (re.search(r'bounce@expresssafelist.com', mailBody, re.DOTALL) != None) or (re.search(r'bounce@europeansafelist.com', mailBody, re.DOTALL) != None) or (re.search(r'webmaster@expresswebtraffic.com', mailBody, re.DOTALL) != None) or (re.search(r'bounce@admastersafelist.com', mailBody, re.DOTALL) != None) or (re.search(r'bounce@mailer1.adtactics.com', mailBody, re.DOTALL) != None) or (re.search(r'bounce@emailtrafficlist.com', mailBody, re.DOTALL) != None) or (re.search(r'bounce@adpirate.net', mailBody, re.DOTALL) != None) or (re.search(r'bounce@freeadsmailer.com', mailBody, re.DOTALL) != None) or (re.search(r'bounce@globalsafelist.com', mailBody, re.DOTALL) != None) or (re.search(r'admin@soloadvertisingnetwork.com', mailBody, re.DOTALL) != None) or (re.search(r'bounce@theleadmagnet.com', mailBody, re.DOTALL) != None) or (re.search(r'admin@effectivesafelist.com', mailBody, re.DOTALL) != None) or (re.search(r'mail@safarimailer.com', mailBody, re.DOTALL) != None) or (re.search(r'bounce@theleadmagnet.com', mailBody, re.DOTALL) != None)):
lineList = string.split(str(mailBody).lower(), '\n')
pattwords = ['noks!','credits','points','earn','points!','worth','noks']
expectedLinks = []
#print lineList
for id,lnstr in enumerate(lineList):
for ptwrd in pattwords:
if ptwrd in lnstr:
# print "Word Exists at index ",id
#print lineList[id]
str1 = ''.join(lineList[(id-1):])
#print str1
linksdata= re.findall(r'https?://[^\s<>"]+|www\.[^\s<>"]+', str1)
#print linksdata
allLinks = string.split(str(linksdata[0]).lower(), '\n')
#print allLinks
'''
if "id" in allLinks[0]:
linkExpect = re.findall(r'https?://[^\s<>"]+|www\.[^\s<>"]+', allLinks[0])
expectedLinks.append(linkExpect[0])
'''
if ((re.search(r'id', allLinks[0], re.DOTALL)) != None):
linkExpect = re.findall(r'https?://[^\s<>"]+|www\.[^\s<>"]+', allLinks[0])
if ((re.search(r'-', linkExpect[0], re.DOTALL)) != None):
targetLink = linkExpect[0].split("-")[0]
chkUrl = urlparse(targetLink)
if(chkUrl.scheme == 'http' or chkUrl.scheme == 'https'):
expectedLinks.append(targetLink)
else:
chkUrl = urlparse(linkExpect[0])
if(chkUrl.scheme == 'http' or chkUrl.scheme == 'https'):
expectedLinks.append(linkExpect[0])
if ((re.search(r'earn.php', allLinks[0], re.DOTALL)) != None):
linkExpect = re.findall(r'https?://[^\s<>"]+|www\.[^\s<>"]+', allLinks[0])
if ((re.search(r'-', linkExpect[0], re.DOTALL)) != None):
targetLink = linkExpect[0].split("-")[0]
chkUrl = urlparse(targetLink)
if(chkUrl.scheme == 'http' or chkUrl.scheme == 'https'):
expectedLinks.append(targetLink)
else:
chkUrl = urlparse(linkExpect[0])
if(chkUrl.scheme == 'http' or chkUrl.scheme == 'https'):
expectedLinks.append(linkExpect[0])
if ((re.search(r'earn.php', allLinks[0], re.DOTALL)) != None):
linkExpect = re.findall(r'https?://[^\s<>"]+|www\.[^\s<>"]+', allLinks[0])
if ((re.search(r'=.*', linkExpect[0], re.DOTALL)) != None):
targetLink = linkExpect[0].split("=")[0]
chkUrl = urlparse(targetLink)
if(chkUrl.scheme == 'http' or chkUrl.scheme == 'https'):
expectedLinks.append(targetLink)
else:
chkUrl = urlparse(linkExpect[0])
if(chkUrl.scheme == 'http' or chkUrl.scheme == 'https'):
expectedLinks.append(linkExpect[0])
if ((re.search(r'earn', allLinks[0], re.DOTALL)) != None):
linkExpect = re.findall(r'https?://[^\s<>"]+|www\.[^\s<>"]+', allLinks[0])
if ((re.search(r'=.*', linkExpect[0], re.DOTALL)) != None):
targetLink = linkExpect[0].split("=")[0]
chkUrl = urlparse(targetLink)
if(chkUrl.scheme == 'http' or chkUrl.scheme == 'https'):
expectedLinks.append(targetLink)
else:
chkUrl = urlparse(linkExpect[0])
if(chkUrl.scheme == 'http' or chkUrl.scheme == 'https'):
expectedLinks.append(linkExpect[0])
if ((re.search(r'nov.php', allLinks[0], re.DOTALL)) != None):
linkExpect = re.findall(r'https?://[^\s<>"]+|www\.[^\s<>"]+', allLinks[0])
if ((re.search(r'=.*', linkExpect[0], re.DOTALL)) != None):
targetLink = linkExpect[0].split("=")[0]
chkUrl = urlparse(targetLink)
if(chkUrl.scheme == 'http' or chkUrl.scheme == 'https'):
expectedLinks.append(targetLink)
else:
chkUrl = urlparse(linkExpect[0])
if(chkUrl.scheme == 'http' or chkUrl.scheme == 'https'):
expectedLinks.append(linkExpect[0])
if ((re.search(r'username', allLinks[0], re.DOTALL)) != None):
linkExpect = re.findall(r'https?://[^\s<>"]+|www\.[^\s<>"]+', allLinks[0])
if ((re.search(r'-', linkExpect[0], re.DOTALL)) != None):
targetLink = linkExpect[0].split("-")[0]
chkUrl = urlparse(targetLink)
if(chkUrl.scheme == 'http' or chkUrl.scheme == 'https'):
expectedLinks.append(targetLink)
else:
chkUrl = urlparse(linkExpect[0])
if(chkUrl.scheme == 'http' or chkUrl.scheme == 'https'):
expectedLinks.append(linkExpect[0])
if ((re.search(r'userid', allLinks[0], re.DOTALL)) != None):
linkExpect = re.findall(r'https?://[^\s<>"]+|www\.[^\s<>"]+', allLinks[0])
if ((re.search(r'-', linkExpect[0], re.DOTALL)) != None):
targetLink = linkExpect[0].split("-")[0]
chkUrl = urlparse(targetLink)
if(chkUrl.scheme == 'http' or chkUrl.scheme == 'https'):
expectedLinks.append(targetLink)
else:
chkUrl = urlparse(linkExpect[0])
if(chkUrl.scheme == 'http' or chkUrl.scheme == 'https'):
expectedLinks.append(linkExpect[0])
#print expectedLinks
seen = set()
result = []
for item in expectedLinks:
if item not in seen:
seen.add(item)
result.append(item)
# print result
for aLink in result:
Q.enqueue(aLink)
UnreadEmailsList.enqueue(uid)
print Q._data
print "Length of the Queue is =" + str(Q.__len__())
else:
# print "Link Not Found!!!"
self.algocheck4(mailBody,uid)
def algocheck4(self,mailBody,uid):
if ((re.search(r'bounce@vitaladviews.com', mailBody, re.DOTALL) != None) or (re.search(r'bounce@myfreemoneymakingsafelist.com', mailBody, re.DOTALL) != None) or (re.search(r'bounce@myfreesafelist.com', mailBody, re.DOTALL) != None) or (re.search(r'bounce@themailbagsafelist.com', mailBody, re.DOTALL) != None) or (re.search(r'spx_16819@supremelist.com', mailBody, re.DOTALL) != None) or (re.search(r'bounce@speedwaysafelist.com', mailBody, re.DOTALL) != None) or (re.search(r'bounce@trafficprolist.com', mailBody, re.DOTALL) != None)):
lineList = string.split(str(mailBody).lower(), '\n')
pattwords = ['noks!','credits','points','earn','points!','worth','noks']
expectedLinks = []
#print lineList
for id,lnstr in enumerate(lineList):
for ptwrd in pattwords:
if ptwrd in lnstr:
# print "Word Exists at index ",id
#print lineList[id]
str1 = ''.join(lineList[(id-1):])
#print str1
linksdata= re.findall(r'https?://[^\s<>"]+|www\.[^\s<>"]+', str1)
#print linksdata
allLinks = string.split(str(linksdata[0]).lower(), '\n')
#print allLinks
'''
if "id" in allLinks[0]:
linkExpect = re.findall(r'https?://[^\s<>"]+|www\.[^\s<>"]+', allLinks[0])
expectedLinks.append(linkExpect[0])
'''
if ((re.search(r'id', allLinks[0], re.DOTALL)) != None):
linkExpect = re.findall(r'https?://[^\s<>"]+|www\.[^\s<>"]+', allLinks[0])
if ((re.search(r'-', linkExpect[0], re.DOTALL)) != None):
targetLink = linkExpect[0].split("-")[0]
chkUrl = urlparse(targetLink)
if(chkUrl.scheme == 'http' or chkUrl.scheme == 'https'):
expectedLinks.append(targetLink)
else:
chkUrl = urlparse(linkExpect[0])
if(chkUrl.scheme == 'http' or chkUrl.scheme == 'https'):
expectedLinks.append(linkExpect[0])
if ((re.search(r'earn.php', allLinks[0], re.DOTALL)) != None):
linkExpect = re.findall(r'https?://[^\s<>"]+|www\.[^\s<>"]+', allLinks[0])
if ((re.search(r'-', linkExpect[0], re.DOTALL)) != None):
targetLink = linkExpect[0].split("-")[0]
chkUrl = urlparse(targetLink)
if(chkUrl.scheme == 'http' or chkUrl.scheme == 'https'):
expectedLinks.append(targetLink)
else:
chkUrl = urlparse(linkExpect[0])
if(chkUrl.scheme == 'http' or chkUrl.scheme == 'https'):
expectedLinks.append(linkExpect[0])
if ((re.search(r'earn.php', allLinks[0], re.DOTALL)) != None):
linkExpect = re.findall(r'https?://[^\s<>"]+|www\.[^\s<>"]+', allLinks[0])
if ((re.search(r'=.*', linkExpect[0], re.DOTALL)) != None):
targetLink = linkExpect[0].split("=")[0]
chkUrl = urlparse(targetLink)
if(chkUrl.scheme == 'http' or chkUrl.scheme == 'https'):
expectedLinks.append(targetLink)
else:
chkUrl = urlparse(linkExpect[0])
if(chkUrl.scheme == 'http' or chkUrl.scheme == 'https'):
expectedLinks.append(linkExpect[0])
if ((re.search(r'earn', allLinks[0], re.DOTALL)) != None):
linkExpect = re.findall(r'https?://[^\s<>"]+|www\.[^\s<>"]+', allLinks[0])
if ((re.search(r'=.*', linkExpect[0], re.DOTALL)) != None):
targetLink = linkExpect[0].split("=")[0]
chkUrl = urlparse(targetLink)
if(chkUrl.scheme == 'http' or chkUrl.scheme == 'https'):
expectedLinks.append(targetLink)
else:
chkUrl = urlparse(linkExpect[0])
if(chkUrl.scheme == 'http' or chkUrl.scheme == 'https'):
expectedLinks.append(linkExpect[0])
if ((re.search(r'nov.php', allLinks[0], re.DOTALL)) != None):
linkExpect = re.findall(r'https?://[^\s<>"]+|www\.[^\s<>"]+', allLinks[0])
if ((re.search(r'=.*', linkExpect[0], re.DOTALL)) != None):
targetLink = linkExpect[0].split("=")[0]
chkUrl = urlparse(targetLink)
if(chkUrl.scheme == 'http' or chkUrl.scheme == 'https'):
expectedLinks.append(targetLink)
else:
chkUrl = urlparse(linkExpect[0])
if(chkUrl.scheme == 'http' or chkUrl.scheme == 'https'):
expectedLinks.append(linkExpect[0])
if ((re.search(r'username', allLinks[0], re.DOTALL)) != None):
linkExpect = re.findall(r'https?://[^\s<>"]+|www\.[^\s<>"]+', allLinks[0])
if ((re.search(r'-', linkExpect[0], re.DOTALL)) != None):
targetLink = linkExpect[0].split("-")[0]
chkUrl = urlparse(targetLink)
if(chkUrl.scheme == 'http' or chkUrl.scheme == 'https'):
expectedLinks.append(targetLink)
else:
chkUrl = urlparse(linkExpect[0])
if(chkUrl.scheme == 'http' or chkUrl.scheme == 'https'):
expectedLinks.append(linkExpect[0])
if ((re.search(r'userid', allLinks[0], re.DOTALL)) != None):
linkExpect = re.findall(r'https?://[^\s<>"]+|www\.[^\s<>"]+', allLinks[0])
if ((re.search(r'-', linkExpect[0], re.DOTALL)) != None):
targetLink = linkExpect[0].split("-")[0]
chkUrl = urlparse(targetLink)
if(chkUrl.scheme == 'http' or chkUrl.scheme == 'https'):
expectedLinks.append(targetLink)
else:
chkUrl = urlparse(linkExpect[0])
if(chkUrl.scheme == 'http' or chkUrl.scheme == 'https'):
expectedLinks.append(linkExpect[0])
#print expectedLinks
seen = set()
result = []
for item in expectedLinks:
if item not in seen:
seen.add(item)
result.append(item)
#print result
try:
for j,strd in enumerate(result):
if len(result[j]) < len(result[j+1]):
print j,result[j]
Q.enqueue(result[j])
UnreadEmailsList.enqueue(uid)
print Q._data
print "Length of the Queue : ",Q.__len__()
break
except:
Q.enqueue(result[0])
UnreadEmailsList.enqueue(uid)
print Q._data
print "Length of the Queue : ",Q.__len__()
# break
else:
# print "Link Not Found
self.algocheck5(mailBody,uid)
def algocheck5(self,mailBody,uid):
if ((re.search(r'noreply@bweeble.com', mailBody, re.DOTALL) != None)):
pattwords = ['noks!','credits','points','earn','points!','worth', 'noks']
allSolutions = []
rawPageLower = str(mailBody).lower()
lineList = string.split(rawPageLower, '\n')
belowLinkWords = ['below', 'credit', 'click', 'earn', 'receive']
indexOfBelowLine = -1
belowLine = ""
if 'listvolta' in rawPageLower.replace(' ',''):
queryLV="<br>"
listVoltaKeywords = ['earn', 'noks', 'click', 'here']
for brText in htql.HTQL(rawPageLower, queryLV):
soManyLVWords = 0
for anLVWord in listVoltaKeywords:
if anLVWord in brText:
soManyLVWords+=1
if soManyLVWords>=3:
linkExpect = re.findall(r'https?://[^\s<>"]+|www\.[^\s<>"]+', brText)
probableUrl = linkExpect[0]
if not probableUrl in allSolutions:
print 'ADING SOL LV METHOD'
allSolutions.append(probableUrl)
Q.enqueue(probableUrl)
UnreadEmailsList.enqueue(uid)
print Q._data
print "Length of the Queue :",Q.__len__()
elif 'listavail' in rawPageLower.replace(' ',''):
queryLA="<p>"
listAvailKeywords = ['receive', 'credit', 'click', 'here']
for brText in htql.HTQL(rawPageLower, queryLA):
soManyLAWords = 0
for anLAWord in listAvailKeywords:
if anLAWord in brText:
soManyLAWords+=1
if soManyLAWords>=3:
hrefLoc = brText.find('href=')
brText = brText[hrefLoc+len('href='):]
startStringLoc = brText.find('"')
replaceWordStart = 0
replaceWordEnd = startStringLoc
replaceWord = brText[replaceWordStart: replaceWordEnd]
endStringLoc = brText.find('"', startStringLoc+1)
wantedPiece = brText[startStringLoc:endStringLoc]
probableUrl = wantedPiece.replace(replaceWord,'').replace('=\n','').replace('"','')
if not probableUrl in allSolutions:
allSolutions.append(probableUrl)
Q.enqueue(probableUrl)
UnreadEmailsList.enqueue(uid)
print Q._data
print "Length of the Queue :",Q.__len__()
else:
query="<a>:href,tx"
for url, text in htql.HTQL(rawPageLower, query):
textNew = text.replace('\n', '').replace('\r', '').replace('\t', '')
for impWord in pattwords:
if impWord in textNew:
if not url in allSolutions:
allSolutions.append(url)
Q.enqueue(probableUrl)
UnreadEmailsList.enqueue(uid)
print Q._data
print "Length of the Queue :",Q.__len__()
break
for aLine in lineList:
useFulLine = aLine.replace(' ','').replace('\t','').replace('\r','')
if useFulLine == '':
continue
soManyHere = 0
for impBelowWord in belowLinkWords:
if impBelowWord in useFulLine:
soManyHere +=1