| Author |  | 
      
        | hmuscroft Groupie
 
  
 
 Joined: 29 December 2009
 Location: United Kingdom
 Online Status: Offline
 Posts: 72
 | 
          Just when I think I've nearly finished implementing IMAP, something new keeps cropping up!
           | Posted: 24 January 2017 at 5:52am | IP Logged |   |  
           | 
 |  
 OK, so when a user chooses to SAVE A DRAFT of an email they're working on, I can upload it using "imap.UploadMessage(msg, draft_folder);"
 
 However, if they then do some more editing of the email and click SAVE DRAFT again, I now need to UPDATE the existing email.
 
 What is the best approach for this? Should I get the UID of the first draft upload, then DELETE it and RE-UPLOAD the new draft each time, or is there a way of updating the existing draft message on the imap server?
 
 What would you recommend as best practice?
 
 Many thanks (again!).
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | Alex AfterLogic Support
 
  
  
 Joined: 19 November 2003
 Online Status: Offline
 Posts: 2207
 | 
          You'll need to delete and upload a new draft each time. There is no UPDATE action of any kind in IMAP.
           | Posted: 24 January 2017 at 6:09am | IP Logged |   |  
           | 
 |  
 If the server supports UIDPLUS (and Hotmail does), you can get UID of uploaded message immediately during upload. This will give you a hint which message to delete next time when replacing an older draft.
 
 Getting just the latest draft in the folder (instead of remembering UID of just uploaded message from UIDPLUs results) is not reliable. What if another draft is being edited simultaneously in a multi-user environment? However, if the server does not support UIDPLUS, getting the last UID is the only option. Just do it immediately after upload to minimize the risk that someone else also uploads a message between your upload and getting UID actions.
 
 Regards,
 Alex
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | hmuscroft Groupie
 
  
 
 Joined: 29 December 2009
 Location: United Kingdom
 Online Status: Offline
 Posts: 72
 | 
          Yes that makes sense - thanks.
           | Posted: 24 January 2017 at 6:38am | IP Logged |   |  
           | 
 |  
 So I can get the "UidPlusResult" result of an imap.UploadMessage(...) and then I can check the .IsSupported to see if I can get the UID from that object.
 
 But... if the server doesn't support UIDPLUS, then what method would you recommend to retrieve the last UID?
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | Alex AfterLogic Support
 
  
  
 Joined: 19 November 2003
 Online Status: Offline
 Posts: 2207
 | 
          
           | Posted: 24 January 2017 at 7:07am | IP Logged |   |  
           | 
 |  
| Quote: 
 
    
    | 
      
       | However, if the server does not support UIDPLUS, getting the last UID is the only option. Just do it immediately after upload to minimize the risk that someone else also uploads a message between your upload and getting UID actions.
 
 |  |  |  DownloadEnvelopes(imp.MessageCount.ToString(), false, EnvelopeParts.Uid, 0)
 
 You can go further and, for instance, with UID also download the message header and analyze Message-ID (or any other custom header of your choice which you can use to provide unique values to your drafts). If the draft's unique value is different from what you expect, it means someone else put it at the same time and you should repeat with a previous message, etc until you find the message you need. This pattern prevents possible race conditions even if UIDPLUS is not available.
 
 Regards,
 Alex
 | 
       
        | Back to Top |     | 
       
       
        |  | 
        | hmuscroft Groupie
 
  
 
 Joined: 29 December 2009
 Location: United Kingdom
 Online Status: Offline
 Posts: 72
 | 
          Thanks Alex. I must congratulate you on your support which is first rate.
           | Posted: 24 January 2017 at 7:12am | IP Logged |   |  
           | 
 |      | 
       
        | Back to Top |     | 
       
       
        |  | 
        | Alex AfterLogic Support
 
  
  
 Joined: 19 November 2003
 Online Status: Offline
 Posts: 2207
 | 
          Much appreciated :) Thanks!
           | Posted: 24 January 2017 at 7:15am | IP Logged |   |  
           | 
 |  
 Regards,
 Alex
 | 
       
        | Back to Top |     | 
       
       
        |  |