Skip to content

Commit 0a3e673

Browse files
committed
Delete POP3 client
1 parent 553e8f2 commit 0a3e673

File tree

5 files changed

+6
-237
lines changed

5 files changed

+6
-237
lines changed

App.config

-9
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,6 @@
9292
<setting name="Converse_BotName" serializeAs="String">
9393
<value>Sarah</value>
9494
</setting>
95-
<setting name="Mail_POPHost" serializeAs="String">
96-
<value />
97-
</setting>
98-
<setting name="Mail_POPPort" serializeAs="String">
99-
<value>995</value>
100-
</setting>
10195
<setting name="Mail_CmdWhitelist" serializeAs="String">
10296
<value />
10397
</setting>
@@ -194,9 +188,6 @@
194188
<setting name="Global_LastKnownInsideTemp2nd" serializeAs="String">
195189
<value>0</value>
196190
</setting>
197-
<setting name="Mail_IMAPMode" serializeAs="String">
198-
<value>True</value>
199-
</setting>
200191
<setting name="Mail_IMAPHost" serializeAs="String">
201192
<value />
202193
</setting>

My Project/Settings.Designer.vb

-36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

My Project/Settings.settings

-9
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,6 @@
6262
<Setting Name="Converse_BotName" Type="System.String" Scope="User">
6363
<Value Profile="(Default)">Sarah</Value>
6464
</Setting>
65-
<Setting Name="Mail_POPHost" Type="System.String" Scope="User">
66-
<Value Profile="(Default)" />
67-
</Setting>
68-
<Setting Name="Mail_POPPort" Type="System.String" Scope="User">
69-
<Value Profile="(Default)">995</Value>
70-
</Setting>
7165
<Setting Name="Mail_CmdWhitelist" Type="System.String" Scope="User">
7266
<Value Profile="(Default)" />
7367
</Setting>
@@ -173,9 +167,6 @@
173167
<Setting Name="Global_LastKnownInsideTemp2nd" Type="System.Int32" Scope="User">
174168
<Value Profile="(Default)">0</Value>
175169
</Setting>
176-
<Setting Name="Mail_IMAPMode" Type="System.Boolean" Scope="User">
177-
<Value Profile="(Default)">True</Value>
178-
</Setting>
179170
<Setting Name="Mail_IMAPHost" Type="System.String" Scope="User">
180171
<Value Profile="(Default)" />
181172
</Setting>

modConverse.vb

+2-17
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,8 @@ Module modConverse
4747
Case "check"
4848
Select Case inputData(1)
4949
Case "mail"
50-
If My.Settings.Mail_IMAPMode = True Then
51-
Dim MailCheckThread As New Threading.Thread(AddressOf modMail.CheckMailImap)
52-
MailCheckThread.Start()
53-
Else
54-
Dim MailCheckThread As New Threading.Thread(AddressOf modMail.CheckMail)
55-
MailCheckThread.Start()
56-
End If
50+
Dim MailCheckThread As New Threading.Thread(AddressOf modMail.CheckMailImap)
51+
MailCheckThread.Start()
5752
strCommandResponse = "Checking mail"
5853
Case "out"
5954
If inputData.Length > 2 Then
@@ -85,11 +80,6 @@ Module modConverse
8580
strCommandResponse = modDreamCheeky.Disable()
8681
Case "gps"
8782
strCommandResponse = modGPS.Disable()
88-
Case "imap"
89-
My.Settings.Mail_IMAPMode = False
90-
modMail.Unload()
91-
modMail.Load()
92-
strCommandResponse = "IMAP mode disabled"
9383
Case "insteon"
9484
strCommandResponse = modInsteon.Disable()
9585
Case "library"
@@ -146,11 +136,6 @@ Module modConverse
146136
strCommandResponse = modDreamCheeky.Enable()
147137
Case "gps"
148138
strCommandResponse = modGPS.Enable()
149-
Case "imap"
150-
My.Settings.Mail_IMAPMode = True
151-
modMail.Unload()
152-
modMail.Load()
153-
strCommandResponse = "IMAP mode enabled"
154139
Case "insteon"
155140
strCommandResponse = modInsteon.Enable()
156141
Case "library"

