コード例 #1
0
        //public List<Message> GetPage(
        //    int pageNumber,
        //    int pageSize,
        //    out int totalPages)
        //{
        //    totalPages = 1;

        //    List<Message> inboxMessages
        //        = new List<Message>();

        //    mailClient.Disconnect();
        //    mailClient.UseSSL = this.useSSL;
        //    mailClient.Connect(this.popServerName, this.popServerPort);

        //    mailClient.Authenticate(
        //        this.userName,
        //        this.password,
        //        AuthenticationMethod.TRYBOTH);

        //    int totalMessages = mailClient.GetMessageCount();

        //    if (pageSize > 0) totalPages = totalMessages / pageSize;

        //    if (totalMessages <= pageSize)
        //    {
        //        totalPages = 1;
        //    }
        //    else
        //    {
        //        int remainder;
        //        Math.DivRem(totalMessages, pageSize, out remainder);
        //        if (remainder > 0)
        //        {
        //            totalPages += 1;
        //        }
        //    }

        //    int lastMessageToGet;
        //    if (pageNumber == 1)
        //    {
        //        lastMessageToGet = totalMessages;
        //    }
        //    else
        //    {
        //        lastMessageToGet = totalMessages - (pageSize * pageNumber);
        //    }
        //    int firstMessageToGet = lastMessageToGet - pageSize;

        //    for (int i = lastMessageToGet; i >= firstMessageToGet; i -= 1)
        //    {
        //        OpenPOP.MIMEParser.Message message
        //            = mailClient.GetMessage(i, false);

        //        if (message != null)
        //        {
        //            inboxMessages.Add(message);
        //        }

        //    }

        //    mailClient.Disconnect();


        //    return inboxMessages;

        //}

        public DataTable GetInBox()
        {
            DataTable dtInBox = new DataTable();

            dtInBox.Columns.Add("MessageID", typeof(String));
            dtInBox.Columns.Add("From", typeof(String));
            dtInBox.Columns.Add("Subject", typeof(String));
            dtInBox.Columns.Add("Date", typeof(String));

            //Utility.Log=true;
            mailClient.Disconnect();
            mailClient.UseSSL = this.useSSL;
            mailClient.Connect(this.popServerName, this.popServerPort);

            mailClient.Authenticate(
                this.userName,
                this.password,
                AuthenticationMethod.TRYBOTH);

            int Count = mailClient.GetMessageCount();

            if (Count > 20)
            {
                Count = 20;
            }

            for (int i = Count; i >= 1; i -= 1)
            {
                SharpMessage message
                    = mailClient.GetMessage(i, false);

                if (message != null)
                {
                    DataRow row = dtInBox.NewRow();
                    row["MessageID"] = message.MessageID;
                    row["From"]      = message.From;
                    row["Subject"]   = message.Subject;
                    row["Date"]      = message.Date;
                    dtInBox.Rows.Add(row);
                }
            }

            mailClient.Disconnect();

            return(dtInBox);
        }
コード例 #2
0
        public AlertMessage GetNextMessage()
        {
            FileInfo[] files;
            if ((files = newDir.GetFiles()).Length > 0)
            {
                files[0].MoveTo(Path.Combine(curDir.FullName, files[0].Name + ":2,"));
                SharpMessage message;
                using (FileStream stream = new FileStream(files[0].FullName, FileMode.Open))
                {
                    message = new SharpMessage(stream);
                }

                AlertMessage m = new AlertMessage();
                m.Date    = message.Date;
                m.Subject = message.Subject;
                m.Body    = message.Body;

                return(m);
            }
            else
            {
                return(null);
            }
        }
