2 Коммиты b7d63884b2 ... 6fddf4ad76

Автор SHA1 Сообщение Дата
  Sergio Guillen 6fddf4ad76 Merge branch 'master' of notabug.org:r00thouse/hacky-sympa-mod 8 лет назад
  Sergio Guillen 8e5f3c8d1e [FIX] Fixed some bugs on blacklist reading 8 лет назад
6 измененных файлов с 17 добавлено и 16 удалено
  1. 2 1
      blacklist.txt.sample
  2. 1 0
      configuration.py
  3. 1 1
      init.sh
  4. 2 3
      main.py
  5. 7 9
      sympa/mail.py
  6. 4 2
      sympa/mod.py

+ 2 - 1
blacklist.txt.sample

@@ -1,2 +1,3 @@
 someone@trolling.com
-someone@apple.com
+someone@apple.com
+jbrander@openmailbox.org

+ 1 - 0
configuration.py

@@ -4,6 +4,7 @@ import json
 settings = {
     'subscribersFile': './subscribers.json',
     'listName': None,
+    'blacklistFile': './blacklist.txt',
     'debug': False,
     'logFile': './hackymod.log',
     'listContactEmail': None,

+ 1 - 1
init.sh

@@ -8,4 +8,4 @@ cp blacklist.txt.sample blacklist.txt
 echo "[OK] Files created"
 echo "  [-] Put your settings on settings.json"
 echo "  [-] Put your list's subscribers on subscribers.json following the given format"
-echo "  [-] Put the moderated emails on listanegra.txt (one email per line)"
+echo "  [-] Put the moderated emails on blacklist.txt (one email per line)"

+ 2 - 3
main.py

@@ -10,11 +10,10 @@ def main():
     loadConfiguration('./settings.json')
     initLogs(settings['logFile'], debug=settings['debug'])
 
-
     users = getSubscribers(settings['subscribersFile'])
+
     mod = HackyMod(users=users,
-#        blacklist=[],
-        blacklistFile=['blacklistFile'],
+        blacklistFile=settings['blacklistFile'],
         listName=settings['listName'],
         listContactEmail=settings['listContactEmail'],
         moderatorEmail=settings['moderatorEmail'],

+ 7 - 9
sympa/mail.py

@@ -56,9 +56,9 @@ def getEmailsFromUser(fromEmail, userEmail, password, imapServer, imapPort):
 
         content = content.decode('utf-8')
         if sender.find(fromEmail) != -1:
-            print("""Subject: %s
-                From: %s
-                """ % (subject, sender))
+            print('     Subject: %s' % subject)
+            print('     From: %s' % sender)
+
             result.append({
                 'subject': subject,
                 'from': sender,
@@ -80,12 +80,10 @@ def concatenateMultipartEmail(emailMessage):
 
 def getModerationData(emailContent='', listName='', senderEmail=''):
 
-    # agregado para probrar
-    print('######################################')
-    print('##### Message body from %s ######' % senderEmail)
-    print(' %s ' % emailContent)
-    print('###### END OF BODY####################')
-    # ---
+    # print('######################################')
+    # print('##### Message body from %s ######' % senderEmail)
+    # print(' %s ' % emailContent)
+    # print('###### END OF BODY####################')
 
     MODERATION_CODE_PATTERN = 'DISTRIBUTE %s' % listName
 

+ 4 - 2
sympa/mod.py

@@ -32,12 +32,14 @@ class HackyMod:
         return False
 
     def __isUserInBlackList(self, email):
-        #blacklist = self.blacklist
         # Added a blacklist file (testing)
         blf = open(self.blacklistFile, 'r')
-        blacklist = blf.reeadlines()
+        blacklist = blf.readlines()
 
         for usr in blacklist:
+            # cleaning newline characters
+            usr = usr.replace('\n', '')
+            usr = usr.replace('\r', '')
             if usr == email:
                 return True
         return False