Esempio n. 1
0
        /// <summary>
        /// Appends a new message to the end of specified folder
        /// </summary>
        /// <param name="eml">The eml data of the message to append</param>
        /// <param name="flags">The flags to be set for the message. If empty, the server will add the \Recent flag automatically</param>
        /// <param name="date">The internal date of the message to be set</param>
        /// <returns><code>true</code> if the message was appended, otherwise <code>false</code></returns>
        public bool AppendMessage(string eml, IEnumerable <string> flags = null, DateTime?date = null)
        {
            if (string.IsNullOrEmpty(eml))
            {
                throw new ArgumentException("eml cannot be empty");
            }

            if (ReadOnly)
            {
                Select();
            }

            IList <string> data = new List <string>();

            var msgUploader = new MessageUploader(eml);

            var dateStr = date.HasValue ? " \"" + date.Value.ToImapInternalDate() + "\"" : "";

            return(_client.SendAndReceive(
                       string.Format(ImapCommands.Append,
                                     _path) +
                       (flags != null && flags.Any() ?
                        " (" + string.Join(" ", flags.ToArray()) + ")" : "")
                       + dateStr + " {" + eml.Length + "}",
                       ref data, msgUploader));
        }
        /// <summary>
        /// Appends a new message to the end of specified folder
        /// </summary>
        /// <param name="eml">The eml data of the message to append</param>
        /// <param name="flags">The flags to be set for the message. If empty, the server will add the \Recent flag automatically</param>
        /// <param name="date">The internal date of the message to be set</param>
        /// <returns><code>true</code> if the message was appended, otherwise <code>false</code></returns>
        public bool AppendMessage(string eml, IEnumerable <string> flags = null, DateTime?date = null)
        {
            if (string.IsNullOrEmpty(eml))
            {
                throw new ArgumentException("eml cannot be empty");
            }

            IList <string> data = new List <string>();

            var msgUploader = new MessageUploader(eml);

            var dateStr = date.HasValue ? date.Value.ToString("dd-MM-yyyy") : "";

            if (dateStr.StartsWith("0"))
            {
                dateStr = " " + dateStr.Substring(1, dateStr.Length - 1);
            }

            return(_client.SendAndReceive(
                       string.Format(ImapCommands.Append,
                                     _path) + " {" + eml.Length + "}",
                       ref data, msgUploader));
        }