Ejemplo n.º 1
0
        public void TestArgumentExceptions()
        {
            var buffer = new byte[1024];

            Assert.Throws <ArgumentNullException> (() => MimeUtils.GenerateMessageId(null), "MimeUtils.GenerateMessageId (null)");
            Assert.Throws <ArgumentException> (() => MimeUtils.GenerateMessageId(string.Empty), "MimeUtils.GenerateMessageId (string.Empty)");

            Assert.Throws <ArgumentNullException> (() => MimeUtils.EnumerateReferences(null), "MimeUtils.EnumerateReferences (null)");
            Assert.Throws <ArgumentNullException> (() => MimeUtils.EnumerateReferences(null, 0, 0).FirstOrDefault(), "MimeUtils.EnumerateReferences (null, 0, 0)");
            Assert.Throws <ArgumentOutOfRangeException> (() => MimeUtils.EnumerateReferences(buffer, -1, 0).FirstOrDefault(), "MimeUtils.EnumerateReferences (buffer, -1, 0)");
            Assert.Throws <ArgumentOutOfRangeException> (() => MimeUtils.EnumerateReferences(buffer, buffer.Length + 1, 0).FirstOrDefault(), "MimeUtils.EnumerateReferences (buffer, buffer.Length + 1, 0)");
            Assert.Throws <ArgumentOutOfRangeException> (() => MimeUtils.EnumerateReferences(buffer, 0, -1).FirstOrDefault(), "MimeUtils.EnumerateReferences (buffer, 0, -1)");
            Assert.Throws <ArgumentOutOfRangeException> (() => MimeUtils.EnumerateReferences(buffer, 0, buffer.Length + 1).FirstOrDefault(), "MimeUtils.EnumerateReferences (buffer, 0, buffer.Length + 1)");

            Assert.Throws <ArgumentNullException> (() => MimeUtils.ParseMessageId(null), "MimeUtils.ParseMessageId (null)");
            Assert.Throws <ArgumentNullException> (() => MimeUtils.ParseMessageId(null, 0, 0), "MimeUtils.ParseMessageId (null, 0, 0)");
            Assert.Throws <ArgumentOutOfRangeException> (() => MimeUtils.ParseMessageId(buffer, -1, 0), "MimeUtils.ParseMessageId (buffer, -1, 0)");
            Assert.Throws <ArgumentOutOfRangeException> (() => MimeUtils.ParseMessageId(buffer, buffer.Length + 1, 0), "MimeUtils.ParseMessageId (buffer, buffer.Length + 1, 0)");
            Assert.Throws <ArgumentOutOfRangeException> (() => MimeUtils.ParseMessageId(buffer, 0, -1), "MimeUtils.ParseMessageId (buffer, 0, -1)");
            Assert.Throws <ArgumentOutOfRangeException> (() => MimeUtils.ParseMessageId(buffer, 0, buffer.Length + 1), "MimeUtils.ParseMessageId (buffer, 0, buffer.Length + 1)");

            Assert.Throws <ArgumentNullException> (() => MimeUtils.AppendQuoted(null, "text"), "MimeUtils.AppendQuoted (null, value)");
            Assert.Throws <ArgumentNullException> (() => MimeUtils.AppendQuoted(new StringBuilder(), null), "MimeUtils.AppendQuoted (builder, null)");
            Assert.Throws <ArgumentNullException> (() => MimeUtils.Quote(null), "MimeUtils.Quote (null)");
            Assert.Throws <ArgumentNullException> (() => MimeUtils.Unquote(null), "MimeUtils.Unquote (null)");
        }
Ejemplo n.º 2
0
 static void EncodeGroup(StringBuilder builder, GroupAddress group)
 {
     builder.Append("(NIL NIL ");
     MimeUtils.AppendQuoted(builder, group.Name);
     builder.Append(" NIL)");
     EncodeInternetAddressListAddresses(builder, group.Members);
     builder.Append("(NIL NIL NIL NIL)");
 }
Ejemplo n.º 3
0
 internal static void Encode(StringBuilder builder, Uri location)
 {
     if (location != null)
     {
         MimeUtils.AppendQuoted(builder, location.ToString());
     }
     else
     {
         builder.Append("NIL");
     }
 }
Ejemplo n.º 4
0
 internal static void Encode(StringBuilder builder, string value)
 {
     if (value != null)
     {
         MimeUtils.AppendQuoted(builder, value);
     }
     else
     {
         builder.Append("NIL");
     }
 }
