Commits

Patrick Mézard committed 72de8b6

Handle multipart messages

  • Participants
  • Parent commits e1f4217

Comments (0)

Files changed (1)

         if n not in existing:
             return n
 
+re_ispatch = re.compile(r'^(# HG|diff\s)')
+
+def ispatch(s):
+    for line in s.splitlines():
+        if re_ispatch.search(line):
+            return True
+    return False
+
+def getpayload(msg):
+    if msg.is_multipart():
+        for m in msg.get_payload():
+            s = getpayload(m)
+            if s is not None:
+                return s
+    else:
+        s = msg.get_payload()
+        if ispatch(s):
+            return s
+    return None
+
 def importpatch(ui, repo, patchname, msg):
     try:
         mq = extensions.find('mq')
     except KeyError:
         raise util.Abort(_("'mq' extension not loaded"))
 
-    s = msg.get_payload()
+    s = getpayload(msg)
+    if s is None:
+        raise util.Abort(_("cannot find patch in message content"))
+
     s = re.sub('\r\n', '\n', s)
     tmpfd, tmppath = tempfile.mkstemp(prefix='hg-mbox-')
     try: