aboutsummaryrefslogtreecommitdiff
path: root/b4/mbox.py
AgeCommit message (Collapse)Author
2021-06-11Save mbox files with proper unixfromKonstantin Ryabitsev
In order to avoid some of the more obscure charset encoding problems, we switched to using as_string() for generating messages before saving them in an mbox file. However, this uncovered a bug where the unixfrom was not actually generated and saved, despite as_bytes() and as_string() supposedly behaving identically. See: https://docs.python.org/3/library/email.message.html#email.message.EmailMessage.as_string This commit fixes the problem by properly setting the unixfrom and using the recommended (and hopefully less buggy) email.generator interface when saving mailboxes. Reported-by: Geert Uytterhoeven <geert@linux-m68k.org> Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2021-06-09Fix for recent function API changesKonstantin Ryabitsev
Returning a simple list of messages from get_am_ready broke a few other auxiliary functions invoked when run with -o- or -Q. Reported-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2021-06-07Save exploded pull requests as maildirs as wellKonstantin Ryabitsev
This moves maildir saving code into __init__.py so that we can benefit from it via other subcommands, such as pr. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2021-06-03Account for in-body headers when trimming bodyKonstantin Ryabitsev
When we discover that a message can only be attested after we trim the body, we *must* set the body to that version, otherwise an attacker could append arbitrary content past the l= value boundary. We already do this in the current form, but we weren't properly handing in-body headers like From: and Subject: that are used to indicate to git the patch author vs. committer. This patch set fixes that and also streamlines a few other places where we were already relying on git mailinfo calls. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2021-05-25Don't depend on List-Archive lore headerKonstantin Ryabitsev
The newer version of public-inbox is not injecting its own List-Archive headers, so stop relying on it for any purpose. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2021-05-25Avoid type error when local mbox lacks specified message IDKyle Meyer
Calling b4-am with --use-local=MBOX is supposed to abort with "Could not find MID in MBOX" if the mbox doesn't contain the specified message ID. As of 4950093c0 (Don't use mboxo for anything, 2021-05-18), a type error is signaled because get_strict_thread() returns None when there are no matches, and get_msgs() feeds this result to len(). Update get_msgs() to instead check whether the returned value evaluates to false. Signed-off-by: Kyle Meyer <kyle@kyleam.com> Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org> Link: https://lore.kernel.org/r/20210523025812.26456-1-kyle@kyleam.com
2021-05-21Return early if no messages retrievedKonstantin Ryabitsev
If we haven't been able to retrieve any messages, then exit early. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2021-05-21Move --show-keys into its own kr subcommandKonstantin Ryabitsev
There will be more keyring operations supported in the future, probably, but for now just move the --show-keys subcommand from "mbox" to "kr". Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2021-05-21Handle partial reroll of series without coverKonstantin Ryabitsev
A series may not have a cover letter, so properly handle that situation. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2021-05-21Don't crash on absent cover letterKonstantin Ryabitsev
We may not have an lmsg[0], so check for that. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2021-05-21Warn when we find an "Obsoleted-by" trailerKonstantin Ryabitsev
If we come across an obsoleted-by trailer, and we're not running with --checknewer, then output a warning that there is a newer revision. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2021-05-20Reimplement single-msgid cherrypickingKonstantin Ryabitsev
When processing -P_, filter by that msgid (and its follow-ups) early on, instead of parsing the entire thread and only then looking for matches. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2021-05-20Initial support for Obsoleted-by: trailerKonstantin Ryabitsev
Per discussion on the users list, add initial support for the "Obsoleted-by" trailer that points at the new revision for the series instead of doing a blind match by subject+from. Probably buggy and needs better support for series number collisions (right now we don't check if the newly retrieved series has a revision number greater than the revision we already have). Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2021-05-20Cherrypick from the correct series revisionKonstantin Ryabitsev
When cherrypicking by msgid and with multiple revisions available, make sure that we pick the series revision that actually contains the msgid being cherrypicked. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2021-05-20Write maildir atomicallyKonstantin Ryabitsev
It probably doesn't matter for b4 usage, but the maildir standard requires that files are written to tmp first and then moved into new (or hardlinked, really, then removed from tmp). Since nothing is reading the dir we're writing to, it's not as important to fully follow the standard when it comes to hardlinking, but let's at least move them into place once writing is completed. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2021-05-20Minor visual tweak in outputKonstantin Ryabitsev
Group patch output inside the indented ---, and all processing messages before the indent. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2021-05-20Fix a crash on incomplete/missing threadsKonstantin Ryabitsev
Properly handle situation where we can get a None as well as an empty message list. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2021-05-18Tweak output filenamesKonstantin Ryabitsev
Save am-able maildirs as .eml files, as this is more likely to be properly recognized format-wise by vim and friends. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2021-05-18Don't use mboxo for anythingKonstantin Ryabitsev
While trying to figure out some odd DKIM failures, I've discovered that there is an important incompatibility between git's idea of what "mbox" format is, and Python's mboxo implementation -- at least when it comes to treating "\nFrom " escapes. According to the "original mbox" standard, when a message body contains a "\nFrom " sequence, it should be converted to "\n>From " in order not to confuse the parser. When reading messages in that format, clients are supposed to back-convert "\n>From " into their original form. This is the so-called "mboxo" format, which is what Python's mailbox.mbox supports: https://docs.python.org/3/library/mailbox.html#mailbox.mbox The "mboxrd" format was created to avoid a corruption problem whereas a body that legitimately contains "\n>From " would be wrongly converted into "\nFrom " upon parsing the mailbox, so mboxrd standard requires that, when saving a mailbox, "\n>From " sequences are additionally escaped as "\n>>From ". This is the format public-inbox supports, so when we grab mailboxes from remote, they are in mboxrd format. Git will try to guess the format of the mbox file, but it will ONLY back-convert "\n>From " sequences when you specifically tell it that it's "mboxrd" format, even when it's in fact "mboxo": git am --patch-format=mboxrd If you don't force the mboxrd format, git-am will preserve all escaped "\n>From " lines as-is. We've been previously operating on the assumption that git-am's mbox support properly implements "mboxo", but this was wrong, resulting in some commits like the following: https://git.kernel.org/torvalds/c/137733d08f4a This large-ish change ditches all internal use of Python's mboxo. When asked to save mbox files, we will save them without any escaping, the way git-am (i.e. git-mailsplit) espects them. The same goes when we're outputting to stdout. There is also a way now to pass -M to both "b4 am" and "b4 mbox" that will save things as maildirs -- git-am supports this natively and thus avoids any possible parsing ambiguities. You can set a config option b4.save-maildirs=yes to make this the default behaviour. The fallout of this is fairly benign, if annoying. There is no situation in which a patch would have "\nFrom " as part of its body, so the problem only affected commit messages. We will have a handful of these sprinkled around the trees, and will hopefully not introduce any new ones once everyone switches to the b4 version that outputs things in the format git-am expects. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2021-05-17Allow passing entire mbox via stdinKonstantin Ryabitsev
Per request, allow passing entire mbox files via stdin, allowing fully pipe-through operation from something like mutt: b4 am -sl -m - -o - Suggested-by: Peter Zijlstra <peterz@infradead.org> Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org> Link: https://lore.kernel.org/tools/YFETLu8TKWI2WlSF@hirez.programming.kicks-ass.net
2021-05-17Implement partial rerollKonstantin Ryabitsev
It has been a common request to support partial series rerolls where someone sends an amended patch as a follow-up to a previous series, e.g.: [PATCH v3 1/3] Patch one [PATCH v3 2/3] Patch two \- Re: [PATCH v3 2/3] Patch two Looks good, but please fix this $small_thing \- [PATCH v4 2/3] Patch two [PATCH v3] Patch three Previously, b4 refused to consider v4 as a complete new series, but now it will properly perform a partial reroll, but only in the cases where such patches are sent as follow-ups to the exact same patch number in the previous series: [PATCH v3->v4 1/3] Patch one [PATCH v4 2/3] Patch two [PATCH v3->v4 3/3] Patch three Reported-by: Dan Williams <dan.j.williams@intel.com> Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org> Link: https://lore.kernel.org/r/CAPcyv4ggbuHbqKV33_TpE7pqxvRag34baJrX3yQe-jXOikoATQ@mail.gmail.com
2021-05-14Don't try to read stdin multiple timesKonstantin Ryabitsev
With multiple entry points for calling get_msgid(), we may end up trying to read stdin multiple times. Call it once to ensure that this doesn't happen. Suggested-by: Morten Linderud <foxboron@archlinux.org> Improved-by: Kyle Meyer <kyle@kyleam.com> Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org> Link: https://lore.kernel.org/tools/87im4fi55o.fsf@kyleam.com
2021-05-11Fix crash when PGP key not in default keyringKonstantin Ryabitsev
Catch KeyError instead of backtracing. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2021-05-11Clean up after ourselvesKonstantin Ryabitsev
Remember to remove the temporary mbox if we're done with it. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2021-05-11Rudimentary support for showing patatt key infoKonstantin Ryabitsev
I expect that we'll have better keyring management tooling in the future, but for now show some rudimentary information about patatt keys used in a thread via --show-keys, e.g.: b4 mbox --show-keys 20210511143536.743919-1-konstantin@linuxfoundation.org b4 mbox --show-keys 20210507181322.172569-1-konstantin@linuxfoundation.org Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2021-05-11Reimplement attestation code one more timeKonstantin Ryabitsev
Move end-to-end attestation code into its own library: patatt. See https://git.kernel.org/pub/scm/utils/patatt/patatt.git/about/ It is included into b4 as a submodule, but you will need to init it first: git submodule update --init This change significantly simplifies our attestation code, dropping thousands of lines of rather hairy code. Notably, patatt-style attestation is incompatible with previous attestation implementations done directly in b4, but that's just as well -- we've always marked it as "experimental" and the lack of adoption was proving that we weren't on the right path. Next to come is keyring management and documentation. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2020-12-28Save to/cc headers as-is for trackingKonstantin Ryabitsev
If we clean the to/cc headers to get rid of all unicode escaping, we run into a Python bug that is unable to properly parse addresses, e.g.: In [5]: from email import utils In [6]: utils.getaddresses(['foo <foo@bar.com>']) Out[6]: [('foo', 'foo@bar.com')] In [7]: utils.getaddresses(['Shuming [范書銘] <shumingf@realtek.com>']) Out[7]: [('', 'Shuming'), ('', ''), ('', '范書銘'), ('', ''), ('', 'shumingf@realtek.com')] If we store the headers as-is from the original message, we are less likely to run into this bug, as all non-ascii sequences should be qp-escaped in the original headers: =?big5?B?U2h1bWluZyBbrVOu0bvKXQ==?= <shumingf@realtek.com> This doesn't fix the underlying bug in Python, but works around it. Reported-by: Mark Brown <broonie@kernel.org> Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2020-12-21Add -f to "b4 mbox" to filter dupesKonstantin Ryabitsev
When saving to a maildir, add option to filter out dupes. Note, that this requires going through the entire maildir to collect message-ids, so it's not going to be a great experience on large maildirs. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2020-12-21Check if -o is a maildirKonstantin Ryabitsev
When -o is a valid maildir, then instead of saving an .mbox file add messages to the maildir instead. This should allow "b4 mbox" to quickly add threads to existing mail spools. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2020-12-14Fix crasher when we don't use -g with b4 prKonstantin Ryabitsev
If we're not passing -g to "b4 pr -e", then we should try to see if we are inside a git checkout and use that as our source. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2020-12-01Deal with dupe follow-up trailers sent to coverKonstantin Ryabitsev
Since we now include the message object into the followup-trailer list (for DKIM verification purposes), we no longer auto-dedupe duplicate trailers. Add some extra logic to handle that. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2020-11-30Properly clean up temporary threadfileKonstantin Ryabitsev
Now that we always create a strict-threaded file, always clean it up after we are done. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2020-11-30If using -m, reduce local mbox to strict threadKonstantin Ryabitsev
When passing a local mbox, don't assume that it is going to contain a strict thread already -- it can be just a local mailbox via something like mbsync. This grabs actual thread from the mailbox before looking at individual messages. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2020-11-25Unbreak thanks-trackingKonstantin Ryabitsev
Don't forget to increment where we are when doing "continue". Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2020-11-24Add --cc-trailers option to b4 amKonstantin Ryabitsev
By request, add ability to copy all addresses from the email's "Cc" header into Cc: trailers, unless they are already mentioned in some other trailer. Requested-by: Arnaldo Carvalho de Melo <acme@kernel.org> Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2020-11-24Fix crash on incomplete series thanks trackingKonstantin Ryabitsev
Now that we do our best to track incomplete series, don't crash when we come across one. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2020-11-24Improve ty with cherrypicked subsetsKonstantin Ryabitsev
Record patch counters when we start tracking series so we properly indicate in the thank-you note which ones got applied. Additionally, indicate in the subject when we're reporting on a subset of a larger series. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2020-10-27Fix a crasher discovered in testingKonstantin Ryabitsev
Don't crash on incomplete threads when trying to carry over previous trailers. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2020-10-02Fix some cherry-picking corner casesKonstantin Ryabitsev
Handle several corner cases when trying to cherrypick from incomplete series. Reported-by: Krzysztof Kozlowski <krzk@kernel.org> Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2020-10-02Use bytes when dumping to stdoutKonstantin Ryabitsev
We don't need to needlessly convert to unicode when dumping to stdout, especially when it can lead to crashers when we encounter other charsets. Reported-by: Rob Herring <robh@kernel.org> Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2020-07-27Support mbox -m to be a maildirKonstantin Ryabitsev
It's a simple if/else to support maildirs for local operations, so let's handle mbox -m to be a maildir. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2020-07-06Fix crash when -c used with incomplete seriesKonstantin Ryabitsev
Return early if we don't have a cover letter or patch 1/X to use as basis for the subject-based query. Reported-by: Christian Brauner <christian.brauner@ubuntu.com> Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2020-06-08Fix mbox naming inconsistenciesKonstantin Ryabitsev
Fix mbox file naming problems introduced by adding "-o -". Reported-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2020-06-08Output less confusing trailer mismatch messagesKonstantin Ryabitsev
Show the actual trailer name we're complaining about. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2020-05-28Don't output git am suggestion for -o -Konstantin Ryabitsev
Since we're piping out to stdout, there's obviously no reason to show what the "git am" command should be -- especially if we delete the temporary mbox file after the command completes. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2020-05-28Add --no-cover and -o - to output to stdoutKonstantin Ryabitsev
By request, provide a way to output the results of b4 am to stdout. This way it can be piped straight to "git am". E.g.: b4 diff 20200526205322.23465-1-mic@digikod.net -o - | git am Requested-by: Rob Herring <robh@kernel.org> Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2020-05-25Add -3 to "b4 am" to prep for a 3way mergeKonstantin Ryabitsev
The original code used for b4 diff was to prepare for a 3-way merge by making sure that all blob indexes exist in the local repo. Add this functionality to "b4 am" and document all the features added in the 0.5.0 branch. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2020-05-22Add ability to diff arbitrary mbox filesKonstantin Ryabitsev
Sometimes we are unable to properly look up previous series -- usually because the cover letter title changes. For those cases, it is now possible to diff two arbitrary mbox files prepared with "b4 am -T". There's also a smattering of other fixes in there because I'm too lazy to properly stage my patches. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2020-05-19Display range-diff by defaultKonstantin Ryabitsev
Don't make developers do copy-pasting unnecessarily. Switch to outputting the diff by default, with flag options to save to file or just show what needs to be done. Additionally, adds caching to lookups and remember previously generated fake-am ranges so we don't continuously generate loose objects on repeat runs. Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
2020-05-15Initial implementation of b4 diffKonstantin Ryabitsev
Based on feedback from Jason Gunthorpe, implement diffing of series by creating fake git-am commit ranges. Here's an easy example: b4 diff 20200511192156.1618284-1-mic@digikod.net Suggested-by: Jason Gunthorpe <jgg@ziepe.ca> Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>