OfficeDev / Office-365-SDK-for-Android

Microsoft Services SDKs for Android produced by MS Open Tech.
https://dev.office.com/android
Other
224 stars 74 forks source link

Request support for removing an attachment from an email #85

Closed JohnMAustin78 closed 9 years ago

JohnMAustin78 commented 9 years ago

You can add an attachment to an email in the drafts folder with the following code: mOutlookClient .getMe() .getMessages() .getById(mailId) .getAttachments() .add(itemAttachment) .get();

There should be a .remove(AttachmentId) method on the attachments collection so that you can remove an attachment from a draft email. This is supported in the REST API.
DELETE https://outlook.office365.com/api/v1.0/me/messages/{message_id}/attachments/{attachment_id}

marcote commented 9 years ago

@JohnAustin-MSFT Have you tried ? :

client.getMe().getMessage("foomessage").getAttachments().getById("fooattachment").delete();
JohnMAustin78 commented 9 years ago

I haven’t tried that. :-(

Why would we call an add(attachment) method on the attachment collection, but a delete method on the attachment itself. Wouldn’t it make more sense to delete from the collection object? On May 27, 2015, at 2:09 PM, Marcos Torres notifications@github.com<mailto:notifications@github.com> wrote:

@JohnAustin-MSFThttps://github.com/JohnAustin-MSFT Have you tried ? :

client.getMe().getMessage("foomessage").getAttachments().getById("fooattachment").delete();

— Reply to this email directly or view it on GitHubhttps://github.com/OfficeDev/Office-365-SDK-for-Android/issues/85#issuecomment-106077859.

JohnMAustin78 commented 9 years ago

If the getById("fooattachment") returns an Attachment object, you would expect the Attachment object to expose a delete() method. It doesn't. We should have CRUD parity on the collection level. Where there is an add() method, there should also be a delete() method on the collection.

marcote commented 9 years ago

@JohnAustin-MSFT a .delete() method is exposed by the Attachment.

When we want to add an item to a collection, we call .add()

client.getMe().getMessage("foo").getAttachments().add(new FileAttachment());

When we want to delete an attachment :

client.getMe().getMessage("foomessage").getAttachments().getById("fooattachment").delete();

We have to know which attachment to delete, and if you take a look the last method call chain actually is pretty similar to what the REST endpoint uses:

DELETE https://outlook.office365.com/api/v1.0/me/messages/{message_id}/attachments/{attachment_id}

What do you think?