public void TestMixedNestedAlternative() { var summary = new MessageSummary(0) { Body = CreateMultipart("MULTIPART", "MIXED", "", CreateMultipart("MULTIPART", "ALTERNATIVE", "1", CreateMultipart("MULTIPART", "ALTERNATIVE", "1.1", CreateText("TEXT", "PLAIN", "1.1.1", false), CreateText("TEXT", "HTML", "1.1.2", false) ) ), CreateBasic("IMAGE", "JPEG", "2", true) ) }; var plain = summary.TextBody; Assert.NotNull(plain, "TextBody"); Assert.AreEqual("1.1.1", plain.ContentType.Parameters["part-specifier"], "TextBody"); var html = summary.HtmlBody; Assert.NotNull(html, "HtmlBody"); Assert.AreEqual("1.1.2", html.ContentType.Parameters["part-specifier"], "HtmlBody"); Assert.AreEqual(1, summary.Attachments.Count(), "Attachments"); Assert.AreEqual(3, summary.BodyParts.Count(), "BodyParts"); }
MessageSummary MakeThreadable(ref int index, string subject, string msgid, string date, string refs) { DateTimeOffset value; DateUtils.TryParse(date, out value); var summary = new MessageSummary(index++); summary.UniqueId = new UniqueId((uint)summary.Index); summary.Envelope = new Envelope(); summary.References = new MessageIdList(); if (refs != null) { foreach (var id in refs.Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries)) { summary.References.Add(id); } } summary.Envelope.MessageId = MimeUtils.EnumerateReferences(msgid).FirstOrDefault(); summary.Envelope.Subject = subject; summary.Envelope.Date = value; summary.Size = 0; return(summary); }
public Mail(MessageSummary Summary, MimeMessage message, string folderName) { if (message == null) { throw new System.ArgumentNullException(nameof(message)); } this.Folder = folderName; this.summary = Summary; this.ID = Summary.UniqueId; this.mimeMessage = message; this.Subject = message.Subject; this.SenderName = message.From[0].Name; this.SenderEmail = ((MailboxAddress)message.From[0]).Address; this.Date = summary.Date.DateTime; this.IsRead = summary.Flags.Value.HasFlag(MessageFlags.Seen); this.Body = message.HtmlBody; this.Attachments = new List <IFormFile>(); this.AttachmentFileNames = new List <string>(); foreach (var attachment in message.Attachments) { if (!(attachment is MessagePart)) { var part = (MimePart)attachment; AttachmentFileNames.Add(part.FileName); } } }
public MessageSummaryWindow(Window owner, MessageSummary messageSummary) { Owner = owner; MessageSummary = messageSummary; InitializeComponent(); }
public void TestArgumentExceptions() { var orderBy = new OrderBy[] { OrderBy.Arrival }; var messagesMissingInfo = new [] { new MessageSummary(0) }; var emptyOrderBy = new OrderBy[0]; int depth; var summary = new MessageSummary(0); summary.UniqueId = UniqueId.MinValue; summary.Envelope = new Envelope(); summary.References = new MessageIdList(); summary.Envelope.MessageId = "*****@*****.**"; summary.Envelope.Subject = "This is the subject"; summary.Envelope.Date = DateTimeOffset.Now; summary.Size = 0; var messages = new MessageSummary[] { summary }; Assert.Throws <ArgumentNullException> (() => MessageThreader.GetThreadableSubject(null, out depth)); Assert.Throws <ArgumentNullException> (() => MessageThreader.Thread((IEnumerable <MessageSummary>)null, ThreadingAlgorithm.References)); Assert.Throws <ArgumentNullException> (() => MessageThreader.Thread((IEnumerable <MessageSummary>)null, ThreadingAlgorithm.References, orderBy)); Assert.Throws <ArgumentException> (() => MessageThreader.Thread(messagesMissingInfo, ThreadingAlgorithm.References)); Assert.Throws <ArgumentNullException> (() => MessageThreader.Thread(messages, ThreadingAlgorithm.References, null)); Assert.Throws <ArgumentException> (() => MessageThreader.Thread(messages, ThreadingAlgorithm.References, emptyOrderBy)); }
public void TestDefaultValues() { var summary = new MessageSummary(17); Assert.AreEqual(0, summary.Attachments.Count(), "Attachments"); Assert.IsNull(summary.Body, "Body"); Assert.AreEqual(0, summary.BodyParts.Count(), "BodyParts"); Assert.AreEqual(DateTimeOffset.MinValue, summary.Date, "Date"); Assert.IsNull(summary.Envelope, "Envelope"); Assert.IsNull(summary.Flags, "Flags"); Assert.IsNull(summary.GMailLabels, "GMailLabels"); Assert.IsNull(summary.GMailMessageId, "GMailMessageId"); Assert.IsNull(summary.GMailThreadId, "GMailThreadId"); Assert.IsNull(summary.Headers, "Headers"); Assert.IsNull(summary.HtmlBody, "HtmlBody"); Assert.AreEqual(17, summary.Index, "Index"); Assert.IsNull(summary.InternalDate, "InternalDate"); Assert.IsFalse(summary.IsReply, "IsReply"); Assert.IsNull(summary.ModSeq, "ModSeq"); Assert.AreEqual(string.Empty, summary.NormalizedSubject, "NormalizedSubject"); Assert.IsNull(summary.PreviewText, "PreviewText"); Assert.IsNull(summary.References, "References"); Assert.IsNull(summary.Size, "Size"); Assert.IsNull(summary.TextBody, "TextBody"); Assert.AreEqual(UniqueId.Invalid, summary.UniqueId, "UniqueId"); Assert.IsNotNull(summary.UserFlags, "UserFlags"); Assert.AreEqual(0, summary.UserFlags.Count, "UserFlags"); }
/// <summary> /// Converts (parts of) MessageSummary to MailHeader /// </summary> /// <param name="msgSum"></param> /// <returns></returns> public static MailHeader ConvertMessageSummary(MessageSummary msgSum) { var mailHeader = new MailHeader(); mailHeader.Subject = msgSum.Envelope.Subject; InternetAddressList fromList = msgSum.Envelope.From; string fromString = ""; //For all InternetAddresses in InternetAddressList, add display name (if it exists) //to the fromString, otherwise add email address foreach (var from in fromList) { if (string.IsNullOrEmpty(from.Name)) { if (fromList.Count > 1) { fromString = from.ToString() + "," + fromString; } else { fromString = from.ToString(); } } else { if (fromList.Count > 1) { fromString = from.Name + "," + fromString; } else { fromString = from.Name; } } } mailHeader.From = fromString; string date = ""; //If the message´s date is today - set date string to Hour+Minute only. Otherwise set to full date&time if (msgSum.Date.Day == DateTimeOffset.Now.Day) { date = msgSum.Date.Hour + ":" + msgSum.Date.Minute; } else { string format = "yyyy-MM-dd HH:mm"; //Formats the date to swedish culture date = msgSum.Date.ToString(format, new CultureInfo("sv-SE")); } mailHeader.Date = date; mailHeader.UniqueId = msgSum.UniqueId; return(mailHeader); }
static List <MessageSummary> Create() { var messages = new List <MessageSummary> (); MessageSummary summary; summary = new MessageSummary(0); summary.Fields = MessageSummaryItems.Annotations | MessageSummaryItems.Envelope | MessageSummaryItems.Size | MessageSummaryItems.ModSeq; summary.Annotations = new List <Annotation> (new [] { new Annotation(AnnotationEntry.AltSubject) }); summary.Annotations[0].Properties.Add(AnnotationAttribute.SharedValue, "aaaa"); summary.Envelope = new Envelope(); summary.Envelope.Date = DateTimeOffset.Now.AddSeconds(-2); summary.Envelope.Subject = "aaaa"; summary.Envelope.From.Add(new MailboxAddress("A", "*****@*****.**")); summary.Envelope.To.Add(new MailboxAddress("A", "*****@*****.**")); summary.Envelope.Cc.Add(new MailboxAddress("A", "*****@*****.**")); summary.ModSeq = 80290; summary.Size = 520; messages.Add(summary); summary = new MessageSummary(1); summary.Fields = MessageSummaryItems.Annotations | MessageSummaryItems.Envelope | MessageSummaryItems.Size | MessageSummaryItems.ModSeq; summary.Annotations = new List <Annotation> (new [] { new Annotation(AnnotationEntry.AltSubject) }); summary.Annotations[0].Properties.Add(AnnotationAttribute.SharedValue, "bbbb"); summary.Envelope = new Envelope(); summary.Envelope.Date = DateTimeOffset.Now.AddSeconds(-1); summary.Envelope.Subject = "bbbb"; summary.Envelope.From.Add(new MailboxAddress("B", "*****@*****.**")); summary.Envelope.To.Add(new MailboxAddress("B", "*****@*****.**")); summary.Envelope.Cc.Add(new MailboxAddress("B", "*****@*****.**")); summary.ModSeq = 70642; summary.Size = 265; messages.Add(summary); summary = new MessageSummary(2); summary.Fields = MessageSummaryItems.Annotations | MessageSummaryItems.Envelope | MessageSummaryItems.Size | MessageSummaryItems.ModSeq; summary.Annotations = new List <Annotation> (new [] { new Annotation(AnnotationEntry.AltSubject) }); summary.Annotations[0].Properties.Add(AnnotationAttribute.SharedValue, "cccc"); summary.Envelope = new Envelope(); summary.Envelope.Date = DateTimeOffset.Now; summary.Envelope.Subject = "cccc"; summary.Envelope.From.Add(new MailboxAddress("C", "*****@*****.**")); summary.Envelope.To.Add(new MailboxAddress("C", "*****@*****.**")); summary.Envelope.Cc.Add(new MailboxAddress("C", "*****@*****.**")); summary.ModSeq = 80290; summary.Size = 520; messages.Add(summary); return(messages); }
public void TestMessageSummaryFetchedEventArgs() { var message = new MessageSummary(0); MessageSummaryFetchedEventArgs args; args = new MessageSummaryFetchedEventArgs(message); Assert.AreEqual(message, args.Message); Assert.Throws <ArgumentNullException> (() => new MessageSummaryFetchedEventArgs(null)); }
private void ValidateMetadata(MessageSummary email) { Assert.Equal(1, email.From.Count); Assert.Equal(1, email.To.Count); Assert.NotEmpty(email.From[0].Email); Assert.NotEmpty(email.From[0].Name); Assert.NotEmpty(email.To[0].Email); Assert.NotEmpty(email.To[0].Name); Assert.NotEmpty(email.Subject); Assert.Equal(DateTime.Now.ToString("yyyy-MM-dd"), email.Received.Value.ToString("yyyy-MM-dd")); }
public void TestComplexBody() { var summary = new MessageSummary(0) { Body = CreateMultipart("MULTIPART", "MIXED", "", CreateMultipart("MULTIPART", "ALTERNATIVE", "1", CreateText("TEXT", "PLAIN", "1.1", false), CreateMultipart("MULTIPART", "RELATED", "1.2", CreateText("TEXT", "HTML", "1.2.1", false), CreateBasic("IMAGE", "JPEG", "1.2.2", false) ) ), CreateBasic("APPLICATION", "OCTET-STREAM", "2", true), CreateMessage("MESSAGE", "RFC822", "3", CreateMultipart("MULTIPART", "MIXED", "3", CreateText("TEXT", "PLAIN", "3.1", false), CreateBasic("APPLICATION", "OCTET-STREAM", "3.2", true) ), true ), CreateBasic("IMAGE", "GIF", "4", true) ) }; int i; var plain = summary.TextBody; Assert.NotNull(plain, "TextBody"); Assert.AreEqual("1.1", plain.ContentType.Parameters["part-specifier"], "TextBody"); var html = summary.HtmlBody; Assert.NotNull(html, "HtmlBody"); Assert.AreEqual("1.2.1", html.ContentType.Parameters["part-specifier"], "HtmlBody"); var bodyParts = new string [] { "1.1", "1.2.1", "1.2.2", "2", "3", "4" }; i = 0; foreach (var part in summary.BodyParts) { Assert.AreEqual(bodyParts[i++], part.ContentType.Parameters["part-specifier"], "BodyParts"); } var attachments = new string[] { "2", "3", "4" }; i = 0; foreach (var attachment in summary.Attachments) { Assert.AreEqual(attachments[i++], attachment.ContentType.Parameters["part-specifier"], "Attachments"); } }
public void TestGMailProperties() { ulong msgid = 179111; ulong thrid = 7192564; var summary = new MessageSummary(0) { GMailLabels = new List <string> (), GMailMessageId = msgid, GMailThreadId = thrid }; Assert.AreEqual(0, summary.GMailLabels.Count, "GMailLabels"); Assert.AreEqual(msgid, summary.GMailMessageId, "GMailMessageId"); Assert.AreEqual(thrid, summary.GMailThreadId, "GMailThreadId"); }
private void sipService_onSubscriptionEvent(object sender, SubscriptionEventArgs e) { if (e.Type != SubscriptionEventTypes.INCOMING_NOTIFY || e.Content == null || (e.Package != MySubscriptionSession.EVENT_PACKAGE_TYPE.REG && e.Package != MySubscriptionSession.EVENT_PACKAGE_TYPE.WINFO && e.Package != MySubscriptionSession.EVENT_PACKAGE_TYPE.MESSAGE_SUMMARY) ) { return; } switch (e.Type) { case SubscriptionEventTypes.INCOMING_NOTIFY: { new Thread(delegate() { this.Dispatcher.Invoke((System.Threading.ThreadStart) delegate { if (e.Package == MySubscriptionSession.EVENT_PACKAGE_TYPE.REG) { this.ParseRegInfo(e.Content); } else if (e.Package == MySubscriptionSession.EVENT_PACKAGE_TYPE.WINFO) { this.ParseWatcherInfo(e.Content); } else if (e.Package == MySubscriptionSession.EVENT_PACKAGE_TYPE.MESSAGE_SUMMARY) { MessageSummary ms = MessageSummary.Parse(e.Content); if (ms != null) { //this.imageMailbox.Visibility = ms.HaveWaitingMessages ? System.Windows.Visibility.Visible : System.Windows.Visibility.Hidden; String tooltip = String.Format("Message-Account: {0}\n", ms.Account); new String[] { "Voice-Message", "Fax-Message", "Pager-Message", "Multimedia-Message", "Text-Message" }.ToList().ForEach(x => { tooltip += String.Format("{0}: {1}/{2} ({3}/{4})\n", x, ms.GetNewMessages(x), ms.GetOldMessages(x), ms.GetNewUrgentMessages(x), ms.GetOldUrgentMessages(x)); }); //this.imageMailbox.ToolTip = tooltip; } } }); }) .Start(); break; } } }
public static MessageItem ConvertToMessageItem(this IMessage msg) { var channel = (SocketGuildChannel)msg.Channel; var msgSum = new MessageSummary { MessageId = msg.Id, Author = msg.Author.Username, Content = msg.Content, Timestamp = msg.Timestamp.ToUnixTimeMilliseconds() }; var channelSum = new ChannelSummary { ChannelId = channel.Id, Name = channel.Name }; var guildSum = new GuildSummary { GuildId = channel.Guild.Id, Name = channel.Guild.Name }; return(new MessageItem { Channel = channelSum, Guild = guildSum, Message = msgSum }); }
public void Refresh(MessageSummary summary) { IsLoading = true; Subject = summary.Subject; IsRead = summary.IsRead; Importance = summary.Importance; HasAttachments = summary.HasAttachments; IsDraft = summary.IsDraft; IsFlagged = summary.IsFlagged; Sender = FormatRecipient(summary.Sender, true); CcRecipients = FormatRecipients(summary.CcRecipients); ToRecipients = FormatRecipients(summary.ToRecipients); ReceivedDateTime = summary.ReceivedDateTime; FormattedReceivedDateTime = FormatReceivedDateTime(summary.ReceivedDateTime); Body = ""; BodyType = ContentType.Html; LoadBody(); }
public void TestImageJpegBody() { var summary = new MessageSummary(0) { Body = CreateBasic("IMAGE", "JPEG", "1", false) }; var plain = summary.TextBody; Assert.IsNull(plain, "TextBody"); var html = summary.HtmlBody; Assert.IsNull(html, "HtmlBody"); Assert.AreEqual(0, summary.Attachments.Count(), "Attachments"); Assert.AreEqual(1, summary.BodyParts.Count(), "BodyParts"); }
public void TestTextHtmlBody() { var summary = new MessageSummary(0) { Body = CreateText("TEXT", "HTML", "1", false) }; var html = summary.HtmlBody; Assert.NotNull(html, "HtmlBody"); Assert.AreEqual("1", html.ContentType.Parameters["part-specifier"], "HtmlBody"); var plain = summary.TextBody; Assert.IsNull(plain, "TextBody"); Assert.AreEqual(0, summary.Attachments.Count(), "Attachments"); Assert.AreEqual(1, summary.BodyParts.Count(), "BodyParts"); }
static List <MessageSummary> Create() { var messages = new List <MessageSummary> (); MessageSummary summary; summary = new MessageSummary(0); summary.Fields = MessageSummaryItems.Envelope | MessageSummaryItems.Size | MessageSummaryItems.ModSeq; summary.Envelope = new Envelope(); summary.Envelope.Date = DateTimeOffset.Now.AddSeconds(-2); summary.Envelope.Subject = "aaaa"; summary.Envelope.From.Add(new MailboxAddress("A", "*****@*****.**")); summary.Envelope.To.Add(new MailboxAddress("A", "*****@*****.**")); summary.Envelope.Cc.Add(new MailboxAddress("A", "*****@*****.**")); summary.ModSeq = 80290; summary.Size = 520; messages.Add(summary); summary = new MessageSummary(1); summary.Fields = MessageSummaryItems.Envelope | MessageSummaryItems.Size | MessageSummaryItems.ModSeq; summary.Envelope = new Envelope(); summary.Envelope.Date = DateTimeOffset.Now.AddSeconds(-1); summary.Envelope.Subject = "bbbb"; summary.Envelope.From.Add(new MailboxAddress("B", "*****@*****.**")); summary.Envelope.To.Add(new MailboxAddress("B", "*****@*****.**")); summary.Envelope.Cc.Add(new MailboxAddress("B", "*****@*****.**")); summary.ModSeq = 70642; summary.Size = 265; messages.Add(summary); summary = new MessageSummary(2); summary.Fields = MessageSummaryItems.Envelope | MessageSummaryItems.Size | MessageSummaryItems.ModSeq; summary.Envelope = new Envelope(); summary.Envelope.Date = DateTimeOffset.Now; summary.Envelope.Subject = "cccc"; summary.Envelope.From.Add(new MailboxAddress("C", "*****@*****.**")); summary.Envelope.To.Add(new MailboxAddress("C", "*****@*****.**")); summary.Envelope.Cc.Add(new MailboxAddress("C", "*****@*****.**")); summary.ModSeq = 80290; summary.Size = 520; messages.Add(summary); return(messages); }
public void TestMultipartAlternativeNoTextParts() { var summary = new MessageSummary(0) { Body = CreateMultipart("MULTIPART", "ALTERNATIVE", "", CreateText("TEXT", "RICHTEXT", "1", false), CreateBasic("APPLICATION", "PDF", "2", false) ) }; var plain = summary.TextBody; Assert.IsNull(plain, "TextBody"); var html = summary.HtmlBody; Assert.IsNull(html, "HtmlBody"); Assert.AreEqual(0, summary.Attachments.Count(), "Attachments"); Assert.AreEqual(2, summary.BodyParts.Count(), "BodyParts"); }
public void TestRelatedTextHtmlBody() { var summary = new MessageSummary(0) { Body = CreateMultipart("MULTIPART", "RELATED", "", CreateText("TEXT", "HTML", "1", false), CreateBasic("IMAGE", "JPEG", "2", true) ) }; var plain = summary.TextBody; Assert.IsNull(plain, "TextBody"); var html = summary.HtmlBody; Assert.NotNull(html, "HtmlBody"); Assert.AreEqual("1", html.ContentType.Parameters ["part-specifier"], "HtmlBody"); Assert.AreEqual(1, summary.Attachments.Count(), "Attachments"); Assert.AreEqual(2, summary.BodyParts.Count(), "BodyParts"); }
// TODO: Check if message came from a channel registered as an AlertChannel or DMs, if not then ignore public async Task OnMessageReceived(SocketMessage msg) { var channel = (SocketGuildChannel)msg.Channel; var gSum = new GuildSummary { GuildId = channel.Guild.Id, Name = channel.Guild.Name }; var cSum = new ChannelSummary { ChannelId = channel.Id, Name = channel.Name }; var mSum = new MessageSummary { Author = msg.Author.Username, Content = msg.Content, MessageId = msg.Id, Timestamp = msg.Timestamp.ToUnixTimeMilliseconds() }; await _messageCache.StoreMessageAsync(new MessageItem { Guild = gSum, Channel = cSum, Message = mSum }); Console.WriteLine($"Guild Name: {channel.Guild.Name}, Channel Name: {channel.Name}"); Console.WriteLine($"{channel.Guild.Name.ToLower()}.{channel.Name.ToLower()} - {msg.Author.Username} ({msg.Timestamp.DateTime:g})"); Console.WriteLine(msg.Content); Console.WriteLine(); }
public void TestMixedRelatedAlternativeWithStartParameter() { var summary = new MessageSummary(0) { Body = CreateMultipart("MULTIPART", "MIXED", "", CreateMultipart("MULTIPART", "RELATED", "1", CreateBasic("IMAGE", "JPEG", "1.1", false), CreateMultipart("MULTIPART", "ALTERNATIVE", "1.2", CreateText("TEXT", "PLAIN", "1.2.1", false), CreateText("TEXT", "HTML", "1.2.2", false) ) ), CreateBasic("IMAGE", "JPEG", "2", true) ) }; var cid = "*****@*****.**"; var mixed = (BodyPartMultipart)summary.Body; var related = (BodyPartMultipart)mixed.BodyParts[0]; var alternative = (BodyPartMultipart)related.BodyParts[1]; related.ContentType.Parameters["start"] = cid; alternative.ContentLocation = new Uri("cid:" + cid); var plain = summary.TextBody; Assert.NotNull(plain, "TextBody"); Assert.AreEqual("1.2.1", plain.ContentType.Parameters["part-specifier"], "TextBody"); var html = summary.HtmlBody; Assert.NotNull(html, "HtmlBody"); Assert.AreEqual("1.2.2", html.ContentType.Parameters["part-specifier"], "HtmlBody"); Assert.AreEqual(1, summary.Attachments.Count(), "Attachments"); Assert.AreEqual(4, summary.BodyParts.Count(), "BodyParts"); }
void FetchSummaryItems (ImapEngine engine, ImapCommand ic, int index) { var token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.OpenParen) throw ImapEngine.UnexpectedToken (ImapEngine.GenericUntaggedResponseSyntaxErrorFormat, "FETCH", token); var ctx = (FetchSummaryContext) ic.UserData; IMessageSummary isummary; MessageSummary summary; if (!ctx.Results.TryGetValue (index, out isummary)) { summary = new MessageSummary (index); ctx.Results.Add (index, summary); } else { summary = (MessageSummary) isummary; } do { token = engine.ReadToken (ic.CancellationToken); if (token.Type == ImapTokenType.CloseParen || token.Type == ImapTokenType.Eoln) break; if (token.Type != ImapTokenType.Atom) throw ImapEngine.UnexpectedToken (ImapEngine.GenericUntaggedResponseSyntaxErrorFormat, "FETCH", token); var atom = (string) token.Value; string format; ulong value64; uint value; int idx; switch (atom) { case "INTERNALDATE": token = engine.ReadToken (ic.CancellationToken); switch (token.Type) { case ImapTokenType.QString: case ImapTokenType.Atom: summary.InternalDate = ImapUtils.ParseInternalDate ((string) token.Value); break; case ImapTokenType.Nil: summary.InternalDate = null; break; default: throw ImapEngine.UnexpectedToken (ImapEngine.GenericItemSyntaxErrorFormat, atom, token); } summary.Fields |= MessageSummaryItems.InternalDate; break; case "RFC822.SIZE": token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.Atom || !uint.TryParse ((string) token.Value, out value)) throw ImapEngine.UnexpectedToken (ImapEngine.GenericItemSyntaxErrorFormat, atom, token); summary.Fields |= MessageSummaryItems.MessageSize; summary.Size = value; break; case "BODYSTRUCTURE": format = string.Format (ImapEngine.GenericItemSyntaxErrorFormat, "BODYSTRUCTURE", "{0}"); summary.Body = ImapUtils.ParseBody (engine, format, string.Empty, ic.CancellationToken); summary.Fields |= MessageSummaryItems.BodyStructure; break; case "BODY": token = engine.PeekToken (ic.CancellationToken); if (token.Type == ImapTokenType.OpenBracket) { // consume the '[' token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.OpenBracket) throw ImapEngine.UnexpectedToken (ImapEngine.GenericItemSyntaxErrorFormat, atom, token); // References and/or other headers were requested... do { token = engine.ReadToken (ic.CancellationToken); if (token.Type == ImapTokenType.CloseBracket) break; if (token.Type == ImapTokenType.OpenParen) { do { token = engine.ReadToken (ic.CancellationToken); if (token.Type == ImapTokenType.CloseParen) break; // the header field names will generally be atoms or qstrings but may also be literals switch (token.Type) { case ImapTokenType.Literal: engine.ReadLiteral (ic.CancellationToken); break; case ImapTokenType.QString: case ImapTokenType.Atom: break; default: throw ImapEngine.UnexpectedToken (ImapEngine.GenericItemSyntaxErrorFormat, atom, token); } } while (true); } else if (token.Type != ImapTokenType.Atom) { throw ImapEngine.UnexpectedToken (ImapEngine.GenericItemSyntaxErrorFormat, atom, token); } } while (true); if (token.Type != ImapTokenType.CloseBracket) throw ImapEngine.UnexpectedToken (ImapEngine.GenericItemSyntaxErrorFormat, atom, token); token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.Literal) throw ImapEngine.UnexpectedToken (ImapEngine.GenericItemSyntaxErrorFormat, atom, token); summary.References = new MessageIdList (); try { summary.Headers = engine.ParseHeaders (engine.Stream, ic.CancellationToken); } catch (FormatException) { // consume any remaining literal data... ReadLiteralData (engine, ic.CancellationToken); summary.Headers = new HeaderList (); } if ((idx = summary.Headers.IndexOf (HeaderId.References)) != -1) { var references = summary.Headers[idx]; var rawValue = references.RawValue; foreach (var msgid in MimeUtils.EnumerateReferences (rawValue, 0, rawValue.Length)) summary.References.Add (msgid); } summary.Fields |= MessageSummaryItems.References; } else { summary.Fields |= MessageSummaryItems.Body; try { format = string.Format (ImapEngine.GenericItemSyntaxErrorFormat, "BODY", "{0}"); summary.Body = ImapUtils.ParseBody (engine, format, string.Empty, ic.CancellationToken); } catch (ImapProtocolException ex) { if (!ex.UnexpectedToken) throw; // Note: GMail's IMAP implementation sometimes replies with completely broken BODY values // (see issue #32 for the `BODY ("ALTERNATIVE")` example), so to work around this nonsense, // we need to drop the remainder of this line. do { token = engine.PeekToken (ic.CancellationToken); if (token.Type == ImapTokenType.Eoln) break; token = engine.ReadToken (ic.CancellationToken); if (token.Type == ImapTokenType.Literal) ReadLiteralData (engine, ic.CancellationToken); } while (true); return; } } break; case "ENVELOPE": summary.Envelope = ImapUtils.ParseEnvelope (engine, ic.CancellationToken); summary.Fields |= MessageSummaryItems.Envelope; break; case "FLAGS": summary.Flags = ImapUtils.ParseFlagsList (engine, atom, summary.UserFlags, ic.CancellationToken); summary.Fields |= MessageSummaryItems.Flags; break; case "MODSEQ": token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.OpenParen) throw ImapEngine.UnexpectedToken (ImapEngine.GenericItemSyntaxErrorFormat, atom, token); token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.Atom || !ulong.TryParse ((string) token.Value, out value64)) throw ImapEngine.UnexpectedToken (ImapEngine.GenericItemSyntaxErrorFormat, atom, token); token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.CloseParen) throw ImapEngine.UnexpectedToken (ImapEngine.GenericItemSyntaxErrorFormat, atom, token); summary.Fields |= MessageSummaryItems.ModSeq; summary.ModSeq = value64; break; case "UID": token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.Atom || !uint.TryParse ((string) token.Value, out value) || value == 0) throw ImapEngine.UnexpectedToken (ImapEngine.GenericItemSyntaxErrorFormat, atom, token); summary.UniqueId = new UniqueId (ic.Folder.UidValidity, value); summary.Fields |= MessageSummaryItems.UniqueId; break; case "X-GM-MSGID": token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.Atom || !ulong.TryParse ((string) token.Value, out value64) || value64 == 0) throw ImapEngine.UnexpectedToken (ImapEngine.GenericItemSyntaxErrorFormat, atom, token); summary.Fields |= MessageSummaryItems.GMailMessageId; summary.GMailMessageId = value64; break; case "X-GM-THRID": token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.Atom || !ulong.TryParse ((string) token.Value, out value64) || value64 == 0) throw ImapEngine.UnexpectedToken (ImapEngine.GenericItemSyntaxErrorFormat, atom, token); summary.Fields |= MessageSummaryItems.GMailThreadId; summary.GMailThreadId = value64; break; case "X-GM-LABELS": summary.GMailLabels = ImapUtils.ParseLabelsList (engine, ic.CancellationToken); summary.Fields |= MessageSummaryItems.GMailLabels; break; default: throw ImapEngine.UnexpectedToken (ImapEngine.GenericUntaggedResponseSyntaxErrorFormat, "FETCH", token); } } while (true); if (token.Type != ImapTokenType.CloseParen) throw ImapEngine.UnexpectedToken (ImapEngine.GenericUntaggedResponseSyntaxErrorFormat, "FETCH", token); if ((ctx.RequestedItems & summary.Fields) == ctx.RequestedItems) OnMessageSummaryFetched (summary); }
public MessageSummaryArgs(IPhoneLine phoneLine, MessageSummary messageSummary) { PhoneLine = phoneLine; MessageSummary = messageSummary; }
private void ValidateEmailSummary(MessageSummary email) { ValidateMetadata(email); Assert.Equal(2, email.Attachments); }
public void TestSorting() { var messages = new List <MessageSummary> (); MessageSummary summary; summary = new MessageSummary(0); summary.Envelope = new Envelope(); summary.Envelope.Date = DateTimeOffset.Now.AddSeconds(-2); summary.Envelope.Subject = "aaaa"; summary.Envelope.From.Add(new MailboxAddress("A", "*****@*****.**")); summary.Envelope.To.Add(new MailboxAddress("A", "*****@*****.**")); summary.Envelope.Cc.Add(new MailboxAddress("A", "*****@*****.**")); summary.Size = 520; messages.Add(summary); summary = new MessageSummary(1); summary.Envelope = new Envelope(); summary.Envelope.Date = DateTimeOffset.Now.AddSeconds(-1); summary.Envelope.Subject = "bbbb"; summary.Envelope.From.Add(new MailboxAddress("B", "*****@*****.**")); summary.Envelope.To.Add(new MailboxAddress("B", "*****@*****.**")); summary.Envelope.Cc.Add(new MailboxAddress("B", "*****@*****.**")); summary.Size = 265; messages.Add(summary); summary = new MessageSummary(2); summary.Envelope = new Envelope(); summary.Envelope.Date = DateTimeOffset.Now; summary.Envelope.Subject = "cccc"; summary.Envelope.From.Add(new MailboxAddress("C", "*****@*****.**")); summary.Envelope.To.Add(new MailboxAddress("C", "*****@*****.**")); summary.Envelope.Cc.Add(new MailboxAddress("C", "*****@*****.**")); summary.Size = 520; messages.Add(summary); messages.Sort(new[] { OrderBy.Arrival }); Assert.AreEqual(0, messages[0].Index, "Sorting by arrival failed."); Assert.AreEqual(1, messages[1].Index, "Sorting by arrival failed."); Assert.AreEqual(2, messages[2].Index, "Sorting by arrival failed."); messages.Sort(new [] { OrderBy.ReverseArrival }); Assert.AreEqual(2, messages[0].Index, "Sorting by reverse arrival failed."); Assert.AreEqual(1, messages[1].Index, "Sorting by reverse arrival failed."); Assert.AreEqual(0, messages[2].Index, "Sorting by reverse arrival failed."); messages.Sort(new [] { OrderBy.Subject }); Assert.AreEqual(0, messages[0].Index, "Sorting by subject failed."); Assert.AreEqual(1, messages[1].Index, "Sorting by subject failed."); Assert.AreEqual(2, messages[2].Index, "Sorting by subject failed."); messages.Sort(new [] { OrderBy.ReverseSubject }); Assert.AreEqual(2, messages[0].Index, "Sorting by reverse subject failed."); Assert.AreEqual(1, messages[1].Index, "Sorting by reverse subject failed."); Assert.AreEqual(0, messages[2].Index, "Sorting by reverse subject failed."); messages.Sort(new [] { OrderBy.Size, OrderBy.Arrival }); Assert.AreEqual(1, messages[0].Index, "Sorting by size failed."); Assert.AreEqual(0, messages[1].Index, "Sorting by size failed."); Assert.AreEqual(2, messages[2].Index, "Sorting by size failed."); messages.Sort(new [] { OrderBy.Date }); Assert.AreEqual(0, messages[0].Index, "Sorting by date failed."); Assert.AreEqual(1, messages[1].Index, "Sorting by date failed."); Assert.AreEqual(2, messages[2].Index, "Sorting by date failed."); messages.Sort(new [] { OrderBy.Size, OrderBy.Subject }); Assert.AreEqual(1, messages[0].Index, "Sorting by size+subject failed."); Assert.AreEqual(0, messages[1].Index, "Sorting by size+subject failed."); Assert.AreEqual(2, messages[2].Index, "Sorting by size+subject failed."); messages.Sort(new [] { OrderBy.ReverseSize, OrderBy.ReverseSubject }); Assert.AreEqual(2, messages[0].Index, "Sorting by reversed size+subject failed."); Assert.AreEqual(0, messages[1].Index, "Sorting by reversed size+subject failed."); Assert.AreEqual(1, messages[2].Index, "Sorting by reversed size+subject failed."); messages.Sort(new[] { OrderBy.DisplayFrom }); Assert.AreEqual(0, messages[0].Index, "Sorting by display-from failed."); Assert.AreEqual(1, messages[1].Index, "Sorting by display-from failed."); Assert.AreEqual(2, messages[2].Index, "Sorting by display-from failed."); messages.Sort(new[] { OrderBy.From }); Assert.AreEqual(0, messages[0].Index, "Sorting by from failed."); Assert.AreEqual(1, messages[1].Index, "Sorting by from failed."); Assert.AreEqual(2, messages[2].Index, "Sorting by from failed."); messages.Sort(new[] { OrderBy.DisplayTo }); Assert.AreEqual(0, messages[0].Index, "Sorting by display-to failed."); Assert.AreEqual(1, messages[1].Index, "Sorting by display-to failed."); Assert.AreEqual(2, messages[2].Index, "Sorting by display-to failed."); messages.Sort(new[] { OrderBy.To }); Assert.AreEqual(0, messages[0].Index, "Sorting by to failed."); Assert.AreEqual(1, messages[1].Index, "Sorting by to failed."); Assert.AreEqual(2, messages[2].Index, "Sorting by to failed."); messages.Sort(new[] { OrderBy.Cc }); Assert.AreEqual(0, messages[0].Index, "Sorting by cc failed."); Assert.AreEqual(1, messages[1].Index, "Sorting by cc failed."); Assert.AreEqual(2, messages[2].Index, "Sorting by cc failed."); }
static void FetchSummaryItems(ImapEngine engine, ImapCommand ic, int index, ImapToken tok) { var token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.OpenParen) throw ImapEngine.UnexpectedToken (token, false); var results = (SortedDictionary<int, MessageSummary>) ic.UserData; MessageSummary summary; if (!results.TryGetValue (index, out summary)) { summary = new MessageSummary (index); results.Add (index, summary); } do { token = engine.ReadToken (ic.CancellationToken); if (token.Type == ImapTokenType.CloseParen || token.Type == ImapTokenType.Eoln) break; if (token.Type != ImapTokenType.Atom) throw ImapEngine.UnexpectedToken (token, false); var atom = (string) token.Value; ulong value64; uint value; switch (atom) { case "INTERNALDATE": token = engine.ReadToken (ic.CancellationToken); switch (token.Type) { case ImapTokenType.QString: case ImapTokenType.Atom: summary.InternalDate = ImapUtils.ParseInternalDate ((string) token.Value); break; case ImapTokenType.Nil: summary.InternalDate = null; break; default: throw ImapEngine.UnexpectedToken (token, false); } break; case "RFC822.SIZE": token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.Atom || !uint.TryParse ((string) token.Value, out value) || value == 0) throw ImapEngine.UnexpectedToken (token, false); summary.MessageSize = value; break; case "BODYSTRUCTURE": case "BODY": summary.Body = ImapUtils.ParseBody (engine, string.Empty, ic.CancellationToken); break; case "ENVELOPE": summary.Envelope = ImapUtils.ParseEnvelope (engine, ic.CancellationToken); break; case "FLAGS": summary.Flags = ImapUtils.ParseFlagsList (engine, ic.CancellationToken); break; case "MODSEQ": token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.OpenParen) throw ImapEngine.UnexpectedToken (token, false); token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.Atom || !ulong.TryParse ((string) token.Value, out value64) || value64 == 0) throw ImapEngine.UnexpectedToken (token, false); token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.CloseParen) throw ImapEngine.UnexpectedToken (token, false); summary.ModSeq = value64; break; case "UID": token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.Atom || !uint.TryParse ((string) token.Value, out value) || value == 0) throw ImapEngine.UnexpectedToken (token, false); summary.Uid = new UniqueId (value); break; case "X-GM-MSGID": token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.Atom || !ulong.TryParse ((string) token.Value, out value64) || value64 == 0) throw ImapEngine.UnexpectedToken (token, false); summary.GMailMessageId = value64; break; case "X-GM-THRID": token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.Atom || !ulong.TryParse ((string) token.Value, out value64) || value64 == 0) throw ImapEngine.UnexpectedToken (token, false); summary.GMailThreadId = value64; break; default: throw ImapEngine.UnexpectedToken (token, false); } } while (true); if (token.Type != ImapTokenType.CloseParen) throw ImapEngine.UnexpectedToken (token, false); }
public void TestSorting() { var messages = new List <MessageSummary> (); IList <MessageSummary> sorted; MessageSummary summary; summary = new MessageSummary(0); summary.Envelope = new Envelope(); summary.Envelope.Date = DateTimeOffset.Now; summary.Envelope.Subject = "aaaa"; summary.Envelope.From = InternetAddressList.Parse("Jeffrey Stedfast <*****@*****.**>"); summary.Envelope.To = InternetAddressList.Parse("Jeffrey Stedfast <*****@*****.**>"); summary.Envelope.Cc = new InternetAddressList(); summary.MessageSize = 520; messages.Add(summary); summary = new MessageSummary(1); summary.Envelope = new Envelope(); summary.Envelope.Date = DateTimeOffset.Now; summary.Envelope.Subject = "bbbb"; summary.Envelope.From = InternetAddressList.Parse("Jeffrey Stedfast <*****@*****.**>"); summary.Envelope.To = InternetAddressList.Parse("Jeffrey Stedfast <*****@*****.**>"); summary.Envelope.Cc = new InternetAddressList(); summary.MessageSize = 265; messages.Add(summary); summary = new MessageSummary(2); summary.Envelope = new Envelope(); summary.Envelope.Date = DateTimeOffset.Now; summary.Envelope.Subject = "cccc"; summary.Envelope.From = InternetAddressList.Parse("Jeffrey Stedfast <*****@*****.**>"); summary.Envelope.To = InternetAddressList.Parse("Jeffrey Stedfast <*****@*****.**>"); summary.Envelope.Cc = new InternetAddressList(); summary.MessageSize = 520; messages.Add(summary); sorted = MessageSorter.Sort(messages, new [] { OrderBy.Arrival }); Assert.AreEqual(0, sorted[0].Index, "Sorting by arrival failed."); Assert.AreEqual(1, sorted[1].Index, "Sorting by arrival failed."); Assert.AreEqual(2, sorted[2].Index, "Sorting by arrival failed."); sorted = MessageSorter.Sort(messages, new [] { OrderBy.ReverseArrival }); Assert.AreEqual(2, sorted[0].Index, "Sorting by reverse arrival failed."); Assert.AreEqual(1, sorted[1].Index, "Sorting by reverse arrival failed."); Assert.AreEqual(0, sorted[2].Index, "Sorting by reverse arrival failed."); sorted = MessageSorter.Sort(messages, new [] { OrderBy.Subject }); Assert.AreEqual(0, sorted[0].Index, "Sorting by subject failed."); Assert.AreEqual(1, sorted[1].Index, "Sorting by subject failed."); Assert.AreEqual(2, sorted[2].Index, "Sorting by subject failed."); sorted = MessageSorter.Sort(messages, new [] { OrderBy.ReverseSubject }); Assert.AreEqual(2, sorted[0].Index, "Sorting by reverse subject failed."); Assert.AreEqual(1, sorted[1].Index, "Sorting by reverse subject failed."); Assert.AreEqual(0, sorted[2].Index, "Sorting by reverse subject failed."); sorted = MessageSorter.Sort(messages, new [] { OrderBy.Size }); Assert.AreEqual(1, sorted[0].Index, "Sorting by size failed."); sorted = MessageSorter.Sort(messages, new [] { OrderBy.Size, OrderBy.Subject }); Assert.AreEqual(1, sorted[0].Index, "Sorting by size+subject failed."); Assert.AreEqual(0, sorted[1].Index, "Sorting by size+subject failed."); Assert.AreEqual(2, sorted[2].Index, "Sorting by size+subject failed."); sorted = MessageSorter.Sort(messages, new [] { OrderBy.ReverseSize, OrderBy.ReverseSubject }); Assert.AreEqual(2, sorted[0].Index, "Sorting by size+subject failed."); Assert.AreEqual(0, sorted[1].Index, "Sorting by size+subject failed."); Assert.AreEqual(1, sorted[2].Index, "Sorting by size+subject failed."); }
static void FetchSummaryItems(ImapEngine engine, ImapCommand ic, int index, ImapToken tok) { var token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.OpenParen) throw ImapEngine.UnexpectedToken (token, false); var results = (SortedDictionary<int, MessageSummary>) ic.UserData; MessageSummary summary; if (!results.TryGetValue (index, out summary)) { summary = new MessageSummary (index); results.Add (index, summary); } do { token = engine.ReadToken (ic.CancellationToken); if (token.Type == ImapTokenType.CloseParen || token.Type == ImapTokenType.Eoln) break; if (token.Type != ImapTokenType.Atom) throw ImapEngine.UnexpectedToken (token, false); var atom = (string) token.Value; ulong value64; uint value; switch (atom) { case "INTERNALDATE": token = engine.ReadToken (ic.CancellationToken); switch (token.Type) { case ImapTokenType.QString: case ImapTokenType.Atom: summary.InternalDate = ImapUtils.ParseInternalDate ((string) token.Value); break; case ImapTokenType.Nil: summary.InternalDate = null; break; default: throw ImapEngine.UnexpectedToken (token, false); } break; case "RFC822.SIZE": token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.Atom || !uint.TryParse ((string) token.Value, out value)) throw ImapEngine.UnexpectedToken (token, false); summary.MessageSize = value; break; case "BODYSTRUCTURE": summary.Body = ImapUtils.ParseBody (engine, string.Empty, ic.CancellationToken); break; case "BODY": token = engine.PeekToken (ic.CancellationToken); if (token.Type == ImapTokenType.OpenBracket) { // consume the '[' token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.OpenBracket) throw ImapEngine.UnexpectedToken (token, false); // References were requested... do { token = engine.ReadToken (ic.CancellationToken); if (token.Type == ImapTokenType.CloseBracket) break; if (token.Type == ImapTokenType.OpenParen) { do { token = engine.ReadToken (ic.CancellationToken); if (token.Type == ImapTokenType.CloseParen) break; if (token.Type != ImapTokenType.Atom) throw ImapEngine.UnexpectedToken (token, false); } while (true); } else if (token.Type != ImapTokenType.Atom) { throw ImapEngine.UnexpectedToken (token, false); } } while (true); if (token.Type != ImapTokenType.CloseBracket) throw ImapEngine.UnexpectedToken (token, false); token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.Literal) throw ImapEngine.UnexpectedToken (token, false); var message = MimeMessage.Load (engine.Stream, ic.CancellationToken); summary.References = message.References; } else { summary.Body = ImapUtils.ParseBody (engine, string.Empty, ic.CancellationToken); } break; case "ENVELOPE": summary.Envelope = ImapUtils.ParseEnvelope (engine, ic.CancellationToken); break; case "FLAGS": summary.Flags = ImapUtils.ParseFlagsList (engine, ic.CancellationToken); break; case "MODSEQ": token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.OpenParen) throw ImapEngine.UnexpectedToken (token, false); token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.Atom || !ulong.TryParse ((string) token.Value, out value64) || value64 == 0) throw ImapEngine.UnexpectedToken (token, false); token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.CloseParen) throw ImapEngine.UnexpectedToken (token, false); summary.ModSeq = value64; break; case "UID": token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.Atom || !uint.TryParse ((string) token.Value, out value) || value == 0) throw ImapEngine.UnexpectedToken (token, false); summary.UniqueId = new UniqueId (value); break; case "X-GM-MSGID": token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.Atom || !ulong.TryParse ((string) token.Value, out value64) || value64 == 0) throw ImapEngine.UnexpectedToken (token, false); summary.GMailMessageId = value64; break; case "X-GM-THRID": token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.Atom || !ulong.TryParse ((string) token.Value, out value64) || value64 == 0) throw ImapEngine.UnexpectedToken (token, false); summary.GMailThreadId = value64; break; case "X-GM-LABELS": token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.OpenParen) throw ImapEngine.UnexpectedToken (token, false); token = engine.ReadToken (ic.CancellationToken); summary.GMailLabels = new List<string> (); while (token.Type == ImapTokenType.Flag || token.Type == ImapTokenType.Atom || token.Type == ImapTokenType.QString) { var label = ImapEncoding.Decode ((string) token.Value); summary.GMailLabels.Add (label); token = engine.ReadToken (ic.CancellationToken); } if (token.Type != ImapTokenType.CloseParen) throw ImapEngine.UnexpectedToken (token, false); break; default: throw ImapEngine.UnexpectedToken (token, false); } } while (true); if (token.Type != ImapTokenType.CloseParen) throw ImapEngine.UnexpectedToken (token, false); }
static void FetchSummaryItems(ImapEngine engine, ImapCommand ic, int index) { var token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.OpenParen) throw ImapEngine.UnexpectedToken (token, false); var results = (SortedDictionary<int, IMessageSummary>) ic.UserData; IMessageSummary isummary; MessageSummary summary; if (!results.TryGetValue (index, out isummary)) { summary = new MessageSummary (index); results.Add (index, summary); } else { summary = (MessageSummary) isummary; } do { token = engine.ReadToken (ic.CancellationToken); if (token.Type == ImapTokenType.CloseParen || token.Type == ImapTokenType.Eoln) break; if (token.Type != ImapTokenType.Atom) throw ImapEngine.UnexpectedToken (token, false); var atom = (string) token.Value; ulong value64; uint value; switch (atom) { case "INTERNALDATE": token = engine.ReadToken (ic.CancellationToken); switch (token.Type) { case ImapTokenType.QString: case ImapTokenType.Atom: summary.InternalDate = ImapUtils.ParseInternalDate ((string) token.Value); break; case ImapTokenType.Nil: summary.InternalDate = null; break; default: throw ImapEngine.UnexpectedToken (token, false); } break; case "RFC822.SIZE": token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.Atom || !uint.TryParse ((string) token.Value, out value)) throw ImapEngine.UnexpectedToken (token, false); summary.MessageSize = value; break; case "BODYSTRUCTURE": summary.Body = ImapUtils.ParseBody (engine, string.Empty, ic.CancellationToken); break; case "BODY": token = engine.PeekToken (ic.CancellationToken); if (token.Type == ImapTokenType.OpenBracket) { // consume the '[' token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.OpenBracket) throw ImapEngine.UnexpectedToken (token, false); // References were requested... do { token = engine.ReadToken (ic.CancellationToken); if (token.Type == ImapTokenType.CloseBracket) break; if (token.Type == ImapTokenType.OpenParen) { do { token = engine.ReadToken (ic.CancellationToken); if (token.Type == ImapTokenType.CloseParen) break; if (token.Type != ImapTokenType.Atom) throw ImapEngine.UnexpectedToken (token, false); } while (true); } else if (token.Type != ImapTokenType.Atom) { throw ImapEngine.UnexpectedToken (token, false); } } while (true); if (token.Type != ImapTokenType.CloseBracket) throw ImapEngine.UnexpectedToken (token, false); token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.Literal) throw ImapEngine.UnexpectedToken (token, false); try { var message = engine.ParseMessage (engine.Stream, false, ic.CancellationToken); summary.References = message.References; summary.Headers = message.Headers; } catch (FormatException) { // consume any remaining literal data... ReadLiteralData (engine, ic.CancellationToken); } } else { try { summary.Body = ImapUtils.ParseBody (engine, string.Empty, ic.CancellationToken); } catch (ImapProtocolException ex) { if (!ex.UnexpectedToken) throw; // Note: GMail's IMAP implementation sometimes replies with completely broken BODY values // (see issue #32 for examples), so to work around this nonsense, we need to drop the // remainder of this line. do { token = engine.PeekToken (ic.CancellationToken); if (token.Type == ImapTokenType.Eoln) break; token = engine.ReadToken (ic.CancellationToken); if (token.Type == ImapTokenType.Literal) ReadLiteralData (engine, ic.CancellationToken); } while (true); return; } } break; case "ENVELOPE": summary.Envelope = ImapUtils.ParseEnvelope (engine, ic.CancellationToken); break; case "FLAGS": summary.Flags = ImapUtils.ParseFlagsList (engine, summary.UserFlags, ic.CancellationToken); break; case "MODSEQ": token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.OpenParen) throw ImapEngine.UnexpectedToken (token, false); token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.Atom || !ulong.TryParse ((string) token.Value, out value64) || value64 == 0) throw ImapEngine.UnexpectedToken (token, false); token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.CloseParen) throw ImapEngine.UnexpectedToken (token, false); summary.ModSeq = value64; break; case "UID": token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.Atom || !uint.TryParse ((string) token.Value, out value) || value == 0) throw ImapEngine.UnexpectedToken (token, false); summary.UniqueId = new UniqueId (value); break; case "X-GM-MSGID": token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.Atom || !ulong.TryParse ((string) token.Value, out value64) || value64 == 0) throw ImapEngine.UnexpectedToken (token, false); summary.GMailMessageId = value64; break; case "X-GM-THRID": token = engine.ReadToken (ic.CancellationToken); if (token.Type != ImapTokenType.Atom || !ulong.TryParse ((string) token.Value, out value64) || value64 == 0) throw ImapEngine.UnexpectedToken (token, false); summary.GMailThreadId = value64; break; case "X-GM-LABELS": summary.GMailLabels = ImapUtils.ParseLabelsList (engine, ic.CancellationToken); break; default: throw ImapEngine.UnexpectedToken (token, false); } } while (true); if (token.Type != ImapTokenType.CloseParen) throw ImapEngine.UnexpectedToken (token, false); }
public SimplifiedMessageSummary(MessageSummary summary, IMailFolder folder) { messageSummary = summary; Folder = folder; }
public MessageDetailViewModel(MessageSummary summary, IProfileDataQueryFactory queryFactory) { _id = summary.Id; _queryFactory = queryFactory; Refresh(summary); }