Re: [gmime-devel] Using gmime to Remove Attachments



On 07/30/2010 11:59 AM, Eugene Reimer wrote:
> Using a counting-down loop helps to keep things simple in such cases.

Iterating over the parts in reverse in GMime's foreach implementation
would probably not yield the expected behavior for most use cases, but
yea, it's the first thought I had :-)

I could copy the contents of the parts array and iterate over that
instead of the real array, thus making it so that mutating the actual
list in any way wouldn't change the behavior (e.g. each of the original
parts would get the callback called on them in their original order even
if a previous callback removed them or moved them to another position).
The problem with this approach is that it may also not be the expected
behavior. Arguably no worse than things are now, though - if the
callback mutates the multipart ;-)

It appears that in .NET (I generally like the .NET API design, they are
mostly pretty clean/elegant and consistent), whether you can mutate the
array/list/whatever in the body of a foreach is dependent upon the
implementation of the list/array/whatever being iterated over.
Apparently all implementations in the core libs throw an exception, but
you could write your own collection type that allowed it.

I'll have to see what other foreach's do in other languages (although
I'm not familiar with any other languages that use foreach). I'll also
have to check glib since they use a similar foreach+callback API.

Jeff



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]