/// <summary> /// Stores the specified mail message on the IMAP server. /// </summary> /// <param name="message">The mail message to store on the server.</param> /// <param name="seen">Set this to true to set the \Seen flag for the message on the /// server.</param> /// <param name="mailbox">The mailbox the message will be stored in. If this parameter is /// omitted, the value of the DefaultMailbox property is used to determine the mailbox to store /// the message in.</param> /// <returns>The unique identifier (UID) of the stored message.</returns> /// <exception cref="ArgumentNullException">The message parameter is null.</exception> /// <exception cref="BadServerResponseException">The mail message could not be stored. The /// message property of the exception contains the error message returned by the /// server.</exception> /// <exception cref="ObjectDisposedException">The ImapClient object has been disposed.</exception> /// <exception cref="IOException">There was a failure writing to or reading from the /// network.</exception> /// <exception cref="NotAuthenticatedException">The method was called in non-authenticated /// state, i.e. before logging in.</exception> /// <remarks>A unique identifier (UID) is a 32-bit value assigned to each message which uniquely /// identifies the message within the respective mailbox. No two messages in a mailbox share /// the same UID.</remarks> /// <seealso cref="StoreMessages"/> /// <include file='Examples.xml' path='S22/Imap/ImapClient[@name="StoreMessage"]/*'/> public uint StoreMessage(MailMessage message, bool seen = false, string mailbox = null) { AssertValid(); message.ThrowIfNull("message"); string mime822 = message.ToMIME822(); lock (sequenceLock) { PauseIdling(); if (mailbox == null) mailbox = defaultMailbox; string tag = GetTag(); string response = SendCommandGetResponse(tag + "APPEND " + Util.UTF7Encode(mailbox).QuoteString() + (seen ? @" (\Seen)" : "") + " {" + mime822.Length + "}"); // The server must send a continuation response before we can go ahead with the actual // message data. if (!response.StartsWith("+")) throw new BadServerResponseException(response); response = SendCommandGetResponse(mime822); while (response.StartsWith("*")) response = GetResponse(); ResumeIdling(); if (!IsResponseOK(response, tag)) throw new BadServerResponseException(response); return GetHighestUID(mailbox); } }
public uint StoreMessage(MailMessage message, bool seen = false, string mailbox = null) { AssertValid(); message.ThrowIfNull("message"); string mime822 = message.ToMIME822(); lock (sequenceLock) { PauseIdling(); if (mailbox == null) { mailbox = defaultMailbox; } string resptag = GetTag(); string response = SendCommandGetResponse(resptag + "APPEND " + Util.UTF7Encode(mailbox).QuoteString() + (seen ? @" (\Seen)" : string.Empty) + " {" + mime822.Length + "}"); if (!response.StartsWith("+")) { throw new BadServerResponseException(response); } response = SendCommandGetResponse(mime822); while (response.StartsWith("*")) { response = GetResponse(); } ResumeIdling(); if (!IsResponseOK(response, resptag)) { throw new BadServerResponseException(response); } return GetHighestUid(mailbox); } }