Exemplo n.º 1
0
        public void TestEquals()
        {
            var r = new ImapPartialRange(0L, 1024L);

              Assert.IsTrue(r.Equals(r));
              Assert.IsTrue(r.Equals(new ImapPartialRange(0L, 1024L)));
              Assert.IsTrue((new ImapPartialRange(0L, 1024L)).Equals(r));

              Assert.IsFalse(r.Equals(0));
              Assert.IsFalse(r.Equals("<0.1024>"));
              Assert.IsFalse(r.Equals(new ImapPartialRange(1L, 1024L)));
              Assert.IsFalse(r.Equals(new ImapPartialRange(0L, 1023L)));
        }
        internal ImapWebClientFetchMessageBodyStream(ImapSession session,
                                                 bool keepAlive,
                                                 bool peek,
                                                 ImapSequenceSet fetchUidSet,
                                                 string fetchSection,
                                                 ImapPartialRange? fetchRange,
                                                 int fetchBlockSize,
                                                 int readWriteTimeout)
            : base(session, peek, fetchUidSet, fetchSection, fetchRange, fetchBlockSize)
        {
            this.keepAlive = keepAlive;

              ReadTimeout   = readWriteTimeout;
              WriteTimeout  = readWriteTimeout;
        }
Exemplo n.º 3
0
        public void TestConstruct()
        {
            ImapPartialRange r;

              r = new ImapPartialRange(0L);

              Assert.AreEqual(0L, r.Start);
              Assert.IsNull(r.Length);
              Assert.IsFalse(r.IsLengthSpecified);
              Assert.AreEqual("<0>", r.ToString());
              Assert.AreEqual("/;PARTIAL=0", r.ToString("u"));

              r = new ImapPartialRange(0L, 1024L);

              Assert.AreEqual(0L, r.Start);
              Assert.AreEqual(1024L, r.Length);
              Assert.IsTrue(r.IsLengthSpecified);
              Assert.AreEqual("<0.1024>", r.ToString());
              Assert.AreEqual("<0.1024>", r.ToString("f"));
              Assert.AreEqual("/;PARTIAL=0.1024", r.ToString("u"));

              r = new ImapPartialRange(0L, (long)0xffffffff);

              Assert.AreEqual(0L, r.Start);
              Assert.AreEqual(4294967295L, r.Length);
              Assert.IsTrue(r.IsLengthSpecified);
              Assert.AreEqual("<0.4294967295>", r.ToString());
              Assert.AreEqual("<0.4294967295>", r.ToString("f"));
              Assert.AreEqual("/;PARTIAL=0.4294967295", r.ToString("u"));

              r = new ImapPartialRange((long)0xfffffffe, 1L);

              Assert.AreEqual(4294967294L, r.Start);
              Assert.AreEqual(1L, r.Length);
              Assert.IsTrue(r.IsLengthSpecified);
              Assert.AreEqual("<4294967294.1>", r.ToString());
              Assert.AreEqual("<4294967294.1>", r.ToString("f"));
              Assert.AreEqual("/;PARTIAL=4294967294.1", r.ToString("u"));
        }
Exemplo n.º 4
0
        public void TestLengthOutOfRange()
        {
            foreach (var length in new[] {
            -1L, 0L, 0x100000000,
              }) {
            try {
              new ImapPartialRange(0L, length);

              Assert.Fail("ArgumentOutOfRangeException not thrown");
            }
            catch (ArgumentOutOfRangeException) {
            }

            try {
              var r = new ImapPartialRange(0L, length);

              r.Length = length;

              Assert.Fail("ArgumentOutOfRangeException not thrown");
            }
            catch (ArgumentOutOfRangeException) {
            }
              }
        }
Exemplo n.º 5
0
 // TODO: HEADER, HEADER.FIELDS, HEADER.FIELDS.NOT, MIME, and TEXT
 private static ImapFetchDataItem BodyTextInternal(bool peek, string section, ImapPartialRange? @partial)
 {
     if (@partial == null) {
     return new ImapFetchDataItem(string.Concat((peek ? "BODY.PEEK[" : "BODY["), section, "]"));
       }
       else {
     try {
       return new ImapFetchDataItem(string.Concat((peek ? "BODY.PEEK[" : "BODY["), section, "]", @partial.Value.ToString("f")));
     }
     catch (FormatException ex) {
       throw new ArgumentException(ex.Message, "partial");
     }
       }
 }
Exemplo n.º 6
0
        private static ImapFetchDataItem BinaryInternal(bool peek, string sectionBinary, ImapPartialRange? @partial)
        {
            if (string.IsNullOrEmpty(sectionBinary))
            throw new ArgumentException("must be non-empty value", "sectionBinary");

              if (@partial == null) {
            return new ImapFetchDataItem(ImapCapability.Binary, string.Concat((peek ? "BINARY.PEEK[" : "BINARY["), sectionBinary, "]"));
              }
              else {
            try {
              return new ImapFetchDataItem(ImapCapability.Binary,
                                       string.Concat((peek ? "BINARY.PEEK[" : "BINARY["), sectionBinary, "]", @partial.Value.ToString("f")));
            }
            catch (FormatException ex) {
              throw new ArgumentException(ex.Message, "partial");
            }
              }
        }
