示例#1
0
        /// <summary>
        /// 将邮件保存到草稿箱 返回邮件的唯一标识
        /// 调用前先调用配置方法CfgIMAP(),调用制做邮件方法
        /// </summary>
        public int SaveDrafts(int uniqueId = -1)
        {
            try
            {
                using (ImapClient client = ConnectIMAP())
                {
                    // 打开草稿箱,添加邮件
                    IMailFolder folder = client.GetFolder(SpecialFolder.Drafts);
                    folder.Open(FolderAccess.ReadWrite);

                    // 如果保存的是已经有的草稿邮件,则删除它再保存新的草稿.(没找到保存已有草稿的办法)
                    if (uniqueId > -1)
                    {
                        List <UniqueId> uidls = new List <UniqueId>();
                        uidls.Add(new UniqueId((uint)uniqueId));
                        folder.SetFlags(uidls, MessageFlags.Seen | MessageFlags.Deleted, true);
                        folder.Expunge(uidls);
                    }

                    UniqueId?uid = folder.Append(this.message, MessageFlags.Seen | MessageFlags.Draft);
                    //
                    folder.Close();
                    client.Disconnect(true);
                    return(uid.HasValue ? (int)uid.Value.Id : -1);
                }
            }
            catch (Exception e)
            {
                ErrMsg = $"邮件保存草稿时异常:{e.ToString()} [{e.Message}]";
                return(-1);
            }
        }
示例#2
0
        public async Task <UniqueId?> WriteAndUnlockStore(IMailFolder parentFolder, EmailBackedKeyValueStore?kvStore, LockResult activeLock)
        {
            if (kvStore == null)
            {
                return(UniqueId.Invalid);
            }

            try
            {
                UniqueId?replacementResult = null;
                // TBD review locking
                lock (parentFolder.SyncRoot)
                {
                    parentFolder.Open(FolderAccess.ReadWrite);
                    logger.Debug("Updating existing storage message in folder {FolderPath} with ID {@ID}", parentFolder.FullName, kvStore.MessageAndId.UniqueId);
                    replacementResult = parentFolder.Replace(kvStore.MessageAndId.UniqueId, kvStore.MessageAndId.Message);
                    parentFolder.SetFlags(kvStore.MessageAndId.UniqueId, MessageFlags.Seen, true);
                }
                return(replacementResult);
            }
            finally
            {
                var unlockResult = await remoteLock.ReleaseLock(parentFolder, activeLock.LockResourceName, activeLock.ResultingLockCookie);

                if (!unlockResult)
                {
                    logger.Warning("Could not unlock the following lock: {@LockResult}", activeLock);
                }
            }
        }
示例#3
0
        static void GetThreads(ThreadableNode root, IList <MessageThread> threads, IList <OrderBy> orderBy)
        {
            root.Children.Sort(orderBy);

            for (int i = 0; i < root.Children.Count; i++)
            {
                var      message = root.Children[i].Message;
                UniqueId?uid     = null;

                if (message != null)
                {
                    uid = message.UniqueId;
                }

                var thread = new MessageThread(uid);
                GetThreads(root.Children[i], thread.Children, orderBy);
                threads.Add(thread);
            }
        }
示例#4
0
        static void GetThreads(ThreadableNode root, List <MessageThread> threads, OrderBy[] orderBy)
        {
            var sorted = MessageSorter.Sort(root.Children, orderBy);

            for (int i = 0; i < sorted.Count; i++)
            {
                var      message = sorted[i].Message;
                UniqueId?uid     = null;

                if (message != null)
                {
                    uid = message.ThreadableUniqueId;
                }

                var thread = new MessageThread(uid);
                GetThreads(sorted[i], thread.children, orderBy);
                threads.Add(thread);
            }
        }
示例#5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MailKit.MessageThread"/> class.
 /// </summary>
 /// <remarks>
 /// Creates a new message thread node.
 /// </remarks>
 /// <param name="uid">The unique identifier of the message.</param>
 public MessageThread(UniqueId?uid)
 {
     Children = new List <MessageThread> ();
     UniqueId = uid;
 }
示例#6
0
        /// <summary>
        /// Attempt to parse the specified token as a set of unique identifiers.
        /// </summary>
        /// <remarks>
        /// Attempts to parse the specified token as a set of unique identifiers.
        /// </remarks>
        /// <returns><c>true</c> if the set of unique identifiers were successfully parsed; otherwise, <c>false</c>.</returns>
        /// <param name="token">The token containing the set of unique identifiers.</param>
        /// <param name="validity">The UIDVALIDITY value.</param>
        /// <param name="uids">The set of unique identifiers.</param>
        /// <param name="minValue">The minimum unique identifier value parsed.</param>
        /// <param name="maxValue">The maximum unique identifier value parsed.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="token"/> is <c>null</c>.
        /// </exception>
        internal static bool TryParse(string token, uint validity, out UniqueIdSet uids, out UniqueId?minValue, out UniqueId?maxValue)
        {
            if (token == null)
            {
                throw new ArgumentNullException(nameof(token));
            }

            uids     = new UniqueIdSet(validity);
            minValue = maxValue = null;

            var  order  = SortOrder.None;
            uint min    = uint.MaxValue;
            uint max    = 0;
            bool sorted = true;
            uint prev   = 0;
            int  index  = 0;

            do
            {
                if (!UniqueId.TryParse(token, ref index, out uint start))
                {
                    return(false);
                }

                min = Math.Min(min, start);
                max = Math.Max(max, start);

                if (index < token.Length && token[index] == ':')
                {
                    index++;

                    if (!UniqueId.TryParse(token, ref index, out uint end))
                    {
                        return(false);
                    }

                    min = Math.Min(min, end);
                    max = Math.Max(max, end);

                    var range = new Range(start, end);
                    uids.count += range.Count;
                    uids.ranges.Add(range);

                    if (sorted)
                    {
                        switch (order)
                        {
                        default: order = start <= end ? SortOrder.Ascending : SortOrder.Descending; break;

                        case SortOrder.Descending: sorted = start >= end && start <= prev; break;

                        case SortOrder.Ascending: sorted = start <= end && start >= prev; break;
                        }
                    }

                    prev = end;
                }
                else
                {
                    uids.ranges.Add(new Range(start, start));
                    uids.count++;

                    if (sorted && uids.ranges.Count > 1)
                    {
                        switch (order)
                        {
                        default: order = start >= prev ? SortOrder.Ascending : SortOrder.Descending; break;

                        case SortOrder.Descending: sorted = start <= prev; break;

                        case SortOrder.Ascending: sorted = start >= prev; break;
                        }
                    }

                    prev = start;
                }

                if (index >= token.Length)
                {
                    break;
                }

                if (token[index++] != ',')
                {
                    return(false);
                }
            } while (true);

            uids.SortOrder = sorted ? order : SortOrder.None;

            if (min <= max)
            {
                minValue = new UniqueId(validity, min);
                maxValue = new UniqueId(validity, max);
            }

            return(true);
        }
示例#7
0
 internal MessageThread(UniqueId?uid)
 {
     children = new List <MessageThread> ();
     UniqueId = uid;
 }
示例#8
0
 internal MethodSchema(string methodName, object[] actualParameters, UniqueId?dynamicInterfaceImplementationUniqueId = null)
 {
     this.methodName       = methodName;
     this.actualParameters = actualParameters;
     this.dynamicInterfaceImplementationUniqueId = dynamicInterfaceImplementationUniqueId;
 } //MethodSchema