0
votes

i'm using java mail api to download java mail message attachment.

i am using this link tutorial

download mail attachment but my requirement is that when user read mail it only display download link for attachment and when click on the link file downloaded that time.

Thanks

Manish

1
so manish make check that mail is already read or not - Kick
Uhm, you want to write an IMAP client? - fge

1 Answers

0
votes

I think you want to do the following:

  1. Check, if it is a multipart message AND consists of several parts

    1.1 If so, it has attachments. You should then retrieve the first text/plain or text/html part, which should be the text itself. You leave the other parts alone. But along the text you store some id or reference to the message on the server, that the text is taken from. Consider the following code.

Folder folderInbox = store.getFolder("INBOX");

Message[] arrayMessages = folderInbox.getMessages();

for (int i = 0; i < arrayMessages.length; i++) {

    Message message = arrayMessages[i];
}

Now the class javax.mail.Message has a method getMessageNumber()::int. If you store this message number and the folder name, in this case "INBOX", you have an identifier, that will allow you to find the message on the server again at a later time and do something with it, like downloading parts that have not been retrieved yet.

So (pseudo code here) you basically have to do this.

var message_text = message.getFirstTextBodyPart();
var message_ident = (message.getFolderName(), message.getMessageNumber());

var message = (message_ident, message_text);

saveMessage(message);
showMessage(message);

1.2 In other cases, you download the entire message right now, as there are no parts for later retrieval.