ANTI SPAMS
ANTI SPAMS
Bjr à tous !!!
Je vous sollicite, car dans le cadre de mes études (IUT info), je dois réaliser un anti-spam.
J'ai choisit PureBasic, car il est selon moi le langage le plus adapté (dont compatibilité sous LINUX).
J'ai déja réaliser un bout d ecode qui analyse un fichier texte, mais je ne sait pas comment analyser l'arrivée d'email.
Ainsi, si quelqu'un peut m'expliquer comment faire pour créer un anti spams, je lui en serais très reconnaissant !!!!!
Merci bien ....
Je vous sollicite, car dans le cadre de mes études (IUT info), je dois réaliser un anti-spam.
J'ai choisit PureBasic, car il est selon moi le langage le plus adapté (dont compatibilité sous LINUX).
J'ai déja réaliser un bout d ecode qui analyse un fichier texte, mais je ne sait pas comment analyser l'arrivée d'email.
Ainsi, si quelqu'un peut m'expliquer comment faire pour créer un anti spams, je lui en serais très reconnaissant !!!!!
Merci bien ....
www.salemioche.com , tout est expliqué. Avec les fonctions network de PB on peut sans problème dialoguer 


T'as 2 solutions : soit les apis windows, soit tu communiques directement avec les commandes network du genre pour le smtp(de mémoire donc commandes surement fausses):
Code : Tout sélectionner
ID = OpenNetworkConnection("smtp.wanado.fr",25)
Sendnetworkstring(ID,"USER moi" + chr(13) +chr(10),len("USER moi" + chr(13) +chr(10)))
code pour acceder au serveur de mail, je sais plus ou je l'ai trouvé celui là... apparement c'est une "traduction de l'exemple" de client pop3 sur salemioche
panonyme du tout
Code : Tout sélectionner
InitNetwork()
OpenConsole()
#MODE_Authorization = 1
#MODE_Transaction = 2
Login$ = "USER"
Password$ = "PASS"
POP_Provider$ = "POP.PROVIDER"
EOL$ = Chr(13)+Chr(10)
Pop3Mode = #MODE_Authorization
NetWorkID=OpenNetworkConnection(POP_Provider$, 110)
If NetWorkID<>0
PrintN("Connected..")
AllocateMemory(0, 2000, 0)
Repeat
NEvent = NetworkClientEvent(NetWorkID)
If NEvent
ReadLength = ReceiveNetworkData(NetWorkID, UseMemory(0), 2000)
If (ReadLength) > 2
PokeB(UseMemory(0)+ReadLength-2, 0) ; Remove the CRLF directly
Line$ = PeekS(UseMemory(0))
PrintN(Line$)
Gosub ParseLine
Else
PrintN("Bad received packet")
EndIf
Else
Delay(20)
EndIf
ForEver
Else
PrintN("Impossible to connect to the pop3 the server")
EndIf
MessageRequester("Info", "Program finished correctly.", 0)
End
ParseLine:
If Len(Line$) >= 3
If Left(Line$, 3) = "+OK"
Select Pop3Mode
Case #MODE_Authorization
Gosub Authorization
Case #MODE_Transaction
Gosub Transaction
Default
; PrintN("Error: no such case 1")
EndSelect
Else
; PrintN("Error... Deconnect now ! (-ERR)");
EndIf
Else
; PrintN("Error... Too short packet");
EndIf
Return
; Authorization
;the init phase where the user must login..
;
;
Authorization:
Select AuthStep
Case 0
a$ = "USER "+Login$+EOL$
SendNetworkData(NetWorkID, a$, Len(a$))
Case 1
a$ = "PASS "+Password$+EOL$
SendNetworkData(NetWorkID, a$, Len(a$))
Pop3Mode = #MODE_Transaction
;Case 2
; a$ = "QUIT"+EOL$
; SendNetworkData(0, a$, Len(a$))
; Pop3Mode = #MODE_Transaction
EndSelect
AuthStep+1
Return
Transaction:
Select TransStep
Case 0
a$ = "STAT"+EOL$
SendNetworkData(NetWorkID, a$, Len(a$))
Case 1
a$ = "LIST "+EOL$
SendNetworkData(NetWorkID, a$, Len(a$))
Case 2
PrintN("Type msg# to retreive:")
Nb$ = Input()
PrintN(Str(1100))
PrintN("Retrieving...")
; Nb$ = "1"
;a$ = "RETR "+Nb$+EOL$
a$ = "TOP "+Nb$+" 0"+EOL$
SendNetworkData(NetWorkID, a$, Len(a$))
TransStep-1
If CreateFile(0, "MAIL.txt")
FirstTime = 1
Size = 1
Repeat
NEvent = NetworkClientEvent(NetWorkID)
If NEvent
ReadLength = ReceiveNetworkData(NetWorkID, UseMemory(0), 1999)
PokeB(UseMemory(0)+ReadLength, 0)
a$ = PeekS(UseMemory(0))
PrintN(a$)
If FirstTime
Position = FindString(a$, " ", 5)
Size$ = Mid(a$, 5, Position-5)
PrintN(Size$)
Size = Val(Size$)
FirstTime = 0
WriteString(a$)
Size-ReadLength
Else
WriteString(a$)
Size-ReadLength
EndIf
Else
Delay(20)
EndIf
Until Size <= 0 ; And FirstTime = 0
CloseFile(0)
PrintN("Mail transfer finished")
Else
PrintN("Can't open the file...")
EndIf
EndSelect
TransStep+1
Return
Patrick88 ???
pour le bout de code...
fo ke je mette mon adresse email complete pour USER (ex: lionel_om@hotmail.com) ? Puis qu'est-ce que je met pour Provider ?
pour le bout de code...
fo ke je mette mon adresse email complete pour USER (ex: lionel_om@hotmail.com) ? Puis qu'est-ce que je met pour Provider ?

