aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--b4/__init__.py18
-rw-r--r--b4/mbox.py3
-rw-r--r--b4/pr.py2
3 files changed, 15 insertions, 8 deletions
diff --git a/b4/__init__.py b/b4/__init__.py
index 48f43a2..25ca569 100644
--- a/b4/__init__.py
+++ b/b4/__init__.py
@@ -43,7 +43,7 @@ try:
except ModuleNotFoundError:
can_patatt = False
-__VERSION__ = '0.7.3-dev'
+__VERSION__ = '0.7.3'
logger = logging.getLogger('b4')
@@ -1161,7 +1161,7 @@ class LoreMessage:
if hcs is None:
hcs = 'utf-8'
try:
- decoded += hstr.decode(hcs)
+ decoded += hstr.decode(hcs, errors='replace')
except LookupError:
# Try as utf-u
decoded += hstr.decode('utf-8', errors='replace')
@@ -1252,8 +1252,11 @@ class LoreMessage:
@staticmethod
def find_trailers(body, followup=False):
- headers = ('subject', 'date', 'from')
- nonperson = ('fixes', 'subject', 'date', 'link', 'buglink', 'obsoleted-by')
+ ignores = {'phone', 'email'}
+ headers = {'subject', 'date', 'from'}
+ nonperson = {'fixes', 'subject', 'date', 'link', 'buglink', 'obsoleted-by'}
+ # Ignore everything below standard email signature marker
+ body = body.split('\n-- \n', 1)[0].strip() + '\n'
# Fix some more common copypasta trailer wrapping
# Fixes: abcd0123 (foo bar
# baz quux)
@@ -1276,6 +1279,9 @@ class LoreMessage:
groups = list(matches.groups())
# We only accept headers if we haven't seen any non-trailer lines
tname = groups[0].lower()
+ if tname in ignores:
+ logger.debug('Ignoring known non-trailer: %s', line)
+ continue
if len(others) and tname in headers:
logger.debug('Ignoring %s (header after other content)', line)
continue
@@ -1727,7 +1733,7 @@ def git_run_command(gitdir: Optional[str], args: List[str], stdin: Optional[byte
logstderr: bool = False) -> Tuple[int, str]:
cmdargs = ['git', '--no-pager']
if gitdir:
- if os.path.isdir(os.path.join(gitdir, '.git')):
+ if os.path.exists(os.path.join(gitdir, '.git')):
gitdir = os.path.join(gitdir, '.git')
cmdargs += ['--git-dir', gitdir]
cmdargs += args
@@ -1948,7 +1954,7 @@ def get_requests_session():
def get_msgid_from_stdin():
if not sys.stdin.isatty():
- message = email.message_from_string(sys.stdin.read())
+ message = email.message_from_bytes(sys.stdin.buffer.read())
return message.get('Message-ID', None)
return None
diff --git a/b4/mbox.py b/b4/mbox.py
index f575f94..3d887e6 100644
--- a/b4/mbox.py
+++ b/b4/mbox.py
@@ -656,7 +656,8 @@ def main(cmdargs):
if cmdargs.wantname:
savename = os.path.join(cmdargs.outdir, cmdargs.wantname)
else:
- savename = os.path.join(cmdargs.outdir, f'{msgid}.{dftext}')
+ safe_msgid = re.sub(r'[^\w@.+%-]+', '_', msgid).strip('_')
+ savename = os.path.join(cmdargs.outdir, f'{safe_msgid}.{dftext}')
if save_maildir:
if os.path.isdir(savename):
diff --git a/b4/pr.py b/b4/pr.py
index d8ff7f4..fbb2a71 100644
--- a/b4/pr.py
+++ b/b4/pr.py
@@ -433,7 +433,7 @@ def main(cmdargs):
if not sys.stdin.isatty():
logger.debug('Getting PR message from stdin')
- msg = email.message_from_string(sys.stdin.read())
+ msg = email.message_from_bytes(sys.stdin.buffer.read())
msgid = b4.LoreMessage.get_clean_msgid(msg)
lmsg = parse_pr_data(msg)
else: