Beispiel #1
0
		public void MessageToMIME822() {
			MailAddress from = new MailAddress("*****@*****.**", "田中純"),
				to = new MailAddress("*****@*****.**", "山田太郎");
			string cc_one = "*****@*****.**", cc_two = "*****@*****.**",
				subject = "大学のプレゼンテーション・秋2011",
				body = "第1大学は初期雇用契約導入(2006年)や大統領ニコラ・" +
				"サルコジの改革方針(2007年)に反対するバリケードストライキが行" +
				"なわれるなど、21世紀に入っても学生運動が盛ん、且つその拠点とさ" +
				"れる大学である。";
			// Create a simple mail message
			MailMessage m = new MailMessage(from, to);
			m.CC.Add(cc_one);
			m.CC.Add(cc_two);
			m.Subject = subject;
			m.Priority = MailPriority.Low;
			m.Body = body;

			string mime822 = m.ToMIME822();

			// Reconstruct MailMessage from text and verify all fields contain
			// the same values.
			MailMessage r = MessageBuilder.FromMIME822(mime822);

			Assert.AreEqual<MailAddress>(from, r.From);
			Assert.AreEqual<MailAddress>(to, r.To.First());
			Assert.AreEqual<string>(cc_one, r.CC.First().Address);
			Assert.AreEqual<string>(cc_two, r.CC.Last().Address);
			Assert.AreEqual<string>(subject, r.Subject);
			Assert.AreEqual<string>(body, r.Body);
		}
Beispiel #2
0
		public void MessageWithAttachmentToMIME822() {
			MailMessage m = new MailMessage("*****@*****.**", "*****@*****.**");

			m.Subject = "This is just a test.";
			m.Body = "Please take a look at the attached file.";

			// Add a zip archive as an attachment
			using (var ms = new MemoryStream(Properties.Resources.ZipAttachment)) {
				Attachment attachment = new Attachment(ms,
					new System.Net.Mime.ContentType("application/zip"));
				m.Attachments.Add(attachment);
				
				string mime822 = m.ToMIME822();
				// Reconstruct MailMessage from text and verify the constructed
				// attachment is identical to our resource file.
				MailMessage r = MessageBuilder.FromMIME822(mime822);

				Assert.AreEqual<int>(1, r.Attachments.Count);
				using (var br = new BinaryReader(r.Attachments[0].ContentStream)) {
					byte[] constructed = br.ReadBytes((int)br.BaseStream.Length);
					Assert.IsTrue(
						Properties.Resources.ZipAttachment.SequenceEqual(constructed));
				}
			}
		}
Beispiel #3
0
		/// <summary>
		/// Stores the specified mail message on the IMAP server.
		/// </summary>
		/// <param name="message">The mail message to store on the server.</param>
		/// <param name="seen">Set this to true to set the \Seen flag for the message
		/// on the server.</param>
		/// <param name="mailbox">The mailbox the message will be stored in. If this
		/// parameter is omitted, the value of the DefaultMailbox property is used to
		/// determine the mailbox to store the message in.</param>
		/// <exception cref="NotAuthenticatedException">Thrown if the method was called
		/// in a non-authenticated state, i.e. before logging into the server with
		/// valid credentials.</exception>
		/// <exception cref="BadServerResponseException">Thrown if the mail message could
		/// not be stored. The message property of the exception contains the error message
		/// returned by the server.</exception>
		/// <returns>The unique identifier (UID) of the stored message.</returns>
		/// <remarks>A unique identifier (UID) is a 32-bit value assigned to each
		/// message which uniquely identifies the message within a mailbox. No two
		/// messages in a mailbox share the the same UID.</remarks>
		/// <seealso cref="StoreMessages"/>
		/// <include file='Examples.xml' path='S22/Imap/ImapClient[@name="StoreMessage"]/*'/>
		public uint StoreMessage(MailMessage message, bool seen = false, string mailbox = null) {
			if (!Authed)
				throw new NotAuthenticatedException();
			string mime822 = message.ToMIME822();
			lock (sequenceLock) {
				PauseIdling();
				if (mailbox == null)
					mailbox = defaultMailbox;
				string tag = GetTag();
				string response = SendCommandGetResponse(tag + "APPEND " +
					Util.UTF7Encode(mailbox).QuoteString() + (seen ? @" (\Seen)" : "") +
					" {" + mime822.Length + "}");
				// The server is required to send a continuation response before
				// we can go ahead with the actual message data.
				if (!response.StartsWith("+"))
					throw new BadServerResponseException(response);
				response = SendCommandGetResponse(mime822);
				while (response.StartsWith("*"))
					response = GetResponse(); 
				ResumeIdling();
				if (!IsResponseOK(response, tag))
					throw new BadServerResponseException(response);
				return GetHighestUID(mailbox);
			}
		}
Beispiel #4
0
        public uint StoreMessage(MailMessage message, bool seen = false, string mailbox = null)
        {
            AssertValid();
            message.ThrowIfNull("message");
            string mime822 = message.ToMIME822();
            lock (sequenceLock)
            {
                PauseIdling();
                if (mailbox == null)
                {
                    mailbox = defaultMailbox;
                }

                string resptag = GetTag();
                string response = SendCommandGetResponse(resptag + "APPEND " +
                    Util.UTF7Encode(mailbox).QuoteString() + (seen ? @" (\Seen)" : string.Empty) +
                    " {" + mime822.Length + "}");

                if (!response.StartsWith("+"))
                {
                    throw new BadServerResponseException(response);
                }

                response = SendCommandGetResponse(mime822);
                while (response.StartsWith("*"))
                {
                    response = GetResponse();
                }

                ResumeIdling();
                if (!IsResponseOK(response, resptag))
                {
                    throw new BadServerResponseException(response);
                }

                return GetHighestUid(mailbox);
            }
        }