Inheritance: MimeKit.MimeVisitor
Beispiel #1
0
        public static MimeMessage Reply(MimeMessage message, MailboxAddress from, bool replyToAll)
        {
            var visitor = new ReplyVisitor();
            var reply   = new MimeMessage();

            reply.From.Add(from);

            // reply to the sender of the message
            if (message.ReplyTo.Count > 0)
            {
                reply.To.AddRange(message.ReplyTo);
            }
            else if (message.From.Count > 0)
            {
                reply.To.AddRange(message.From);
            }
            else if (message.Sender != null)
            {
                reply.To.Add(message.Sender);
            }

            if (replyToAll)
            {
                // include all of the other original recipients (removing ourselves from the list)
                reply.To.AddRange(message.To.Mailboxes.Where(x => x.Address != from.Address));
                reply.Cc.AddRange(message.Cc.Mailboxes.Where(x => x.Address != from.Address));
            }

            // set the reply subject
            if (!message.Subject.StartsWith("Re:", StringComparison.OrdinalIgnoreCase))
            {
                reply.Subject = "Re: " + message.Subject;
            }
            else
            {
                reply.Subject = message.Subject;
            }

            // construct the In-Reply-To and References headers
            if (!string.IsNullOrEmpty(message.MessageId))
            {
                reply.InReplyTo = message.MessageId;
                foreach (var id in message.References)
                {
                    reply.References.Add(id);
                }
                reply.References.Add(message.MessageId);
            }

            visitor.Visit(message);

            reply.Body = visitor.Body ?? new TextPart("plain")
            {
                Text = ReplyVisitor.GetOnDateSenderWrote(message) + Environment.NewLine
            };

            return(reply);
        }
		public static MimeMessage Reply (MimeMessage message, MailboxAddress from, bool replyToAll)
		{
			var visitor = new ReplyVisitor ();
			var reply = new MimeMessage ();

			reply.From.Add (from);

			// reply to the sender of the message
			if (message.ReplyTo.Count > 0) {
				reply.To.AddRange (message.ReplyTo);
			} else if (message.From.Count > 0) {
				reply.To.AddRange (message.From);
			} else if (message.Sender != null) {
				reply.To.Add (message.Sender);
			}

			if (replyToAll) {
				// include all of the other original recipients (removing ourselves from the list)
				reply.To.AddRange (message.To.Mailboxes.Where (x => x.Address != from.Address));
				reply.Cc.AddRange (message.Cc.Mailboxes.Where (x => x.Address != from.Address));
			}

			// set the reply subject
			if (!message.Subject.StartsWith ("Re:", StringComparison.OrdinalIgnoreCase))
				reply.Subject = "Re: " + message.Subject;
			else
				reply.Subject = message.Subject;

			// construct the In-Reply-To and References headers
			if (!string.IsNullOrEmpty (message.MessageId)) {
				reply.InReplyTo = message.MessageId;
				foreach (var id in message.References)
					reply.References.Add (id);
				reply.References.Add (message.MessageId);
			}

			visitor.Visit (message);

			reply.Body = visitor.Body ?? new TextPart ("plain") { Text = ReplyVisitor.GetOnDateSenderWrote (message) + Environment.NewLine };

			return reply;
		}