modMail.vb

+4-166
Original file line numberDiff line numberDiff line change
@@ -56,57 +56,9 @@ Module modMail
5656
End If
5757
End Function
5858

59-
Sub CheckMail()
60-
If My.Settings.Mail_Enable = True Then
61-
If modGlobal.IsOnline = True AndAlso My.Settings.Mail_IMAPMode = False Then
62-
Try
63-
If pClient.Connected = True Then
64-
CloseServer()
65-
pClient = New TcpClient(My.Settings.Mail_POPHost, My.Settings.Mail_POPPort)
66-
ret_Val = 0
67-
Exit Sub
68-
Else
69-
pClient = New TcpClient(My.Settings.Mail_POPHost, My.Settings.Mail_POPPort)
70-
71-
NetworkS_tream = pClient.GetStream 'Read the stream
72-
m_sslStream = New SslStream(NetworkS_tream) 'Read SSL stream
73-
m_sslStream.AuthenticateAsClient(My.Settings.Mail_POPHost) 'Auth
74-
Read_Stream = New StreamReader(m_sslStream) 'Read the stream
75-
StatResp = Read_Stream.ReadLine()
76-
77-
StatResp = Login(m_sslStream, "USER " & My.Settings.Mail_Username)
78-
My.Application.Log.WriteEntry("POP3: " & StatResp)
79-
StatResp = Login(m_sslStream, "PASS " & My.Settings.Mail_Password)
80-
My.Application.Log.WriteEntry("POP3: " & StatResp)
81-
StatResp = Login(m_sslStream, "STAT ")
82-
My.Application.Log.WriteEntry("POP3: " & StatResp)
83-
84-
'Get Messages count
85-
server_Stat = StatResp.Split(" "c)
86-
My.Application.Log.WriteEntry("POP3 Message count: " & server_Stat(1))
87-
ret_Val = 1
88-
End If
89-
90-
If IsNumeric(server_Stat(1)) = True Then 'Apparently POP3 returned 'bad' during a "Temporary system problem" and 'Command' when an invalid password is used, which I want to mitigate.
91-
GetMessages(server_Stat(1))
92-
Else
93-
My.Application.Log.WriteEntry("Mail server returned a bad message count", TraceEventType.Warning)
94-
End If
95-
CloseServer()
96-
Catch SocketEx As System.Net.Sockets.SocketException
97-
My.Application.Log.WriteException(SocketEx, TraceEventType.Warning, "usually caused by a mail connection timeout")
98-
Catch NullRefEx As System.NullReferenceException
99-
My.Application.Log.WriteException(NullRefEx, TraceEventType.Warning, "usually caused by an empty POP3 response")
100-
End Try
101-
End If
102-
Else
103-
My.Application.Log.WriteEntry("Mail module is disabled")
104-
End If
105-
End Sub
106-
10759
Sub CheckMailImap()
10860
If My.Settings.Mail_Enable = True Then
109-
If modGlobal.IsOnline = True AndAlso My.Settings.Mail_IMAPMode = True Then
61+
If modGlobal.IsOnline = True Then
11062
Try
11163
pClient = New TcpClient(My.Settings.Mail_IMAPHost, My.Settings.Mail_IMAPPort)
11264
m_sslStream = New SslStream(pClient.GetStream())
@@ -133,11 +85,7 @@ Module modMail
13385
End Sub
13486

13587
Sub CheckMailHandler(source As Object, e As System.Timers.ElapsedEventArgs)
136-
If My.Settings.Mail_IMAPMode = True Then
137-
CheckMailImap()
138-
Else
139-
CheckMail()
140-
End If
88+
CheckMailImap()
14189
End Sub
14290

14391
Function CheckPurelyMailBalance(ByVal strPurelyMailAPIKey As String) As String
@@ -169,13 +117,6 @@ Module modMail
169117
End Try
170118
End Function
171119

