forked from cosullivan/SmtpServer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTracingSmtpCommandVisitor.cs
More file actions
131 lines (117 loc) · 4.11 KB
/
Copy pathTracingSmtpCommandVisitor.cs
File metadata and controls
131 lines (117 loc) · 4.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
using System;
using System.IO;
using System.Linq;
using SmtpServer.Mail;
using SmtpServer.Protocol;
namespace SmtpServer.Tracing
{
/// <summary>
/// Tracing Smtp Command Visitor
/// </summary>
public sealed class TracingSmtpCommandVisitor : SmtpCommandVisitor
{
readonly TextWriter _output;
/// <summary>
/// Constructor.
/// </summary>
/// <param name="output">The output stream to write the command execution to.</param>
public TracingSmtpCommandVisitor(TextWriter output)
{
if (output == null)
{
throw new ArgumentException(nameof(output));
}
_output = output;
}
/// <summary>
/// Visit an AUTH command.
/// </summary>
/// <param name="command">The command that is being visited.</param>
protected override void Visit(AuthCommand command)
{
_output.WriteLine("AUTH: Method={0}, Parameter={1}", command.Method, command.Parameter);
}
/// <summary>
/// Visit an DATA command.
/// </summary>
/// <param name="command">The command that is being visited.</param>
protected override void Visit(DataCommand command)
{
_output.WriteLine("DATA");
}
/// <summary>
/// Visit a HELO command.
/// </summary>
/// <param name="command">The command that is being visited.</param>
protected override void Visit(HeloCommand command)
{
_output.WriteLine("HELO: DomainOrAddress={0}", command.DomainOrAddress);
}
/// <summary>
/// Visit an EHLO command.
/// </summary>
/// <param name="command">The command that is being visited.</param>
protected override void Visit(EhloCommand command)
{
_output.WriteLine("EHLO: DomainOrAddress={0}", command.DomainOrAddress);
}
/// <summary>
/// Visit an MAIL command.
/// </summary>
/// <param name="command">The command that is being visited.</param>
protected override void Visit(MailCommand command)
{
_output.WriteLine("MAIL: Address={0} Parameters={1}",
command.Address.AsAddress(),
string.Join(",", command.Parameters.Select(kvp => $"{kvp.Key}={kvp.Value}")));
}
/// <summary>
/// Visit an NOOP command.
/// </summary>
/// <param name="command">The command that is being visited.</param>
protected override void Visit(NoopCommand command)
{
_output.WriteLine("NOOP");
}
/// <summary>
/// Visit an PROXY command.
/// </summary>
/// <param name="command">The command that is being visited.</param>
protected override void Visit(ProxyCommand command)
{
_output.WriteLine($"PROXY {command.SourceEndpoint} --> {command.DestinationEndpoint}");
}
/// <summary>
/// Visit an QUIT command.
/// </summary>
/// <param name="command">The command that is being visited.</param>
protected override void Visit(QuitCommand command)
{
_output.WriteLine("QUIT");
}
/// <summary>
/// Visit an RCPT command.
/// </summary>
/// <param name="command">The command that is being visited.</param>
protected override void Visit(RcptCommand command)
{
_output.WriteLine("RCPT: Address={0}", command.Address.AsAddress());
}
/// <summary>
/// Visit an RSET command.
/// </summary>
/// <param name="command">The command that is being visited.</param>
protected override void Visit(RsetCommand command)
{
_output.WriteLine("RSET");
}
/// <summary>
/// Visit an STARTTLS command.
/// </summary>
/// <param name="command">The command that is being visited.</param>
protected override void Visit(StartTlsCommand command)
{
_output.WriteLine("STARTTLS");
}
}
}