Ejemplo n.º 5
0
        static void EncodeMailbox(StringBuilder builder, MailboxAddress mailbox)
        {
            builder.Append('(');

            if (mailbox.Name != null)
            {
                MimeUtils.AppendQuoted(builder, mailbox.Name);
                builder.Append(' ');
            }
            else
            {
                builder.Append("NIL ");
            }

            if (mailbox.Route.Count != 0)
            {
                MimeUtils.AppendQuoted(builder, mailbox.Route.ToString());
                builder.Append(' ');
            }
            else
            {
                builder.Append("NIL ");
            }

            int at = mailbox.Address.LastIndexOf('@');

            if (at >= 0)
            {
                var domain = mailbox.Address.Substring(at + 1);
                var user   = mailbox.Address.Substring(0, at);

                MimeUtils.AppendQuoted(builder, user);
                builder.Append(' ');
                MimeUtils.AppendQuoted(builder, domain);
            }
            else
            {
                MimeUtils.AppendQuoted(builder, mailbox.Address);
                builder.Append(" \"localhost\"");
            }

            builder.Append(')');
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:MailKit.FolderNamespaceCollection"/>.
        /// </summary>
        /// <remarks>
        /// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:MailKit.FolderNamespaceCollection"/>.
        /// </remarks>
        /// <returns>A <see cref="T:System.String"/> that represents the current <see cref="T:MailKit.FolderNamespaceCollection"/>.</returns>
        public override string ToString()
        {
            var builder = new StringBuilder();

            builder.Append('(');
            for (int i = 0; i < namespaces.Count; i++)
            {
                builder.Append("(\"");
                if (Escape(namespaces[i].DirectorySeparator))
                {
                    builder.Append('\\');
                }
                builder.Append(namespaces[i].DirectorySeparator);
                builder.Append("\" ");
                MimeUtils.AppendQuoted(builder, namespaces[i].Path);
                builder.Append(")");
            }
            builder.Append(')');

            return(builder.ToString());
        }
Ejemplo n.º 7
0
        public byte[] Encode(Encoding encoding)
        {
            var builder = new StringBuilder();

            builder.Append("username="******",realm=\"{0}\"", Realm);
            builder.AppendFormat(",nonce=\"{0}\"", Nonce);
            builder.AppendFormat(",cnonce=\"{0}\"", CNonce);
            builder.AppendFormat(",nc={0:x8}", Nc);
            builder.AppendFormat(",qop=\"{0}\"", Qop);
            builder.AppendFormat(",digest-uri=\"{0}\"", DigestUri);
            builder.AppendFormat(",response={0}", Response);
            if (MaxBuf.HasValue)
            {
                builder.AppendFormat(CultureInfo.InvariantCulture, ",maxbuf={0}", MaxBuf.Value);
            }
            if (!string.IsNullOrEmpty(Charset))
            {
                builder.AppendFormat(",charset={0}", Charset);
            }
            if (!string.IsNullOrEmpty(Algorithm))
            {
                builder.AppendFormat(",algorithm={0}", Algorithm);
            }
            if (!string.IsNullOrEmpty(Cipher))
            {
                builder.AppendFormat(",cipher=\"{0}\"", Cipher);
            }
            if (!string.IsNullOrEmpty(AuthZid))
            {
                builder.AppendFormat(",authzid=\"{0}\"", AuthZid);
            }

            return(encoding.GetBytes(builder.ToString()));
        }
Ejemplo n.º 8
0
        internal void Encode(StringBuilder builder)
        {
            builder.Append('(');

            if (Date.HasValue)
            {
                builder.AppendFormat("\"{0}\" ", DateUtils.FormatDate(Date.Value));
            }
            else
            {
                builder.Append("NIL ");
            }

            if (Subject != null)
            {
                MimeUtils.AppendQuoted(builder, Subject);
                builder.Append(' ');
            }
            else
            {
                builder.Append("NIL ");
            }

            if (From.Count > 0)
            {
                EncodeAddressList(builder, From);
                builder.Append(' ');
            }
            else
            {
                builder.Append("NIL ");
            }

            if (Sender.Count > 0)
            {
                EncodeAddressList(builder, Sender);
                builder.Append(' ');
            }
            else
            {
                builder.Append("NIL ");
            }

            if (ReplyTo.Count > 0)
            {
                EncodeAddressList(builder, ReplyTo);
                builder.Append(' ');
            }
            else
            {
                builder.Append("NIL ");
            }

            if (To.Count > 0)
            {
                EncodeAddressList(builder, To);
                builder.Append(' ');
            }
            else
            {
                builder.Append("NIL ");
            }

            if (Cc.Count > 0)
            {
                EncodeAddressList(builder, Cc);
                builder.Append(' ');
            }
            else
            {
                builder.Append("NIL ");
            }

            if (Bcc.Count > 0)
            {
                EncodeAddressList(builder, Bcc);
                builder.Append(' ');
            }
            else
            {
                builder.Append("NIL ");
            }

            if (InReplyTo != null)
            {
                string inReplyTo;

                if (InReplyTo.Length > 1 && InReplyTo[0] != '<' && InReplyTo[InReplyTo.Length - 1] != '>')
                {
                    inReplyTo = '<' + InReplyTo + '>';
                }
                else
                {
                    inReplyTo = InReplyTo;
                }

                MimeUtils.AppendQuoted(builder, inReplyTo);
                builder.Append(' ');
            }
            else
            {
                builder.Append("NIL ");
            }

            if (MessageId != null)
            {
                string messageId;

                if (MessageId.Length > 1 && MessageId[0] != '<' && MessageId[MessageId.Length - 1] != '>')
                {
                    messageId = '<' + MessageId + '>';
                }
                else
                {
                    messageId = MessageId;
                }

                MimeUtils.AppendQuoted(builder, messageId);
            }
            else
            {
                builder.Append("NIL");
            }

            builder.Append(')');
        }