Welcome, guest | Sign In | My Account | Store | Cart

it use to fetchmail & distribute into every user...for now only use for local but...only in class form..for now that i can present. use "class fetch_mail first" -> "class re_ex"

Python, 133 lines
  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
#!/usr/bin/python
'''
This locust_fetchmail -----------------------------------------open source one
'''
import poplib, re, time, os, string

class re_ex:

    def __init__(self, domain):
        #self.user   = user
        self.domain = domain
        
    def split_user(self, str):
        user    = string.split(str, "@")
	user_	= string.split(user[1], "\012")
	user	= string.split(user[0], "Delivered-To: ")
        return user[1], user_[0]
    
    def list_user(self, domaiN):
	
        list = os.listdir("/home/vpopmail/domains/"+domaiN+"")
        return list

    def check_user(self,user, list):
        print user
	i = 0
        flag = 0
        while i < len(list):
            if user == list[i]:
                flag = 1
            else:
                flag = 0
	    i = i + 1
        if flag == 1 :
            return flag, user
        else:
            return flag, user

        
        
    def find(self):
        file    = open("../domains/"+self.domain+".txt","r")
        read1   = file.readlines()
        file.close()
	#user_len = 0
        i = 0              
        while i < len(read1):
            isi     = re.search("Return-Path",read1[i])
            re1	= read1[i]
            if isi != None:
                isi2 	= re.search("Delivered-To:",read1[i+1])
                re2	        = read1[i+1]
                list_	= []
                if isi2 != None :
		    #user_len = user_len + 1
		    list_.append(re1)
                    list_.append(re2)
                    i = i + 2
                    flag = 1
                    while 1 :
                        try:
                                isi3 	= re.search("Return-Path",read1[i])
                                re3	        = read1[i]
                                if isi3 != None:
                                    isi4 = re.search("Delivered-To:",read1[i+1])
                                    if isi4 != None :
                                        break
                                    else:
                                        list_.append(re3)
                                else:
                                    list_.append(read1[i])
                                    i = i + 1
                        except:
                                flag = 0
                                break
                                
                                             
                
                    if flag != 0:
                        
                        user , domain   = self.split_user(re2)
		        list_users      = self.list_user(domain)
                        check           = self.check_user(user, list_users)
			self.user       = user
   					
	               	if check[0] == 1 :
                            file_nm     = "locust_fetchmail_4_"+self.domain+"_"+str(i)+"_"+str(time.time())+".lfm"
                            write_mail  = open("/home/vpopmail/"+self.domain+"/"+self.user+"/Maildir/new/"+file_nm+"", "w")
                            
			    
			    for vol in list_:
                                write_mail.write(vol)
                            write_mail.close()
                            os.popen("chown vpopmail.vchkpw "+file_nm+"")
                        else:
                            file_nm     = "locust_fetchmail_4_"+self.domain+"_"+str(time.time())+".lfm"
                            write_mail  = open("/temp/"+file_nm+"", "w")
                            for vol in list_:
                                write_mail.write(vol)
                            write_mail.close()
                            os.popen("chown vpopmail.vchkpw "+file_nm+"")
                                
            
            
            


class fetch_mail:

    def __init__(self, user, pass_, domain, IP):

        self.user   = user
        self.pass_  = pass_
        self.domain = domain
        self.IP     = IP
        

    def pop3_(self):

        M = poplib.POP3(self.IP)
        M.user(self.user+"@"+self.domain)
        M.pass_(self.pass_)
        numMessages = len(M.list()[1])
        list_   = []
        for i in range(numMessages):
            for j in M.retr(i+1)[1]:
                list_.append(j)

        file    = open("../domains/"+self.domain+".txt","w")
        for k in list_:
        	
	   	file.write(k+"\n")
        file.close()

it might be...useful 4 every one