I'm developing Android mail client. I need to build a "conversation" structure for every email message. I use the
IMAPMessage.getInReplyTo()
method that returns the Message ID of message which the message is a reply to. Unfortunatelly there seems to be no easy way to obtain message from
IMAPFolder
using its message ID. It is only possible to get the message by its UID. Is there an easy way to get the IMAP message by its Message ID?
You can use the IMAPFolder's search method like this:
SearchTerm searchTerm = new MessageIDTerm(messageId);
Message[] messages = imapFolder.search(searchTerm);
See the docs for the IMAPFolder's search method here:
https://javaee.github.io/javamail/docs/api/com/sun/mail/imap/IMAPFolder.html#search-javax.mail.search.SearchTerm-
and for the MessageIDTerm class here:
https://javaee.github.io/javamail/docs/api/javax/mail/search/MessageIDTerm.html
unfortunately there is no straight forward solution... May be what you can try is to maintain an internal structure with body structures of all the mail ids and then perform a one on one Message-ID check and obtain the UID of mail. Anyways you would be doing it, in order to show the Maillist. Add a new logic to map the message-ids as well.
Related
I have a scenario where I have to read a mail sent out by a X person with a specific subject, which i will be receiving on a daily basis.
Is there any JAVA Gmail APi provided by google to retrieve the recent mail that i have received.
And also is there a way to retrieve the mail for a given date?
Yes there's a Gmail API and it has a Java client library, you can check the Quickstart to get used to it.
Now, for retrieving a list of mails you will need to use the Users.messages: list endpoint ( There's also a Java example on how to use that endpoint). Answering your question about retrieving certain emails, you will need to use the q parameter and set the values there as if you would be searching an email in the gmail search bar. I will leave you an example that you can try using the Try this API:
List emails from certain user and date.
Notice
You will only get the email's IDs, for getting more info about an email, you will have to use the Users.messages: get endpoint.
Let's say there is an attachment in the slack channel . And that attachment has some unique identifier So if I type the identifier i should get the attachment as response in the channel.
Example: if i type 45 and its related to an xml file attached in the slack channel, then it should reply with the uploaded attachment in the conversation.
I tried using GET method for https://slack.com/api/channels.history?&channel=<>&count=1&pretty=1&inclusive=true&token=<> and I obtained the history of the conversation in the channel.
Don't know how timestamp and unfurl can help in achieving this.
The API method channels.history returns a list of messages from a specific channel as a big JSON array. It will only return the 100 latest by default and you have to use paging if your channel contains more messages.
Messages are referenced by timestamp (ts). Attachments are elements of its message and references by ID (id), which represents the order their are shown on Slack.
So to access a specific attachment you first need to find the correct message by its timestamp and then you can find the attachment by its ID.
If you know the timestamp of the message you are interested in you can include latest=timestamp and oldest=timestamp in your API call to receive only that message.
If you do not know the timestamp of the message you will have to retrieve all messages within a reasonable timeframe and then detect your message based on some other criteria.
Btw. I would consider switching to conversations.history, which is the new and recommend API method for retrieving messages from all type of channels.
I have the following use case in my app:
When a specific event happens in the app all interested users should be notified by email. Then if a user replies to the email, his reply should be shown in the event page in the app.
My initial idea was to create a temp mail alias of the main notification email every time when an event happens and send the notification email with that alias set in the Reply-To header. Then if someone replies to that mail by using the alias (let's say csa123423#mydomain.com) I can figure out which event this reply refers to.
It turned out that Spring's JavaMailSender doesn't provide a way to use aliases, so I tried with Gmail API. As far as I understood creating a Gmail alias means actually setting an already existing email in your domain as an alias for another already existing email in that domain. So the Java code to achieve this using Directory API and Gmail API would look like this:
User newUser = new User();
UserName userName = new UserName();
userName.setGivenName("xsd");
userName.setFamilyName("ewrewr");
newUser.setPrimaryEmail("bbb34262bb45#mydomain.com");
newUser.setPassword("12345");
newUser.setName(userName);
User result = directoryService.users().insert(newUser).execute();
SendAs sendAs = new SendAs().setSendAsEmail("bbb34262bb45#mydomain.com").setReplyToAddress("bbb34262bb45#mydomain.com").setDisplayName("My name").setTreatAsAlias(true);
SendAs sendAsResult = gmailService.users().settings().sendAs().create(user, sendAs).execute();
MimeMessage emailContent = createEmail("mymail#gmail.com", "bbb34262bb45#mydomain.com", "Test from app", "Test body");
Message message = createMessageWithEmail(emailContent);
message = gmailService.users().messages().send(user, message).execute();
But as far as I know there are some limits on the number of accounts you can create per domain/account and also Google would charge more for this.
Is there another easier way to create aliases in Gmail? Or is there another approach to achieve the desired functionality (linking mail replies to application content) without using mail aliases?
Try leveraging '+' functionality given by Gmail for creating temporary aliases.
The basic idea is if my email id is xyz#gmail.com, I can send/receive an email with xyz+1#gmail.com or xyz+anything_here#gmail.com and it will work like a charm.
You can utilize this by keeping the alias/unique-id after the '+' in the Gmail id and then parse this alias easily in your application.
HelloI've built an Android application that uses PubNub to create a chat channel between each user. I would like to be able to identify which users have sent which messages. Currently the login of my app is handled by Parse so each user has a unique username. I found some documentation and example code where rather than sending just the message string, an object was set up that contained the UUID and message string as two different objects that could then be extracted on the subscribe side but from what I could tell this was only in the PubNub javascript code not the Java code for Android.Right now i'm thinking that the only way for me to do this is to attach the UUID/username to the beginning of my message string with a special character to seperate the UUID and the message and then split it up and read it in on the subscribe side. For example String message = "uuidhere_messagehere";. Is this the correct way to approach this or is there a better, more convenient way of doing this?thanks
Correct - PubNub does not inject anything into your messages so you will need to include the sender id within each message that is published. Here's is a simple example of a JSON message you might publish:
{'sender_id':'user_333', 'msg':'this is my msg to you-hoo-hoo'}
Of course, the JSON message can have any key/value pairs you require.
I have a very special requirement
I am using Java Mail API to access a user's Inbox. You can say its like a service inbox for complaints. User registers a complaint by sending an email to this address. I fetch every email from Inbox and create a new complaint. My problem is that I don't want to create unnecessary complaints for reply or forwarded emails. Is there a way to find out that.
Most email clients add Re: or Fwd: to the subject line, but I wouldn't rely on that to determine whether an email is a reply or forwarded text; for example, a German mailclient might put Betr.: in front of the original subject.
Instead, you might want to look at the In-Reply-To: header and/or the References: header. See RFC 4021 for detailed information on those headers.
You can retrieve the headers from a Message by calling the getHeader(java.lang.String) method.
Reading the email header might help, see http://javamail.kenai.com/nonav/javadocs/javax/mail/Part.html#getAllHeaders(). In case of replies, the message header would include:
In-Reply-To: Message-ID of the message that this is a reply to
In case of a forwarded message, selected headers might be preserved. Not as straight-forward as the previous case, but it might still be possible to determine if it was a forwarded message. Refer to http://en.wikipedia.org/wiki/Email_forwarding#Manual_client-based_forwarding for details.