Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editing a Part #176

Open
stellarpower opened this issue Sep 6, 2024 · 2 comments
Open

Editing a Part #176

stellarpower opened this issue Sep 6, 2024 · 2 comments

Comments

@stellarpower
Copy link

Hi,

mime::parts() returns the parts of a multipart message by value.

I'm only just trying mailio for the first time (having been using a different package up until now) - so maybe there's another approach I should be using, but not seen one so far.

But by returning by value, as far as I can tell this then makes it difficult for me to edit a part within a message. I'd need to make a copy of it, remove the original, and then add it back in again, which I'm concerned would have ramifications for the rest of the message. I'm looking to modify the HTML of a message body, whilst leaving things like attachments as they are. Even if I tried to copy-construct a copy of the original message and work with that, as I recurse through any subparts I'm still getting a copy of those parts back. So I think I would need to construct my own tree and then start at the leaves and add new parts back into parents recursively in order to work around this.

Perhaps this is by design due to the link to the original message as parsed, I'm not sure. But if there would be a way to make edits to just one part, that'd be a helpful feature to add to achieve what I'm trying to do.

I assume returning by (const) reference in parts() would break API compatibility for existing projects - but would a function similar to this perhaps with a different name be physically possible to enable modifications of the content or headers of an existing part within a message body?

Thanks.

@karastojko
Copy link
Owner

Hi,

Thanks for the suggestion.

I believe such possibility could be added. Currently there is void mime::add_part(const mime&) but indeed a specific part cannot be edited. So, do you suggest to add few more operations like void mime::update_part(const mime& part) (update based on the content id) and void mime::delete_part(const string& content_id) or maybe to return a reference with a method like mime& mime::part(const string& content_id) ?

Cheers

@stellarpower
Copy link
Author

That makes sense to me. I have been using mimesis too, and this generally returns parts by reference/pointer (or reference to the container of these), so any modifications I make can be written out, which has been convenient. But again, this may break the API for users of mailio. So I think update_part and delete_part, or fetching one by its ID as you say both sound very reasonable to me.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants