How to lock a (IMAP) Folder or Message?

I am working on a program that reads and processes email messages from a IMAP folder. Because there might be huge volume of messages to be processed, multiple processes of this program may run on different machines. Since a single message can only be processed once, I need a lock mechanism that guarantees that no message can be read by more than one processes at any time.
Can anyone tell me how to do that by using JavaMail APIs? Thanks a lot.

Thanks. I tried using flag but got duplicated messages. There is a method doCommand(IMAPFolder.ProtocolCommand cmd) in class IMAPFolder. The document says that it "Execute a user-supplied IMAP command. The command is executed in the appropriate context with the necessary locks held and using the appropriate IMAPProtocol object. " I tried to use it. But it seems that there was still a race condition. Below is my code:
protected Message getNextMessage(IMAPFolder folder) throws Exception {
if (! folder.isOpen())
folder.open(Folder.READ_WRITE);
//curImapFolder is a class member variable
curImapFolder = folder;
Object val = folder.doCommand(new IMAPFolder.ProtocolCommand() {
public Object doCommand(IMAPProtocol p) throws ProtocolException {
Flags searchflags = new Flags(Flags.Flag.FLAGGED);
searchflags.add(Flags.Flag.DELETED);
FlagTerm term = new FlagTerm(searchflags, false);
int[] ids = null;
try {
ids = p.search(term);
} catch (SearchException se) {
return null;
if ((null == ids) || (ids.length <= 0))
return null;
Message msg = null;
try {
//get the first fresh message
msg = curImapFolder.getMessage(ids[0]);
} catch (MessagingException me) {
msg = null;
if (null != msg) {
//set message not fresh
Flags checkedflags = new Flags(Flags.Flag.FLAGGED);
p.storeFlags(ids[0], checkedflags, true);
return msg;
else
return null;
return (Message)val;
}

Similar Messages

  • Mail always creates To-Dos in IMAP folder.. message pop-ups annoying.

    I tried to create a new todo in Mail by right-clicking on a message and choosing the option.
    Apart from the text styling looking very ugly, I can't use this feature because a message keeps popping up:
    +Different versions of a To Do item have been found for the account "Gmail"+
    No matter which button I press to close the dialogue it keeps coming back. Eventually I have to look in the Gmail To-do folder and delete the to-do.
    I notice this bug was found back in Feb 2008 on Leopard: http://forums.macosxhints.com/showthread.php?t=80739
    I have tried changing the preference for notes to be created 'On My Mac' and not in Gmail IMAP but the preference does not seem to do anything - it still keeps dropping them in the Gmail account. This is after closing prefs, quitting and restarting Mail.
    Very annoying.
    Anyone know how to solve it?
    Is this an OS X bug?

    quit Mail, open iCal and delete all gmail to-dos. start Mail and see if that helps.

  • How to lock icloud photo folder on my windows 7

    i recently have purchased an iphone 6 and am loving it. Ive set up my icloud account and realized it is nice having my photos automatically uploaded to my icloud photo folder on my pc. I am just wondering if there is any way i can put a password or lock this folder because i share my pc with my younger siblings and can have personal photos that i want to keep private. Any help would be greatly appreciated

    Go here for more info:
    http://answers.microsoft.com/en-us/windows/forum/windows_7-performance/how-do-i- make-my-printer-on-windows-7-share-with/bd920e46-dbeb-4bb2-a38e-8791facd0608

  • Search finds messages, but how do I know what folder the message is in?

    New to TB from Eudora. I like TB.
    Playing around with searching, both using the box within TB as well as Windows Search. Either way I get results - slightly different but that's okay. But using both methods, when I've found the message that interests me, I can't determine the TB folder in which the message resides. Is there a way to do this?

    have a look at the space being consumed by the mozmsg files and then decide if windows search is really worth it. I got rid of gigabytes of those files around 80 thousand of them. I thought it was more baggage than it was worth. What suprised me was that turn off the windows search option did not remove the files.
    But to your question. When you have the returned list in front of you. In the middle at the top, hidden in plain sight, is the show as a list option. Once you have them in a list you can click the widget at the end of the heading row and select folder. (unfortunately it does not save.)
    You might like the search under Ctrl+Shift+F as well. Those can be saved as "virtual folders"

  • Mail 3.6 doesn't show new message in IMAP folder

    Hello,
    I am using Mail with an IMAP server.
    On this IMAP server, mails are automatically sorted to different mailboxes (IMAP folder) via .procmail.rc directives.
    When I receive an Email and when this email is dispatched in the correct mailbox, Mail3.6 doesn't display this new message.
    Questions : How to set-up Mail3.6 to correctly display new incoming mail server sorted in IMAP folder ? or How to overcome this Mail bug ?
    PS : This question was already asked a few months ago on Apple Bug Report, answer was that this bug will be corrected on the next release.... Seems not...
    Thank you by adance

    Hello,
    I am having a very similar problem that just started happening recently when I started using gmail folders instead of my school's email (both IMAP).
    I have all emails configured for IMAP and the messages arrive fine, but when mail applies my custom filters and the messages are moved to the individual folders, the new message indicator (on the file and on the dock icon) are not present. The only new messages that appear are those in the mail Inbox. When I then click on the individual folders (I have to click through them all individually) it recognizes the new, unread email and updates the indicators (both next to the custom folder and on the dock icon).
    This is a frustrating issue because I do not have any indication that I have new mail unless I go and click on each folder individually.
    The issue just started occurring when i switched to using my gmail account. The folders seem to be set up appropriately to move messages in Mail and also have them labeled on gmail ([GMAIL]/foldername), but Mail just doesn't seem to recognize the messages as new once they have been moved to the folders until I sync (either by clicking on the folder or by using the "synchronize all accounts" command).
    Any suggestions? I found this same issue in the archived questions (http://discussions.apple.com/message.jspa?messageID=7513842), but it was not resolved.
    Thanks,
    Daniel
    Message was edited by: dharveyfm

  • Moving IMAP gmail folder error message

    This is not a question, but just posting to help someone else who might be having the same problem.  When moving Gmail folders from "On My mac" to the IMAP folder for Gmail, I received the error message:
    The IMAP command “CREATE” failed with server error: Folder contains excess whitespace (Failure).
    Turns out that one of the sub-folders I was trying to move had a folder name with a space at the end of it.  As soon as I deleted the extra space at the end of the folder name, Gmail would allow me to move the folders.
    Also, I was moving a batch of multiple folders and all of the ones prior to this one moved successfully.  The one with the extra space, plus all of the folders after this one, failed to move until I solved the problem.

    Hello,
    I have used the procedure/settings described in the link hereunder on my Z10 and iCloud mail is working fine:
    http://helpblog.blackberry.com/2013/03/how-to-setup-icloud-email/
    If the problem still persists, I would advise to consult your administrator to check about possible limitations.
    Hope this helps
    Please don't forget to mark as "solved" if your question is replied and to "like" a useful reply to your post ;-)

  • How do I get email and text message notifications when my phone is locked?

    How do I get email and text message banner notifications on my iphone when the phone is locked? When I had iOS 6 I could get notifications with sound and banner. Now that I have iOS7 I can't see notificaitons when the phone is locked.

    See if this support document about Notifications helps. http://support.apple.com/kb/HT3576

  • How to lock a drive and/or folder if there is no lock icon in the get info field?, how to lock a drive and/or folder if there is no lock icon in the get info field?

    how to lock a drive and/or folder if there is no lock icon in the get info field?, how to lock a drive and/or folder if there is no lock icon in the get info field?

    You can create an encrypted disk image.
    http://www.macworld.com/article/1154559/password_protect_folders.html

  • How to lock a folder with password ?

    Please tell me how to lock a folder with password (to keep personal files)

    Keep looking it can be done. I have a folder on my hard drive that requires a password everytime I try to open it. I found how to do this in an old "Mac OS - The missing manual" but don't remember off the top of my head how I did it. I remember you have to partition a portion of the hard drive, I think I did like 10 Gig of my 1 Teribite external drive and then you give it a name and make up a password. The password is NOT changeable and if you lose it you can't get back in that folder. It appears as a standard folder but needs a password to open it.
    Email me direct if you can't find any info and I will try to look it up - [email protected]

  • How to display your email and a message to finder on the lock screen of an iPhone?

    Hi,
    I loose things, including phones and keys...
    To prevent a worst case scenario: How to display your email and a message to finder on the lock screen of an iPhone? (6 plus, current iOS)
    That is, I assume most people finding an iPhone would want to try to contact me to give it back to me, if they know how: how can leave my contact information in the phone? This needs to be on the lock screen, naturally, as this is the only view the finder can see. It would be useful to be able to add a message of sorts a la "if found please call my wife ### or email me ###".
    How can this be done other than editing the JPG of the wallpaper, or sticking a business card to the back of the phone (these are the only solutions I came up with, there must be something better).
    Cheers!

    Greetings _daniel_, 
    Thank you for contributing to the Apple Support Communities. 
    It seems like you'd like to display a message on your iPhone 6 Plus in the event it is lost. Good news--you can do this with the Find my iPhone feature of iCloud.
    Check out these links for more information:
    iCloud: Set up iCloud
    iCloud: Use Lost Mode
    If you can’t find your device, use Lost Mode right away to lock it with a passcode, display a custom message on the screen, and keep track of its location.
    Cheers, 
    Jeremy

  • How to lock folder at working space

    Hi,
    I just recently purchased new macbook pro,and I cannot find a way how to lock the folder at specific working space ( ie lione lets create many working spaces). So I want to make sure how to lock folder at specific working space.

    Thanks your reply ^^
    I need to lock 'db' folder including system key on Mac OS.
    Such as this picture below :
    Edit

  • How to lock only the message on lenovo a6000 plus?

    Respected sir, i have bought a lenovo a6000 plus and i want to know how to lock only the message on it, when its locking message, contacts, call log & dialer, altogether?

    There is no way to lock access to individual apps on the phone.

  • How do I change IMAP "special folder" names

    For the special folders for "Trash" and "Sent", even though Mail.app displays the names thus, the actual folder names that it creates on the IMAP server are "Deleted Messages" and "Sent Messages". That seems a little absurd to me. If the designers of Mail.app thought that "Trash" and "Sent" were the best names for those folders, why did they make the actual folder names "Deleted Messages" and "Sent Messages"? And why is there not a way in the account settings for me to tell Mail.app which IMAP folders to use for those special folders, a la Thunderbird?
    The problem is that, when I'm not on my Mac I have to use either Thunderbird or the Zimbra webmail client--BOTH of which (rationally) use "Trash" and "Sent" for their special trash and sent folders. Thunderbird, of course, lets you choose which IMAP folder to use. But Zimbra doesn't. It would be REALLY nice if Mail.app would allow me to choose which IMAP folders to use for Trash, Sent, Drafts, and Junk, just like Thunderbird does.
    (To make matters even worse, if you happen to connect to your IMAP account with MS Outlook, it creates folders called "Deleted Items" and "Sent Items". Now I ask you, WHAT'S WRONG WITH JUST "Trash" and "Sent"???
    --Dan

    Subject to names the IMAP server creates, you can often tell Mail to use any folder for these purposes. Open a folder, click on Mailbox in the Menubar, choose Use This Mail For and see if the options are in black type or gray. If black you can choose.
    However, Trash is a category in the Sidebar. The name given to standard mailboxes used in account folders (each account has its own set), whether POP or IMAP are set in the application. With IMAP there is some ability to alter, depending upon the standards of the IMAP server, I believe.
    Ernie

  • How should i lock apps(whatsapp, facebook and messages) in iphone4

    how should i lock apps(whatsapp, facebook and messages) in iphone4.

    By setting a passcode on your phone: Settings > General > Passcode Lock.
    You cannot lock individual apps.

  • How does one move or copy emails from one IMAP folder to another without loosing tags?

    I am using Thunderbird 31 with an IMAP server (one that I control) and I'm wanting to move some emails from one IMAP folder to another (within the same account) which works just fine, but I noticed that tags are not retained. Is there a way to copy/move emails without losing tags?
    Thanks:

    I think there are some misunderstood.
    I do not suggest to "Switch" devices.
    I suggest the safest way how you can do it.
    Connect device, where you have needed Address Book, buckup it (only Address Book)
    Then connect second device and just recover Address Book, after from Second device you can delete not needed contact.
    I have 6 devices for separate issue and in all of them same contact, with small changes
    Be sure to click Likes! for those who have helped you.
    If your query is resolved then please click on “Accept as Solution”.

Maybe you are looking for

  • Transition from Trial to Purchased Java + DB PaaS cloud - overage?

    Oracle, A minimum configuration for Java EE hosting on Oracle Cloud Java + Database comes out to around 12 * (250 + 175) * 1.13 = $5763 per year - which is a price that requires some diligence for small businesses but worth it in order to use a full

  • PI 7.1 Performance Monitoring - Advanced Adapter Engine (AAE)

    Hi Experts, how can i use the "Performance Monitoring" from the RWB, to see all the messages (including the messages from the AAE) for a specific timeperiod? For example, i want to know how many messages go through the PI (including AAE) on one day.

  • Billing Plan Values different in VA02 & VA03

    Hi All, We have a case where in the billing plan values are different for the same sales order when seen in change mode (VA02) & display mode (VA03). can you please let me know what and where the problem can be? Regards Sujay

  • XDK upgrade 9.0.1.2.0 -- 9.2.0.1.0 problem (XSL-1049)

    Doing a test upgrade of XDK 9.0.1.2.0 --> 9.2.0.1.0, I ran into XSL-1049: (Error) Template ... invoked but not defined. I have produced a simple test case that illustrates the problem: file test.xsql contains: <?xml version="1.0"?> <?xml-stylesheet t

  • Album Art screensaver won't work w/iTunes 9

    I just updated to iTunes 9 and now my screensaver won't work. I use the standard Apple iTunes artwork screensaver. It say "You're iTunes library does not contain any songs with artwork". Any ideas? I closed iTunes, reopened it, restarted it. Obviousl