[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r21028: {projects} Parse '+' addresses, add farsi support (projects/gettor/lib/gettor)



Author: kaner
Date: 2009-11-26 17:34:52 -0500 (Thu, 26 Nov 2009)
New Revision: 21028

Modified:
   projects/gettor/lib/gettor/requests.py
Log:
Parse '+' addresses, add farsi support


Modified: projects/gettor/lib/gettor/requests.py
===================================================================
--- projects/gettor/lib/gettor/requests.py	2009-11-26 22:09:43 UTC (rev 21027)
+++ projects/gettor/lib/gettor/requests.py	2009-11-26 22:34:52 UTC (rev 21028)
@@ -28,6 +28,7 @@
     defaultLang = "en-US"
     # XXX
     supportedLangs = { "en-US": "English", 
+                       "fa": "Farsi",
                        "de": "Deutsch" }
 
     def __init__(self, config):
@@ -47,9 +48,15 @@
         except:
             pass
 
+        self.replyLocale = "en-US"
         # We want to parse, log and act on the "To" field
         self.toAddress = self.parsedMessage["to"]
         log.info("User made request to %s" % self.toAddress)
+        # Check if we got a '+' address
+        match = re.search('(?<=\+)\w+', self.toAddress)
+        if match:
+            self.replyLocale = match.group(0)
+            log.info("User requested language %s" % self.replyLocale)
         # TODO XXX: 
         # Scrub this data
         self.replytoAddress = self.parsedMessage["from"]
@@ -58,7 +65,6 @@
         self.returnPackage = None
         self.splitDelivery = False
         self.commandaddress = None
-        self.replyLocale = "en-US"
         packager = gettor.packages.Packages(config)
         self.packages = packager.getPackageList()
         assert len(self.packages) > 0, "Empty package list"
@@ -88,11 +94,12 @@
             if match:
                 self.splitDelivery = True
                 log.info("User requested a split delivery")
-            # Default locale is english
-            match = re.match(".*[Ll]ang:\s+(.*)$", line)
-            if match:
-                self.replyLocale = match.group(1)
-                log.info("User requested locale %s" % self.replyLocale)
+            # Change locale only if none is set so far
+            if self.replyLocale is not None:
+                match = re.match(".*[Ll]ang:\s+(.*)$", line)
+                if match:
+                    self.replyLocale = match.group(1)
+                    log.info("User requested locale %s" % self.replyLocale)
             # Check if this is a command
             match = re.match(".*[Cc]ommand:\s+(.*)$", line)
             if match: