[Merge] ~hyask/ubuntu-dev-tools:skia/i-b-f-d_multipart into ubuntu-dev-tools:main

Skia mp+468091 at code.launchpad.net
Fri Jul 12 13:26:08 UTC 2024


Pushed a new version, and answered your comments inline.

Diff comments:

> diff --git a/import-bug-from-debian b/import-bug-from-debian
> index 5d0fd7f..8c3623a 100755
> --- a/import-bug-from-debian
> +++ b/import-bug-from-debian
> @@ -118,7 +118,41 @@ def main():
>          bug_num = bug.bug_num
>          subject = bug.subject
>          log = debianbts.get_bug_log(bug_num)
> -        summary = log[0]["message"].get_payload()
> +        message = log[0]["message"]
> +        attachments = []
> +        if message.is_multipart():
> +            summary = ""
> +            i = 1
> +            for part in message.walk():
> +                content_type = part.get_content_type()
> +                if content_type.startswith("multipart/"):
> +                    # we're already iterating on multipart items, let's just skip the multipart extra metadata
> +                    continue

I honestly have no idea. I've basically never touched emails, not in Python, nor in anything. Implementing that has been interesting for me, but I'm sadly unable to answer your concern with solid information.
>From what I see in my mailbox, an email forwarded as attachment is `message/rfc822`, but that's only one example on one email client.

If you have an example of an email included as an attachment to a bug, I can certainly see how to handle that.

> +                elif content_type == "application/pgp-signature":
> +                    continue
> +                elif part.is_attachment():
> +                    attachments.append((i, part))
> +                elif content_type.startswith("image/"):
> +                    # images here are not attachment, they are inline, but Launchpad can't handle that,
> +                    # so let's add them as attachments
> +                    summary += f"Message part #{i}\n"
> +                    summary += f"[inline image '{part.get_filename()}']\n\n"
> +                    attachments.append((i, part))
> +                elif content_type == "text/plain":
> +                    summary += f"Message part #{i}\n"
> +                    summary += part.get_content()
> +                else:
> +                    raise RuntimeError(
> +                        f"""Unknown message part
> +Your Debian bug is too weird to be imported in Launchpad, sorry.
> +You can fix that by patching this script in ubuntu-dev-tools.
> +Faulty message part:
> +{part}"""
> +                    )

True, forgot about that.
Here is a bug imported with the code I'll just push: https://bugs.qastaging.launchpad.net/ubuntu/+source/linux/+bug/2043840

Other proposition is to just include that as inline text, like this: https://bugs.qastaging.launchpad.net/ubuntu/+source/linux/+bug/2043837
I find that less readable though, especially since clicking on the attachment makes it display nicely in the first example.

> +                i += 1
> +        else:
> +            summary = log[0]["message"].get_payload()
> +
>          target = ubuntu.getSourcePackage(name=ubupackage)
>          if target is None:
>              Logger.error(
> @@ -137,12 +171,31 @@ def main():
>          Logger.debug("Subject: %s", subject)
>          Logger.debug("Description: ")
>          Logger.debug(description)
> +        for attachment in attachments:
> +            i, attachment = attachment
> +            Logger.debug(f"Attachment #{i} ({attachment.get_filename()})")
> +            Logger.debug("Content:")
> +            if attachment.get_content_type() == "text/plain":
> +                Logger.debug(attachment.get_content())

About usefulness: Dumping the attachment has helped me, mostly when it was a patch, to check that I had read it correctly, but verbose mode is only useful for debugging anyway, and at that point, one can always tweak the logging if it doesn't fit.

I've cropped after 2000 characters, arbitrarily, but please tell me if you feel otherwise, I don't really care.

> +            else:
> +                Logger.debug("[data]")
>  
>          if options.dry_run:
>              Logger.info("Dry-Run: not creating Ubuntu bug.")
>              continue
>  
>          u_bug = launchpad.bugs.createBug(target=target, title=subject, description=description)
> +        for i, attachment in attachments:
> +            name = f"#{i}-{attachment.get_filename()}"
> +            content = attachment.get_content()
> +            if isinstance(content, str):
> +                # Launchpad only wants bytes
> +                content = content.encode()
> +            u_bug.addAttachment(
> +                filename=name,
> +                data=content,
> +                comment=f"Imported from Debian bug http://bugs.debian.org/{bug_num}",
> +            )
>          d_sp = debian.getSourcePackage(name=package)
>          if d_sp is None and options.package:
>              d_sp = debian.getSourcePackage(name=options.package)


-- 
https://code.launchpad.net/~hyask/ubuntu-dev-tools/+git/ubuntu-dev-tools/+merge/468091
Your team Ubuntu Development Team is subscribed to branch ubuntu-dev-tools:main.




More information about the Ubuntu-reviews mailing list