コード例 #3
0
        public List <SharpMessage> GetPage(
            int pageNumber,
            int pageSize,
            out int totalPages)
        {
            totalPages = 1;

            List <SharpMessage> inboxMessages
                = new List <SharpMessage>();

            mailClient.Disconnect();
            mailClient.UseSSL = this.useSSL;
            mailClient.Connect(this.popServerName, this.popServerPort);

            mailClient.Authenticate(
                this.userName,
                this.password,
                AuthenticationMethod.TRYBOTH);

            int totalMessages = mailClient.GetMessageCount();

            if (pageSize > 0)
            {
                totalPages = totalMessages / pageSize;
            }

            if (totalMessages <= pageSize)
            {
                totalPages = 1;
            }
            else
            {
                int remainder;
                Math.DivRem(totalMessages, pageSize, out remainder);
                if (remainder > 0)
                {
                    totalPages += 1;
                }
            }

            int lastMessageToGet;

            if (pageNumber == 1)
            {
                lastMessageToGet = totalMessages;
            }
            else
            {
                lastMessageToGet = totalMessages - (pageSize * pageNumber);
            }
            int firstMessageToGet = lastMessageToGet - pageSize;

            for (int i = lastMessageToGet; i >= firstMessageToGet; i -= 1)
            {
                SharpMessage message
                    = mailClient.GetMessage(i, false);

                if (message != null)
                {
                    inboxMessages.Add(message);
                }

                //message.
            }

            mailClient.Disconnect();


            return(inboxMessages);
        }
コード例 #4
0
		MailModel HandlePgpMime(Outlook.MailItem mailItem, Outlook.Attachment encryptedMime, Outlook.Attachment sigMime, string sigHash = "sha1")
		{
			Logger.Trace("> HandlePgpMime");
			CryptoContext context = null;

			var cleartext = mailItem.Body;
			// 1. Decrypt attachement

			if (encryptedMime != null)
			{
				if (DecryptMime(mailItem, encryptedMime, ref context, ref cleartext))
				{
					return null;
				}
			}

			// 2. Verify signature
			Signature signature = null;
			if (sigMime != null)
			{
				context = new CryptoContext(Passphrase);
				signature = VerifySignature(mailItem, sigMime, sigHash, ref context);
			}

			if (context == null)
				return null;

			// Extract files from MIME data

			MailModel mailModel = null;
			var msg = new SharpMessage(cleartext);
			string body = mailItem.Body;

			if (mailItem.BodyFormat == Outlook.OlBodyFormat.olFormatPlain)
			{
				mailModel = new PlainMailModel
				{
					Body = msg.Body
				};
			}
			else if (mailItem.BodyFormat == Outlook.OlBodyFormat.olFormatHTML)
			{
				if (!msg.Body.TrimStart().ToLower().StartsWith("<html"))
				{
					body = msg.Body;
					body = System.Net.WebUtility.HtmlEncode(body);
					body = body.Replace("\n", "<br />");

					mailModel = new HtmlMailModel
					{
						Body = "<html><head></head><body>" + body + "</body></html>"
					};
				}
				else
				{
					mailModel = new HtmlMailModel
					{
						Body = msg.Body
					};
				}
			}
			else
			{
				// May cause mail item not to open correctly

				mailModel = new PlainMailModel
				{
					Body = msg.Body,
					Signature = signature
				};
			}

			foreach (SharpAttachment mimeAttachment in msg.Attachments)
			{
				mimeAttachment.Stream.Position = 0;
				var fileName = mimeAttachment.Name;

				var tempFile = Path.Combine(Path.GetTempPath(), fileName);

				using (var fout = File.OpenWrite(tempFile))
				{
					mimeAttachment.Stream.CopyTo(fout);
				}

				if (fileName == "signature.asc")
				{
					var detachedsig = File.ReadAllText(tempFile);
					var clearsig = CreateClearSignatureFromDetachedSignature(mailItem, sigHash, detachedsig);
					var crypto = new PgpCrypto(context);
					signature = VerifyClearSignature(ref context, crypto, clearsig);
				}

				mailModel.Attachments.Add(new Attachment
				{
					TempFile = tempFile, 
					AttachmentType = Outlook.OlAttachmentType.olByValue, 
					FileName = fileName
				});
			}
			mailModel.Body = mailModel.Body;
			mailModel.Signature = signature;
			return mailModel;
		}