Exemplo n.º 7
0
 public static ImapFetchDataItem BodyText(bool peek, string section, ImapPartialRange? @partial)
 {
     return BodyTextInternal(peek, section, @partial);
 }
Exemplo n.º 8
0
 public static ImapFetchDataItem BodyText(bool peek, ImapPartialRange? @partial)
 {
     return BodyTextInternal(peek, null, @partial);
 }
Exemplo n.º 9
0
 public static ImapFetchDataItem BodyText(ImapPartialRange? @partial)
 {
     return BodyTextInternal(false, null, @partial);
 }
Exemplo n.º 10
0
 public static ImapFetchDataItem BodyPeek(string section, ImapPartialRange? @partial)
 {
     return BodyTextInternal(true, section, @partial);
 }
Exemplo n.º 11
0
 public static ImapFetchDataItem BinaryPeek(string sectionBinary, ImapPartialRange? @partial)
 {
     return BinaryInternal(true, sectionBinary, @partial);
 }
Exemplo n.º 12
0
 public static ImapFetchDataItem Binary(bool peek, string sectionBinary, ImapPartialRange? @partial)
 {
     return BinaryInternal(peek, sectionBinary, @partial);
 }
Exemplo n.º 13
0
        public void TestSetStartLength()
        {
            var r = new ImapPartialRange(0L);

              Assert.AreEqual(0L, r.Start);
              Assert.IsNull(r.Length);
              Assert.AreEqual("<0>", r.ToString());
              Assert.AreEqual("/;PARTIAL=0", r.ToString("u"));

              r.Start = 1024L;

              Assert.AreEqual(1024L, r.Start);
              Assert.IsNull(r.Length);
              Assert.AreEqual("<1024>", r.ToString());
              Assert.AreEqual("/;PARTIAL=1024", r.ToString("u"));

              r.Length = 1024L;

              Assert.AreEqual(1024L, r.Start);
              Assert.AreEqual(1024L, r.Length);
              Assert.AreEqual("<1024.1024>", r.ToString());
              Assert.AreEqual("<1024.1024>", r.ToString("f"));
              Assert.AreEqual("/;PARTIAL=1024.1024", r.ToString("u"));

              r.Start = 2048L;
              r.Length = null;

              Assert.AreEqual(2048L, r.Start);
              Assert.IsNull(r.Length);
              Assert.AreEqual("<2048>", r.ToString());
              Assert.AreEqual("/;PARTIAL=2048", r.ToString("u"));
        }
Exemplo n.º 14
0
        public void TestStartOutOfRange()
        {
            foreach (var start in new[] {
            -1L, 0x100000000,
              }) {
            try {
              new ImapPartialRange(start, 1L);

              Assert.Fail("ArgumentOutOfRangeException not thrown");
            }
            catch (ArgumentOutOfRangeException) {
            }

            try {
              var r = new ImapPartialRange(0L, 1L);

              r.Start = start;

              Assert.Fail("ArgumentOutOfRangeException not thrown");
            }
            catch (ArgumentOutOfRangeException) {
            }
              }
        }
Exemplo n.º 15
0
        public void TestStartLengthOutOfRange()
        {
            foreach (var pair in new[] {
            new {Start = 0L,                Length = (long)0x100000000},
            new {Start = 1L,                Length = (long)0x0ffffffff},
            new {Start = (long)0x0ffffffff, Length = 1L},
              }) {
            try {
              new ImapPartialRange(pair.Start, pair.Length);

              Assert.Fail("ArgumentOutOfRangeException not thrown");
            }
            catch (ArgumentOutOfRangeException) {
            }

            var r = new ImapPartialRange(0L, 1L);

            r.Start = pair.Start;

            try {
              r.Length = pair.Length;

              Assert.Fail("ArgumentOutOfRangeException not thrown");
            }
            catch (ArgumentOutOfRangeException) {
            }
              }
        }
        private ImapWebResponse GetPartialFetchResponse(ImapSequenceSet requestedUidSet, string section, ImapPartialRange? partial)
        {
            var responseStream = new ImapWebClientFetchMessageBodyStream(Session,
                                                                   KeepAlive,
                                                                   FetchPeek,
                                                                   requestedUidSet,
                                                                   section,
                                                                   partial,
                                                                   FetchBlockSize,
                                                                   ReadWriteTimeout);

              IImapMessageAttribute discard;
              var response = new ImapWebResponse(responseStream.Prepare(GetFetchDataItem(), out discard));

              if (response.Result.Failed)
            return response;

              response.SetResponseStream(responseStream,
                                 responseStream.Length,
                                 true);

              return response;
        }