private static string GetHash(string input) { ImapEntryId.ValidateCreateEntryIdInput(input); byte[] sha1Hash = CommonUtils.GetSHA1Hash(input.ToLowerInvariant()); StringBuilder stringBuilder = new StringBuilder(BitConverter.ToString(sha1Hash)); stringBuilder = stringBuilder.Replace("-", string.Empty); return(stringBuilder.ToString()); }
public static uint ParseUid(byte[] messageEntryId) { Dictionary <string, string> dictionary = ImapEntryId.ParseMessageEntryId(messageEntryId); string s; uint result; if (dictionary.TryGetValue("U", out s) && uint.TryParse(s, out result)) { return(result); } throw new ParsingMessageEntryIdFailedException(TraceUtils.DumpBytes(messageEntryId), new ArgumentException("Cannot parse uid.", "messageEntryId")); }
private void EnumerateIncrementalChanges(ImapFolderState currentState, ImapFolderState lastSyncedState, FolderChangesManifest changes, IEnumerable <MessageRec> messages) { Dictionary <uint, MessageRec> dictionary = new Dictionary <uint, MessageRec>(); foreach (MessageRec messageRec in messages) { uint key = ImapEntryId.ParseUid(messageRec.EntryId); dictionary.Add(key, messageRec); } this.EnumerateNewMessages(currentState, lastSyncedState, changes, dictionary); this.EnumerateReadUnreadFlagChanges(currentState, lastSyncedState, changes, dictionary); this.EnumerateMessageDeletes(currentState, lastSyncedState, changes, dictionary); }
public static byte[] CreateFolderEntryId(string input) { string hash = ImapEntryId.GetHash(input); return(Encoding.UTF8.GetBytes(string.Format(CultureInfo.InvariantCulture, "{0}={1};{2}={3};{4}={5}", new object[] { "V", "1", "P", "IMAP", "FP", hash }))); }
List <WellKnownFolder> IMailbox.DiscoverWellKnownFolders(int flags) { List <WellKnownFolder> list = new List <WellKnownFolder>(); list.Add(new WellKnownFolder(3, ImapMailbox.IpmSubtreeEntryId)); foreach (ImapClientFolder imapClientFolder in this.folderCache.Values) { if (imapClientFolder.WellKnownFolderType != WellKnownFolderType.None) { WellKnownFolderType wellKnownFolderType = imapClientFolder.WellKnownFolderType; byte[] entryId = ImapEntryId.CreateFolderEntryId(imapClientFolder.Name); list.Add(new WellKnownFolder((int)wellKnownFolderType, entryId)); } } return(list); }
Stream ISupportMime.GetMimeStream(MessageRec message, out PropValueData[] extraPropValues) { extraPropValues = null; string messageUid = ImapEntryId.ParseUid(message.EntryId).ToString(CultureInfo.InvariantCulture); Stream result; ExDateTime?exDateTime; this.FetchMessage(messageUid, out result, out exDateTime); if (exDateTime != null) { extraPropValues = new PropValueData[] { new PropValueData(PropTag.MessageDeliveryTime, exDateTime.Value.ToUtc()) }; } return(result); }
private void EnumerateMessageDeletes(ImapFolderState currentState, ImapFolderState lastSyncedState, FolderChangesManifest changes, Dictionary <uint, MessageRec> lookup) { Action <uint> uidInclusionAction = delegate(uint uid) { MessageRec item = new MessageRec(ImapEntryId.CreateMessageEntryId(uid, this.Folder.UidValidity, this.Folder.Name, this.Mailbox.ImapConnection.ConnectionContext.UserName), this.FolderId, CommonUtils.DefaultLastModificationTime, 0, MsgRecFlags.Deleted, Array <PropValueData> .Empty); changes.ChangedMessages.Add(item); }; Action <uint> uidExclusionAction = delegate(uint uid) { MessageRec item = null; if (lookup.TryGetValue(uid, out item)) { changes.ChangedMessages.Add(item); } }; ImapFolderState.EnumerateMessageDeletes(currentState, lastSyncedState, uidInclusionAction, uidExclusionAction); }
public FolderRec CreateFolderRec(ImapClientFolder folder) { if (folder.Name.Equals(ImapMailbox.Root)) { return(new FolderRec(ImapMailbox.RootEntryId, null, FolderType.Root, string.Empty, DateTime.MinValue, null)); } if (folder.Name.Equals(ImapMailbox.IpmSubtree)) { return(new FolderRec(ImapMailbox.IpmSubtreeEntryId, ImapMailbox.RootEntryId, FolderType.Generic, "Top of Information Store", DateTime.MinValue, null)); } byte[] entryId = ImapEntryId.CreateFolderEntryId(folder.Name); string parentFolderPath = folder.ParentFolderPath; if (string.IsNullOrEmpty(parentFolderPath)) { return(new FolderRec(entryId, ImapMailbox.IpmSubtreeEntryId, FolderType.Generic, folder.ShortFolderName, DateTime.MinValue, null)); } return(new FolderRec(entryId, ImapEntryId.CreateFolderEntryId(parentFolderPath), FolderType.Generic, folder.ShortFolderName, DateTime.MinValue, null)); }
public static byte[] CreateMessageEntryId(uint uid, uint uidValidity, string folderPath, string logonName) { ImapEntryId.ValidateCreateEntryIdInput(folderPath); ImapEntryId.ValidateCreateEntryIdInput(logonName); string hash = ImapEntryId.GetHash(folderPath + logonName); return(Encoding.UTF8.GetBytes(string.Format(CultureInfo.InvariantCulture, "{0}={1};{2}={3};{4}={5};{6}={7};{8}={9}", new object[] { "V", "1", "P", "IMAP", "U", uid, "UV", uidValidity, "LF", hash }))); }
private void SetReadFlags(byte[] messageEntryId, byte[] folderEntryId, bool isRead) { base.CheckDisposed(); using (ImapFolder folder = base.GetFolder <ImapSourceFolder>(folderEntryId)) { if (folder == null) { MrsTracer.Provider.Warning("Source folder {0} doesn't exist", new object[] { TraceUtils.DumpBytes(folderEntryId) }); throw new ImapObjectNotFoundException(TraceUtils.DumpBytes(folderEntryId)); } uint item = ImapEntryId.ParseUid(messageEntryId); List <uint> list = new List <uint>(1); list.Add(item); List <ImapMessageRec> list2 = folder.Folder.LookupMessages(base.ImapConnection, list); if (list2.Count == 0) { MrsTracer.Provider.Warning("Source message {0} doesn't exist", new object[] { TraceUtils.DumpBytes(messageEntryId) }); throw new ImapObjectNotFoundException(TraceUtils.DumpBytes(messageEntryId)); } ImapMailFlags imapMailFlags = list2[0].ImapMailFlags; ImapMailFlags imapMailFlags2 = isRead ? (imapMailFlags | ImapMailFlags.Seen) : (imapMailFlags & ~ImapMailFlags.Seen); if (imapMailFlags != imapMailFlags2) { string text = item.ToString(CultureInfo.InvariantCulture); MrsTracer.Provider.Debug("StoreMessageFlags - uid: {0}, flagsToStore: {1}, previousFlags {2}", new object[] { text, imapMailFlags2, imapMailFlags }); base.ImapConnection.StoreMessageFlags(text, imapMailFlags2, imapMailFlags); } } }
private static Dictionary <string, string> ParseMessageEntryId(byte[] messageEntryId) { if (messageEntryId == null) { throw new ParsingMessageEntryIdFailedException(null, new ArgumentNullException("messageEntryId")); } string text = null; try { text = Encoding.UTF8.GetString(messageEntryId); } catch (Exception innerException) { throw new ParsingMessageEntryIdFailedException(TraceUtils.DumpBytes(messageEntryId), innerException); } string[] keyValuePairs = text.Split(new char[] { ';' }); return(ImapEntryId.ParseKeyValuePairs(messageEntryId, keyValuePairs)); }
internal static ImapFolderState Create(List <MessageRec> messages, int seqNumCrawl, uint uidNext, uint uidValidity) { if (messages.Count == 0) { return(new ImapFolderState { SeqNumCrawl = seqNumCrawl, UidNext = uidNext, UidValidity = uidValidity }); } Dictionary <uint, MessageRec> dictionary = new Dictionary <uint, MessageRec>(); foreach (MessageRec messageRec in messages) { uint key = ImapEntryId.ParseUid(messageRec.EntryId); dictionary.Add(key, messageRec); } GlobCountSet globCountSet = new GlobCountSet(); GlobCountSet globCountSet2 = new GlobCountSet(); for (uint num = uidNext - 1U; num > 0U; num -= 1U) { MessageRec messageRec2 = null; if (!dictionary.TryGetValue(num, out messageRec2)) { globCountSet2.Insert((ulong)num); } else { MessageFlags messageFlags = (MessageFlags)((int)messageRec2[PropTag.MessageFlags]); if (messageFlags.HasFlag(MessageFlags.Read)) { globCountSet.Insert((ulong)num); } } } return(new ImapFolderState(seqNumCrawl, uidNext, uidValidity, globCountSet, globCountSet2)); }
private List <MessageRec> GetMessageRecs(List <ImapMessageRec> imapMessageRecs) { if (imapMessageRecs.Count == 0) { return(new List <MessageRec>(0)); } List <MessageRec> list = new List <MessageRec>(imapMessageRecs.Count); foreach (ImapMessageRec imapMessageRec in imapMessageRecs) { SyncEmailContext syncEmailContext = ImapFolder.GetSyncEmailContext(this.Folder, imapMessageRec); int messageSize = 0; ImapExtendedMessageRec imapExtendedMessageRec = imapMessageRec as ImapExtendedMessageRec; if (imapExtendedMessageRec != null) { messageSize = (int)imapExtendedMessageRec.MessageSize; } PropValueData[] messageProps = SyncEmailUtils.GetMessageProps(syncEmailContext, this.Mailbox.ImapConnection.ConnectionContext.UserName, this.FolderId, new PropValueData[0]); MessageRec item = new MessageRec(ImapEntryId.CreateMessageEntryId(imapMessageRec.Uid, this.Folder.UidValidity, this.Folder.Name, this.Mailbox.ImapConnection.ConnectionContext.UserName), this.FolderId, CommonUtils.DefaultLastModificationTime, messageSize, MsgRecFlags.None, messageProps); list.Add(item); } return(list); }