MailCore / mailcore2

MailCore 2 provide a simple and asynchronous API to work with e-mail protocols IMAP, POP and SMTP. The API has been redesigned from ground up.
Other
2.6k stars 625 forks source link

Can we have messages maintain which folder they came from? #67

Closed CodaFi closed 11 years ago

dinhvh commented 11 years ago

If we refer to the folder object, we might create a reference cycle or reference invalid folders.

If we use string, we might not have enough information to perform the request and/or there will be a performance hit if we have 100000 messages, we'll be keeping 100000 times the same string in memory. Though it can be optimized.

Let's try to work without it for now.

CodaFi commented 11 years ago

It certainly could be optimized. We could make folders act like NSString (vend the same folder as long as the paths are the same). I'll try to look into it.

dinhvh commented 11 years ago

I'd suggest using unified NSStrings using NSSet to refer to the folder and have an easy way to get a folder using a path.

CodaFi commented 11 years ago

What about an NSDictionary. Something like this: https://github.com/MailCore/mailcore2/compare/Folders-Cache#L1R38

CodaFi commented 11 years ago

I'm thinking it could be more thread safe if access to the dictionary was synchronized, which would make it safe for an MCOOperation to make one from a background thread.

dinhvh commented 11 years ago

It would leak folders in memory. It wouldn't work when you have several session to manage. It wouldn't work when the list of the folders would change.

NSString would be simpler to implement (event though NSString could leak too). To solve that you might have to implement a "Bag": NSSet with a counter for each element.

It looks hard enough to me to just not implement reference to the owning folder and leave the responsibility to the application to do that. The application can do that more easily.

CodaFi commented 11 years ago

The static qualifier does make memory management ambiguous, I'll give you that, but it would still work if the folders were to change, so long as you used the caching +folderWithPath: variant. And I can foresee a problem if two accounts use the same folder path, but the folders have different flags. Yeah, you're right.