172-
Sub CloseServer()
173-
StatResp = Login(m_sslStream, "QUIT ")
174-
My.Application.Log.WriteEntry("POP3: " & StatResp)
175-
pClient.Close()
176-
ret_Val = 0
177-
End Sub
178-
179120
Sub CreateMailkeysDb()
180121
modDatabase.Execute("CREATE TABLE IF NOT EXISTS MAILKEYS(Id INTEGER PRIMARY KEY, Nickname TEXT UNIQUE, CmdAllowlist TEXT, CmdKey TEXT)")
181122
modDatabase.Execute("ALTER TABLE MAILKEYS RENAME COLUMN CmdWhitelist TO CmdAllowlist")
@@ -239,96 +180,16 @@ Module modMail
239180
Return result
240181
End Function
241182

242-
Sub GetEmails(ByVal Server_Command As String)
243-
Dim m_buffer() As Byte = System.Text.Encoding.ASCII.GetBytes(Server_Command.ToCharArray())
244-
Dim stream_Reader As StreamReader
245-
Dim TxtLine, CmdRec, ReFrom, ReSubj As String
246-
Dim CmdTo As String = "", CmdFrom As String = "", CmdSubj As String = "", CmdID As String = "", CmdKeyLookup As String = "", CmdNickLookup As String = ""
247-
Try
248-
m_sslStream.Write(m_buffer, 0, m_buffer.Length)
249-
stream_Reader = New StreamReader(m_sslStream)
250-
Do While stream_Reader.Peek() <> -1
251-
TxtLine = stream_Reader.ReadLine()
252-
253-
If TxtLine.StartsWith("Received: ") Then
254-
CmdRec = String.Copy(TxtLine)
255-
My.Application.Log.WriteEntry("Command " & CmdRec)
256-
End If
257-
If TxtLine.StartsWith("Message-ID: ") Then
258-
CmdID = String.Copy(TxtLine)
259-
My.Application.Log.WriteEntry("Command " & CmdID)
260-
End If
261-
If TxtLine.StartsWith("Subject: ") Then
262-
CmdSubj = String.Copy(TxtLine)
263-
My.Application.Log.WriteEntry("Command " & CmdSubj)
264-
End If
265-
If TxtLine.StartsWith("From: ") Then
266-
CmdFrom = String.Copy(TxtLine)
267-
My.Application.Log.WriteEntry("Command " & CmdFrom)
268-
End If
269-
If TxtLine.StartsWith("To: ") Then
270-
CmdTo = String.Copy(TxtLine)
271-
My.Application.Log.WriteEntry("Command " & CmdTo)
272-
End If
273-
274-
If CmdSubj <> "" AndAlso CmdFrom <> "" AndAlso CmdTo <> "" AndAlso CmdID <> "" Then
275-
Exit Do
276-
End If
277-
Loop
278-
279-
If CmdSubj <> "" AndAlso CmdFrom <> "" AndAlso CmdTo <> "" AndAlso CmdID <> "" Then
280-
ReFrom = CmdFrom.Replace("From: ", "")
281-
CmdKeyLookup = GetCmdKeyFromAllowlist(ReFrom)
282-
If CmdKeyLookup <> "" Then
283-
If CmdTo = "To: " & CmdKeyLookup & " <" & My.Settings.Mail_From & ">" Then
284-
CmdNickLookup = GetNicknameFromKey(ReFrom, CmdKeyLookup)
285-
My.Application.Log.WriteEntry("Received email from " + CmdNickLookup + ", command key validated")
286-
ReSubj = CmdSubj.Replace("Subject: ", "")
287-
modConverse.Interpret(ReSubj, True, False, CmdNickLookup)
288-
Else
289-
My.Application.Log.WriteEntry("Received email from authorized user, but command key was not valid")
290-
End If
291-
Else
292-
My.Application.Log.WriteEntry("Received email from unauthorized user, ignoring")
293-
End If
294-
End If
295-
Catch ex As Exception
296-
My.Application.Log.WriteException(ex)
297-
End Try
298-
End Sub
299-
300-
Sub GetMessages(ByVal Num_Emails As Integer)
301-
Dim List_Resp As String
302-
Dim StrRetr As String
303-
Dim I As Integer
304-
For I = 1 To Num_Emails
305-
List_Resp = Login(m_sslStream, "LIST " & I.ToString)
306-
My.Application.Log.WriteEntry("POP3: " & List_Resp)
307-
308-
StrRetr = ("RETR " & I & vbCrLf)
309-
GetEmails(StrRetr)
310-
Next I
311-
End Sub
312-
313183
Function Load() As String
314184
My.Application.Log.WriteEntry("Loading mail module")
315185
If My.Settings.Mail_Enable = True Then
316-
If My.Settings.Mail_IMAPMode = False AndAlso My.Settings.Mail_POPHost = "" Then
317-
My.Application.Log.WriteEntry("No mail POP host set, asking for it")
318-
My.Settings.Mail_POPHost = InputBox("Enter mail POP host.", "Mail POP Host")
319-
End If
320186

