diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -63,6 +63,10 @@ def extract(ui, fileobj): subject = msg['Subject'] user = msg['From'] + if not subject and not user: + # Not an email, restore parsed headers if any + subject = '\n'.join(': '.join(h) for h in msg.items()) + '\n' + gitsendmail = 'git-send-email' in msg.get('X-Mailer', '') # should try to parse msg['Date'] date = None diff --git a/tests/test-import b/tests/test-import --- a/tests/test-import +++ b/tests/test-import @@ -332,3 +332,23 @@ new file mode 100644 EOF hg import --no-commit a.patch cd .. + +echo % 'first line mistaken for email headers (issue 1859)' +hg init emailconfusion +cd emailconfusion +cat > a.patch <