Salut 
Pour le provider, tu dois mettre le compte serveur pop3, mais le problème, c'est que sur hotmail, il ne le donnent pas.
Tu n'as pas une autre adresse ?
Si tu ne veux pas donner ta vraie adresse e-mail, tu dois pouvoir en créer une chez ton fournisseur d'accès, juste le temps de faire tes essais.
Le compte pop3 dépend de ton fournisseur d'accès. Par exemple, pour Wanadoo, pop.wanadoo.fr
Chris

Pour le provider, tu dois mettre le compte serveur pop3, mais le problème, c'est que sur hotmail, il ne le donnent pas.
Tu n'as pas une autre adresse ?
Si tu ne veux pas donner ta vraie adresse e-mail, tu dois pouvoir en créer une chez ton fournisseur d'accès, juste le temps de faire tes essais.
Le compte pop3 dépend de ton fournisseur d'accès. Par exemple, pour Wanadoo, pop.wanadoo.fr
Chris

Ba je V essayé d etrouV qd mm, ms si je ne trouve pa ca sera tant pis.
Sinon voila le code ke j'ai fé pour linstant, il ne gere pa les codes html, mais je rajouteré cette option qd jrriveré a accéder a un msg sur le serveur des fournisseursz d'accès internet.
Voici mon code (ne pas oublier de modifier le nom et le chemin d'accès du fichier a analyser) :
Global email.s, email2.s, email3.s
Global nbr_mot.l, nbr_fil.l, nbr_mot_tab.f, nbr_phrase.l
#MAX_fil.l = 10
Global Filtre.l, pourcentage.f
Filtre = 0
;file_to_open.s = ProgramParameter()
file_to_open.s = "C:\Anti SPAM\texte.txt"
Dim val_fil.l(#MAX_fil)
Dim found.l(#MAX_fil)
Dim found2.l(#MAX_fil)
;'nombre de mots' = nbr par cathé * val de la cathég
Procedure.f nbr_mot_taboo()
nbr.f = 0: tp.f = 0
For i.l = 1 To nbr_fil
tp = found(i)+ ( (found2(i)-found(i)) *1.5)
nbr = nbr + ( val_fil(i) * tp )
Next
ProcedureReturn nbr
EndProcedure
Procedure.l vrai(a.l)
i.l = 0: If a: i = 1: EndIf
ProcedureReturn i
EndProcedure
; autres options de recherches pour déclarer le mail comme spam
Procedure.l other_options()
nbr_p.l = 0: nbr_m.l = 0: nbr_f.l = 0: nbr_h.l = 0: nbr_ph.l = 0
; recherche du signe '%'
For i.l = 1 To Len(email)
If Mid(email,i,1) = "%"
If nbr_p = 0 : nbr_p = 4 : Else : nbr_p = nbr_p + 2: EndIf
EndIf
Next i
; si le spam contient un trop petit nombre de mots
If nbr_mot < 20 : nbr_m = 20 : EndIf
; si les phrases sont trop courtes
If nbr_mot / nbr_phrase < 12: nbr_f = 4: EndIf
If nbr_mot / nbr_phrase < 8: nbr_f = 10: EndIf
If nbr_mot / nbr_phrase < 6: nbr_f = 17: EndIf
If nbr_mot / nbr_phrase < 4: nbr_f = 25: EndIf
; si ya pa bcp de phrases
If nbr_phrase < 8: nbr_ph = 10: EndIf
If nbr_phrase < 5: nbr_ph = 20: EndIf
; recherche de lien vers des sites web
For i.l = 1 To Len(email)-3
If Mid(email,i,4) = "http"
If nbr_h = 0
nbr_h = 4 + vrai(nbr_mot < 20)*10
Else
nbr_h = nbr_h + 2 + vrai(nbr_mot < 20)*6
EndIf
EndIf
Next i
ProcedureReturn nbr_p + nbr_m + nbr_f + nbr_h + nbr_ph
EndProcedure
; Convertion du texte en minuscule et en modifiant les caractères incorrects
Procedure.s convert(a.s)
out.s = " ": tmp.s = "": t.l = 0: cpt.l = 0: nbr_phrase=1: sui.l
; début de la boucle de traitement
For i.l = 1 To Len(a)
tmp = Mid(a,i,1): t = Asc(tmp)
If i < Len(a) :sui = Asc(Mid(a,i+1,1)): Else :suiv = Asc(" "): EndIf
If t > 223
t = t - 32
If t > 191 And t < 199 : tmp = "a": EndIf
If t > 199 And t < 204 : tmp = "e": EndIf
If t = 199 : tmp = "c": EndIf
If t > 203 And t < 208 : tmp = "i": EndIf
If t > 241 And t < 247 : tmp = "o": EndIf
If t > 248 And t < 253 : tmp = "u": EndIf
EndIf
If t < 48 Or (t > 57 And t < 64) Or (t > 90 And t < 97) Or (t > 122 And t <192)
If Right(out,1) = " "
tmp = ""
Else
tmp = " " : If (sui = Asc(" ") Or t=Asc(" ")):cpt = cpt + 1: EndIf
EndIf
EndIf
If (t = 33 Or t = 46 Or t = 59 Or t = 63)And (sui = Asc(" ")) : nbr_phrase = nbr_phrase + 1: EndIf
out = out + tmp
Next i
If Right(out,1) <> " ": out = out + " " : EndIf
nbr_mot = cpt
ProcedureReturn out
EndProcedure
Procedure.s wout_pt(a.s)
out.s = "": tp.l = 0
For i.l = 1 To Len(a)
tp = Asc(Mid(a,i,1))
;si <> ! , . ; ^
If (tp <> 33 And tp <> 44 And tp <> 46 And tp <> 59 And tp <>Asc("^"))
out = out + Chr(tp)
EndIf
Next i
ProcedureReturn out
EndProcedure
; renvoi le nombre de filtre (selon la zone 'data' )
Procedure.l get_filtre_nbr()
Restore Filtre : a.s = "": i.l = 0
While a <> "EOF"
Read a
If Val(a) : l = l + 1 : EndIf
Wend
If l > #MAX_fil : l = #MAX_fil : EndIf
ProcedureReturn l
EndProcedure
; renvoi le nombre d'occurence de a.s présenteent dans 'email2'
Procedure.l recherche(a.s, b.s)
cpt.l = 0
For i.l = 1 To (Len(b) - Len(a))
If a = Mid(b,i,Len(a)) : cpt = cpt + 1: EndIf
Next i
ProcedureReturn cpt
EndProcedure
; chargement des filtres et recherches de ces mots dans le texte
Procedure search_mot_taboo()
Shared filtres, act_fil
Shared nbr_mot, nbr_mot_tab
Restore Filtre
i.l = 0: j.l = 0 : a.s : b.s
;PrintN("Mots trouvees dans les selections :")
For i.l = 1 To nbr_fil
found(i) = 0
Repeat
Read a : b = LCase(a)
If Val(a) = 0
If Left(b,1) = "|"
found(i) = found(i) + recherche(Right(b,Len(b)-1), email2)
found2(i) = found2(i) + recherche(Right(b,Len(b)-1), email3)
Else
found(i) = found(i) + recherche(" " + b + " ", email2)
found2(i) = found2(i) + recherche(" " + b + " ", email3)
EndIf
EndIf
Until Val(a) > 0
val_fil(i) = Val(a)
;PrintN(Str(i) + " " + Str(found(i)) + " " + Str(found2(i)))
Next i
nbr_mot_tab = nbr_mot_taboo()
EndProcedure
; ##################### DEBUT DU PROGRAMME #############################
nbr_fil = get_filtre_nbr()
t.l : t2.s
If (FileSize(file_to_open) > 0)
OpenFile(1,file_to_open)
While (~(Eof(1)))
t2 = ReadString()
If Len(t2) > 2
email = email + t2
t = Asc(Right(email,1))
If (t = 33 Or t = 46 Or t = 59 Or t = 63): email = email + " ": Else : email = email + ". ": EndIf
EndIf
Wend
CloseFile(1)
OpenConsole()
ConsoleTitle("Anti Spams")
email = LCase(email)
email2 = convert(email)
email3 = wout_pt(email)
OpenFile(1,"out.txt")
WriteString(email2)
writestring(Chr(13) + Chr(10))
WriteString(email3)
CloseFile(1)
; recherche des mots filtres dans la variable 'email'
search_mot_taboo()
pourcentage = (nbr_mot_tab * 100 / nbr_mot) + other_options()
If pourcentage > 100 : pourcentage = 100 : EndIf
;affichages
PrintN("Nombre de mots que comporte le mail : " + Str(nbr_mot))
PrintN("Nombre de mots taboo trouves : " + Str(nbr_mot_tab))
PrintN("Pourcentage que ce mail soit un spam : " + Str(pourcentage))
Input(): CloseConsole()
Else
MessageRequester("Erreur", "Erreur lors de l'ouverture du fichier" + Chr(13) + Chr(10) + "Le fichier '" + file_to_open + "' est introuvable.", 0)
EndIf
End
DataSection
Filtre:
;sexe
Data.s "|sex", "|porno", "cul", "cum", "seins", "tits", "viagra", "4"
;finances
Data.s "promotion", "bonnes affaires", "proposons", "|achet", "prix", "discount"
Data.s "|achat", "|en ligne", "produit", "price", "money", "buy", "free"
Data.s "euros", "subsription", "|inscription","2"
;anglais
Data.s "very", "good", "the", "of", "wish", "visit our web site", "new", "1"
; other
Data.s "win", "congratulation", "1"
; fin des données
Data.s "EOF"
EndDataSection
P.S.:
La liste des mots clé n'est que provisoire. Elle va être totalement remodifiée !
Si vous avez des remarques n'hésités pas j'en prendrait compte !!!!
Sinon voila le code ke j'ai fé pour linstant, il ne gere pa les codes html, mais je rajouteré cette option qd jrriveré a accéder a un msg sur le serveur des fournisseursz d'accès internet.
Voici mon code (ne pas oublier de modifier le nom et le chemin d'accès du fichier a analyser) :
Global email.s, email2.s, email3.s
Global nbr_mot.l, nbr_fil.l, nbr_mot_tab.f, nbr_phrase.l
#MAX_fil.l = 10
Global Filtre.l, pourcentage.f
Filtre = 0
;file_to_open.s = ProgramParameter()
file_to_open.s = "C:\Anti SPAM\texte.txt"
Dim val_fil.l(#MAX_fil)
Dim found.l(#MAX_fil)
Dim found2.l(#MAX_fil)
;'nombre de mots' = nbr par cathé * val de la cathég
Procedure.f nbr_mot_taboo()
nbr.f = 0: tp.f = 0
For i.l = 1 To nbr_fil
tp = found(i)+ ( (found2(i)-found(i)) *1.5)
nbr = nbr + ( val_fil(i) * tp )
Next
ProcedureReturn nbr
EndProcedure
Procedure.l vrai(a.l)
i.l = 0: If a: i = 1: EndIf
ProcedureReturn i
EndProcedure
; autres options de recherches pour déclarer le mail comme spam
Procedure.l other_options()
nbr_p.l = 0: nbr_m.l = 0: nbr_f.l = 0: nbr_h.l = 0: nbr_ph.l = 0
; recherche du signe '%'
For i.l = 1 To Len(email)
If Mid(email,i,1) = "%"
If nbr_p = 0 : nbr_p = 4 : Else : nbr_p = nbr_p + 2: EndIf
EndIf
Next i
; si le spam contient un trop petit nombre de mots
If nbr_mot < 20 : nbr_m = 20 : EndIf
; si les phrases sont trop courtes
If nbr_mot / nbr_phrase < 12: nbr_f = 4: EndIf
If nbr_mot / nbr_phrase < 8: nbr_f = 10: EndIf
If nbr_mot / nbr_phrase < 6: nbr_f = 17: EndIf
If nbr_mot / nbr_phrase < 4: nbr_f = 25: EndIf
; si ya pa bcp de phrases
If nbr_phrase < 8: nbr_ph = 10: EndIf
If nbr_phrase < 5: nbr_ph = 20: EndIf
; recherche de lien vers des sites web
For i.l = 1 To Len(email)-3
If Mid(email,i,4) = "http"
If nbr_h = 0
nbr_h = 4 + vrai(nbr_mot < 20)*10
Else
nbr_h = nbr_h + 2 + vrai(nbr_mot < 20)*6
EndIf
EndIf
Next i
ProcedureReturn nbr_p + nbr_m + nbr_f + nbr_h + nbr_ph
EndProcedure
; Convertion du texte en minuscule et en modifiant les caractères incorrects
Procedure.s convert(a.s)
out.s = " ": tmp.s = "": t.l = 0: cpt.l = 0: nbr_phrase=1: sui.l
; début de la boucle de traitement
For i.l = 1 To Len(a)
tmp = Mid(a,i,1): t = Asc(tmp)
If i < Len(a) :sui = Asc(Mid(a,i+1,1)): Else :suiv = Asc(" "): EndIf
If t > 223
t = t - 32
If t > 191 And t < 199 : tmp = "a": EndIf
If t > 199 And t < 204 : tmp = "e": EndIf
If t = 199 : tmp = "c": EndIf
If t > 203 And t < 208 : tmp = "i": EndIf
If t > 241 And t < 247 : tmp = "o": EndIf
If t > 248 And t < 253 : tmp = "u": EndIf
EndIf
If t < 48 Or (t > 57 And t < 64) Or (t > 90 And t < 97) Or (t > 122 And t <192)
If Right(out,1) = " "
tmp = ""
Else
tmp = " " : If (sui = Asc(" ") Or t=Asc(" ")):cpt = cpt + 1: EndIf
EndIf
EndIf
If (t = 33 Or t = 46 Or t = 59 Or t = 63)And (sui = Asc(" ")) : nbr_phrase = nbr_phrase + 1: EndIf
out = out + tmp
Next i
If Right(out,1) <> " ": out = out + " " : EndIf
nbr_mot = cpt
ProcedureReturn out
EndProcedure
Procedure.s wout_pt(a.s)
out.s = "": tp.l = 0
For i.l = 1 To Len(a)
tp = Asc(Mid(a,i,1))
;si <> ! , . ; ^
If (tp <> 33 And tp <> 44 And tp <> 46 And tp <> 59 And tp <>Asc("^"))
out = out + Chr(tp)
EndIf
Next i
ProcedureReturn out
EndProcedure
; renvoi le nombre de filtre (selon la zone 'data' )
Procedure.l get_filtre_nbr()
Restore Filtre : a.s = "": i.l = 0
While a <> "EOF"
Read a
If Val(a) : l = l + 1 : EndIf
Wend
If l > #MAX_fil : l = #MAX_fil : EndIf
ProcedureReturn l
EndProcedure
; renvoi le nombre d'occurence de a.s présenteent dans 'email2'
Procedure.l recherche(a.s, b.s)
cpt.l = 0
For i.l = 1 To (Len(b) - Len(a))
If a = Mid(b,i,Len(a)) : cpt = cpt + 1: EndIf
Next i
ProcedureReturn cpt
EndProcedure
; chargement des filtres et recherches de ces mots dans le texte
Procedure search_mot_taboo()
Shared filtres, act_fil
Shared nbr_mot, nbr_mot_tab
Restore Filtre
i.l = 0: j.l = 0 : a.s : b.s
;PrintN("Mots trouvees dans les selections :")
For i.l = 1 To nbr_fil
found(i) = 0
Repeat
Read a : b = LCase(a)
If Val(a) = 0
If Left(b,1) = "|"
found(i) = found(i) + recherche(Right(b,Len(b)-1), email2)
found2(i) = found2(i) + recherche(Right(b,Len(b)-1), email3)
Else
found(i) = found(i) + recherche(" " + b + " ", email2)
found2(i) = found2(i) + recherche(" " + b + " ", email3)
EndIf
EndIf
Until Val(a) > 0
val_fil(i) = Val(a)
;PrintN(Str(i) + " " + Str(found(i)) + " " + Str(found2(i)))
Next i
nbr_mot_tab = nbr_mot_taboo()
EndProcedure
; ##################### DEBUT DU PROGRAMME #############################
nbr_fil = get_filtre_nbr()
t.l : t2.s
If (FileSize(file_to_open) > 0)
OpenFile(1,file_to_open)
While (~(Eof(1)))
t2 = ReadString()
If Len(t2) > 2
email = email + t2
t = Asc(Right(email,1))
If (t = 33 Or t = 46 Or t = 59 Or t = 63): email = email + " ": Else : email = email + ". ": EndIf
EndIf
Wend
CloseFile(1)
OpenConsole()
ConsoleTitle("Anti Spams")
email = LCase(email)
email2 = convert(email)
email3 = wout_pt(email)
OpenFile(1,"out.txt")
WriteString(email2)
writestring(Chr(13) + Chr(10))
WriteString(email3)
CloseFile(1)
; recherche des mots filtres dans la variable 'email'
search_mot_taboo()
pourcentage = (nbr_mot_tab * 100 / nbr_mot) + other_options()
If pourcentage > 100 : pourcentage = 100 : EndIf
;affichages
PrintN("Nombre de mots que comporte le mail : " + Str(nbr_mot))
PrintN("Nombre de mots taboo trouves : " + Str(nbr_mot_tab))
PrintN("Pourcentage que ce mail soit un spam : " + Str(pourcentage))
Input(): CloseConsole()
Else
MessageRequester("Erreur", "Erreur lors de l'ouverture du fichier" + Chr(13) + Chr(10) + "Le fichier '" + file_to_open + "' est introuvable.", 0)
EndIf
End
DataSection
Filtre:
;sexe
Data.s "|sex", "|porno", "cul", "cum", "seins", "tits", "viagra", "4"
;finances
Data.s "promotion", "bonnes affaires", "proposons", "|achet", "prix", "discount"
Data.s "|achat", "|en ligne", "produit", "price", "money", "buy", "free"
Data.s "euros", "subsription", "|inscription","2"
;anglais
Data.s "very", "good", "the", "of", "wish", "visit our web site", "new", "1"
; other
Data.s "win", "congratulation", "1"
; fin des données
Data.s "EOF"
EndDataSection
P.S.:
La liste des mots clé n'est que provisoire. Elle va être totalement remodifiée !
Si vous avez des remarques n'hésités pas j'en prendrait compte !!!!