321-
If My.Settings.Mail_IMAPMode = False AndAlso My.Settings.Mail_POPPort = "" Then
322-
My.Application.Log.WriteEntry("No mail POP port set, asking for it")
323-
My.Settings.Mail_POPPort = InputBox("Enter mail POP port.", "Mail POP Port", "995")
324-
End If
325-
326-
If My.Settings.Mail_IMAPMode = True AndAlso My.Settings.Mail_IMAPHost = "" Then
187+
If My.Settings.Mail_IMAPHost = "" Then
327188
My.Application.Log.WriteEntry("No mail IMAP host set, asking for it")
328189
My.Settings.Mail_IMAPHost = InputBox("Enter mail IMAP host.", "Mail IMAP Host")
329190
End If
330191

331-
If My.Settings.Mail_IMAPMode = True AndAlso My.Settings.Mail_IMAPPort = "" Then
192+
If My.Settings.Mail_IMAPPort = "" Then
332193
My.Application.Log.WriteEntry("No mail IMAP port set, asking for it")
333194
My.Settings.Mail_IMAPPort = InputBox("Enter mail IMAP port.", "Mail IMAP Port", "993")
334195
End If
@@ -562,28 +423,6 @@ Module modMail
562423
End Select
563424
End Function
564425

565-
Function Login(ByVal SslStrem As SslStream, ByVal Server_Command As String) As String
566-
Dim justExit As Boolean = False
567-
Dim Read_Stream2 = New StreamReader(SslStrem)
568-
Server_Command = Server_Command + vbCrLf
569-
m_buffer = System.Text.Encoding.ASCII.GetBytes(Server_Command.ToCharArray())
570-
Try
571-
m_sslStream.Write(m_buffer, 0, m_buffer.Length)
572-
Catch IOExcep As System.IO.IOException
573-
My.Application.Log.WriteException(IOExcep)
574-
modMail.Send("Mail crash averted", "Mail crash averted") ' Remove this line later if this retry method actually works
575-
justExit = True
576-
Threading.Thread.Sleep(600000)
577-
End Try
578-
If justExit = False Then
579-
Dim Server_Response As String
580-
Server_Response = Read_Stream2.ReadLine()
581-
Return Server_Response
582-
Else
583-
Return "Dumped"
584-
End If
585-
End Function
586-
587426
''' <summary>
588427
''' Asks for an updated mail password.
589428
''' </summary>
@@ -598,7 +437,6 @@ Module modMail
598437
If tmrMailCheckTimer IsNot Nothing Then
599438
tmrMailCheckTimer.Enabled = False
600439
RemoveHandler tmrMailCheckTimer.Elapsed, AddressOf CheckMailHandler
601-
' CloseServer() - Wasn't used before, causes errors, commenting out this line.
602440
End If
603441
Return "Mail module unloaded"
604442
End Function

0 commit comments

Comments
 (0)