Commits

Anonymous committed aebe175

dont get into endless loops

Comments (0)

Files changed (2)

ec2control/emailer.py

             orig_from = None
         subject = None
         from_ = None
+        command = None
+        arguments = []
         for line in lines:
             if subject is None and line.startswith("Subject: "):
                 tokens = re.split(r"\s+", line)
-                if len(tokens) == 1:
-                    command = None
-                    arguments = []
-                else:
-                    command = tokens[1]
-                    arguments = tokens[2:]
+                command = tokens[1]
+                arguments = tokens[2:]
             elif from_ is None and line.startswith("From: "):
                 from_ = re.split(r"\s", line, 1)[1]
                 m = re.match(r".*<(.*?)>\s*$", from_)
         msg['To'] = to_addr
         msg['Cc'] = cc_addr
         msg = msg.as_string()
-        smtp = smtplib.SMTP(self.config['smtp_host'], int(self.config['smtp_port']))
 
         addrs = set([to_addr] + re.split(r',\s*', cc_addr))
+
+        if from_addr in addrs:
+            raise ValueError("From address %s is in the TO list, not sending" % from_addr)
+
+        smtp = smtplib.SMTP(self.config['smtp_host'], int(self.config['smtp_port']))
         log.info("Sending mail to %s", ", ".join(addrs))
         log.info(subject)
         log.debug(message)

ec2control/main.py

             instance = Instance(config, name)
             instance.start()
             resp.send_started(instance)
+        elif struct.command is None:
+            raise CommandError("No command sent in subject line !")
         else:
             raise CommandError("Unknown command: '%s'"  % struct.command)
     except CommandError, ce: