I'm using the Java EWS library to try to sync messages from an Exchange mailbox. I'm able to get a list off all new messages created since the last sync date, however, I would really like to find out the Message-ID property of the message before loading it from exchange.
Background: I'm trying to integrate EWS sync into an existing mail storage system. The Message-ID identification is solely for performance reasons, as our system already has millions of messaged processed outside of EWS. Having to download them again would cause major performance overhead.
//Sample code to fetch the message from sync
ChangeCollection<ItemChange> icc = service.syncFolderItems( folder.getId()
, PropertySet.FirstClassProperties // propertySet
, null // ignoredItemIds
, 25 // maxChangesReturned
, SyncFolderItemsScope.NormalItems
, currSyncState );
for ( ItemChange ic : icc )
{
if (ic.getChangeType() == ChangeType.Create)
{
Item item = ic.getItem();
//how to get the Message-ID
}
Right now, the best way I see to retrieve the Message-ID is by calling ic.getItem().getInternetMessageHeaders() after calling ic.load(). But that requires loading the entire message from exchange, and I would to avoid this step.
Edit: Another way to grab the Message-ID is
EmailMessage em = EmailMessage.bind( service, item.getId() );
em.getInternetMessageId()
However, that still loads the entire message.
The other solution is to start associating messages by the ItemId, but even that's not perfect: http://daniellang.net/exchange-web-services-itemid-is-not-permanent/
More about Message-ID: http://en.wikipedia.org/wiki/Message-ID
I believe the solution is this:
EmailMessage em = EmailMessage.bind( service, item.getId(),
new PropertySet( EmailMessageSchema.InternetMessageId) );
Explanation :
We have to bind the item to an email message, but instead of grabbing all the info, we only ask for the ID and any additional properties we want through the PropertySet parameter.
Inspired by this answer: https://stackoverflow.com/a/22482779/138228
Related
Requirement is to sync mails from Gmail for an user into our CRM. The system in place is based on Google Pub/Sub which watches inbox of the user for any change and fires the notification to our HTTPs endpoint. More on this at Gmail cloud pub/sub.
Based on the above procedure we git history of changes. And then i am interested in only new messages, so history.getMessagesAdded is preferred as per this guide. Issue we are facing now is the first mail of a thread is not captured under messagesAdded all the subsequent messages are passing through our system.
Note: For the first mail, we do get push from Google. But when we try to get Messages added it turns out empty. Is there anything special needs to be done for the first mail of the thread or am i missing out something.
I was experiencing a very similar problem, and my mistake was that I was using the historyId from the push notification, the solution was to store the last known historyId on my database, so, every time I get a notification, I get the history from the id I have stored, not the one from the notification.
In my case, the historyId from the notification doesn't even make part of the history, maybe because of my watch restrictions: labelIds=['INBOX']
This is the google pub/sub notification:
{
message:
{
data: {"emailAddress": "user#example.com", "historyId": "9876543210"},
message_id: "1234567890",
}
subscription: "projects/myproject/subscriptions/mysubscription"
}
I was using the message.data.historyId, wich was causing the confusion!
The message.data, comes as a base64 encoded string, in this example I just decoded it!
Step by step for watching new e-mails on the inbox:
Do all the configuration in the google pub/sub.
Start watching the user with the filters you want (docs.: https://developers.google.com/gmail/api/v1/reference/users/watch)
Store the historyId obtained in the step 2
When receive the notification, get all the events (history) using the stored id as the startHistoryId parameter (docs: https://developers.google.com/gmail/api/v1/reference/users/history/list)
In the history list obtained on the step 4, look for the new messages: history.getMessagesAdded().
Update the last known history id in your database, so you don't need to deal with the whole history every time!
I hope it helps.
I'm trying to use twitter4j (in Java) to grab the list of users following a particular user who happen to have direct messaging enabled. Something like this...
IDs followerIDs = twitter.getFollowersIDs(someTwitterScreenName, -1);
long[] ids = followerIDs.getIDs();
for (long id : ids) {
twitter4j.User user = twitter.showUser(id);
String userScreenName = user.getScreenName();
String realName = user.getName();
//I'm hoping for something like...
///Boolean directMessagingEnabled = user.messagingEnabled();
}
The only problem is that I can't find any attributes associated with the twitter4j.User object that sound suitable (and also can't find any reference to it in the API documentation). Does anyone know if there's some way to programmatically find these types of users? Or perhaps twitter have deliberately excluded it? Thanks for any thoughts at all.
------EDIT-----
The documentation link from Yuri led me to this response from a twitter employee: "Determining if a user accepts DMs from all is not available via the public API. If you are a trusted partner please reach out via your direct Twitter contacts for details."
(https://twittercommunity.com/t/how-can-i-tell-which-users-the-current-user-can-send-messages-to/36127/4)
Also noticed that it IS possible to get the DM status for an already authenticated user using "AccountSettings.getAccountSettings().allow_dms_from"
This is discussed here
https://dev.twitter.com/rest/reference/post/direct_messages/new
There is apparently a whitelist for access you can apply for.
However it seems you mostly have all you need. The users following your account can usually receive DMs from you already. This doesn't cover the cases where the user either DMed you first, or accepts DMs from anyone.
But it is probably simplest to try sending and inspect the failures.
I am very new to java server side development, i have followed this link [http://javapapers.com/android/google-cloud-messaging-gcm-for-android-and-push-notifications/][1] and successfully implemented GCM with my android device, the problem is dont know how to trigger the GCM server while the content is updated in my db,i need to notify each and every update of my db to the user, am i need to watch the db using timer task something like that or is there any default solution to keep track of db ?
My Server side code :
regId = "my registration id";
String userMessage = request.getParameter("message");
Sender sender = new Sender(GOOGLE_SERVER_KEY);
Message message = new Message.Builder().timeToLive(30)
.delayWhileIdle(true).addData(MESSAGE_KEY, userMessage).build();
result = sender.send(message, regId, 1);
have tried with many solution but till now not getting exact solution, Suggestion, ideas or related links are most welcome
Thanks in advance
Without knowing the specific functionality of your server and app, I can only offer a general solution.
Each process in your server that performs DB updates that have to be pushed to some Android devices via GCM can write the messages and the registration IDs to some kind of queue.
Then you can have another process (or processes) that would consume the queue of GCM messages, and send them to Google. These processes can handle failures (retry sending the messages in case of temporary failures), and update your database of registration IDs if they receive responses with canonical registration IDs or errors such as InvalidRegistration or NotRegistered.
I have a piece of code which uses spring integration's IMAP adapter to poll an inbox to read all incoming emails which are unread and that works perfectly. But if I open any email message and and then mark it as "unread" in my outlook inbox the poller doesn't fetch the marked email.
I can use the pop3 adapter which fetches all the email, but deletes them afterwords, but I want to keep the emails in my inbox and I want the poller to fetch all the email which are unseen.
Any suggestions to handle this problem? I been searching and reading articles on email adapters but didn't find anything useful.
Thanks in advance.
Looks like you need custom 'search-term-strategy'. From Spring Integration (SI) documentation:
By default, the ImapMailReceiver will search for Messages based on the default SearchTerm which is All mails that are RECENT (if supported), that are NOT ANSWERED, that are NOT DELETED, that are NOT SEEN and have not been processed by this mail receiver (enabled by the use of the custom USER flag or simply NOT FLAGGED if not supported). Since version 2.2, the SearchTerm used by the ImapMailReceiver is fully configurable via the SearchTermStrategy which you can inject via the search-term-strategy attribute. SearchTermStrategy is a simple strategy interface with a single method that allows you to create an instance of the SearchTerm that will be used by the ImapMailReceiver.
And here is a post from SI forum with funtastic Oleg's explanation: Server does not support RECENT or USER flags
And here you can find SI DefaultSearchTermStrategy: it's a place to determine how you should implement your own strategy. I guess, you case is:
This email server does not support RECENT flag, but it does support USER flags which will be used to prevent duplicates during email fetch.
Switch SI-mail logging level to DEBUG and take a look, which flag supports your email server.
I want to debug GCM messages which receives my application but the problem I can't log fields outside the data array: collapse key, time-to-live , etc. GCM message which comes from the server is look like this:
{
"registration_ids" : ["xyz"],
"data" : {
text: {...}
},
"time_to_live" : 3
},
For debugging purposes i want to log time-to live parameters and others.But when I do this: String text = intent.getExtras().getString("text"); I can only view what is inside data. How can I view all the GCM message structure?
I don't believe you can.
The parameters outside of data are not part of the notification payload. It's quite reasonable to believe that they are not even passed by the GCM server to your application. These outside params' only purpose is to tell the GCM server how to deliver the message (whether to send it to an idle device, how long to keep it in the GCM server when the device is not available, whether to override older undelivered messages that have the same collapse key, etc...).
EDIT :
Handling Received Data
The com.google.android.c2dm.intent.RECEIVE intent is used by GCM to deliver the messages sent by the 3rd-party server to the application running in the device. If the server included key-pair values in the data parameter, they are available as extras in this intent, with the keys being the extra names. GCM also includes an extra called from which contains the sender ID as an string, and another called collapse_key containing the collapse key (when in use).
From this quote, it seems you can also retrieve the collapse_key and the sender ID in addition to the key/value pairs inside data.