-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_POP3.au3
651 lines (595 loc) · 21.3 KB
/
_POP3.au3
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
; :collapseFolds=0:maxLineLen=80:mode=autoitscript:tabSize=8:indentSize=8:folding=indent:
;===============================================================================
; Original UDF:
; http://www.autoitscript.com/forum/index.php?showtopic=22838
;~ Basic functions for AU3 Scripts, based on the 1939 RFC.
;~ See http://www.ietf.org/rfc/rfc1939.txt
;~ Include version : 0.99 (March 2006, 9th).
;~ Requires AU3 beta version 3.1.1.110 or newer.
;~ Author : Luc HENNINOT <lhenninot@nordnet.fr>
;===============================================================================
; Name ..........: _POP3.au3
; Author: .......: Thorsten Willert (thorsten [dot] willert [at] gmx [dot] de)
; Date ..........: Thu Feb 24 22:59:56 CET 2010 @778 /Internet Time/
; Version .......: 1.03
; AutoIt ........: v3.3.2.0
;===============================================================================
#include-once
#Region Global constants
; -- _POP3 error codes, sent by SetError. Use @error to display it. --
Global Enum $POP3_ERROR_OK = 0, _
$POP3_ERROR, _
$POP3_ERROR_TCPCONNECT_FAILED, _
$POP3_ERROR_SERVER_RESPONSE_TIMEOUT, _
$POP3_ERROR_ALREADY_CONNECTED, _
$POP3_ERROR_NOT_CONNECTED, _
$POP3_ERROR_NO_AUTH, _
$POP3_ERROR_TCPRECV_TIMEOUT, _
$POP3_ERROR_USER_REFUSED, _
$POP3_ERROR_PASSWD_REFUSED, _
$POP3_ERROR_ERR_RESPONSE, _
$POP3_ERROR_NO_OK_RESPONSE, _
$POP3_ERROR_STAT_BADRESPONSE, _
$POP3_ERROR_NO_TCP_RESPONSE, _
$POP3_ERROR_STAT_REFUSED, _
$POP3_ERROR_LIST_REFUSED, _
$POP3_ERROR_RSET_REFUSED, _
$POP3_ERROR_RETR_REFUSED, _
$POP3_ERROR_QUIT_REFUSED, _
$POP3_ERROR_DELE_REFUSED, _
$POP3_ERROR_TOP_REFUSED, _
$POP3_ERROR_UIDL_REFUSED, _
$POP3_ERROR_NOOP_REFUSED ; I love this one ;)
;-- _POP3 vars --
Global Const $POP3_OK = '^\+OK'; Regexp syntax
#EndRegion Global constants
#Region Global variables
Global $POP3_TRACE = True
Global $POP3_ISCONNECTED = 0
Global $POP3_ISAUTH = 0
Global $POP3_SOCKET
Global $POP3_SERVER_RESPONSE_TIMEOUT = 60000 ; 1 mn, modify it if needed
#EndRegion Global variables
#Region Example
#include <array.au3>
If _POP3Connect("AnnExampleUser@freenet.de", "0815") Then
$a = _POP3Info()
_ArrayDisplay($a)
_POP3Quit()
_POP3Disconnect()
EndIf
Exit
#EndRegion Example
; #FUNCTION# ===================================================================
; Name ..........: _POP3Info
; Description ...: Returns an array with the specified informations about all mails
; AutoIt Version : V3.3.2.0
; Syntax ........: _POP3Info([$vInfo = ""])
; Parameter(s): .: $vInfo - Optional: (Default = "") : string or array
; Return Value ..: Success - array (Default: array[date,from,to,subject])
; Failure - 0
; @ERROR -
; Author(s) .....: Thorsten Willert
; Date ..........: Fri Jan 15 18:17:54 CET 2010
; Link ..........:
; Related .......:
; Example .......: No
; ==============================================================================
Func _POP3Info($vInfo = "")
If $POP3_ISAUTH Then
Local $vInf
If $vInfo = "" Then
Local $vInf[4] = ["Date", "From", "To", "Subject"]
ElseIf IsArray($vInfo) Then
$vInf = $vInfo
Else
Local $vInf[1] = [$vInfo]
EndIf
Local $iCnt = _POP3MsgCnt()
If @error Then Return SetError(@error, 0, 0)
Local $sTMP, $aTMP
Local $iInf = UBound($vInf)
If $iCnt > 0 Then
Local $aRet[$iCnt + 1][$iInf]
$aRet[0][0] = $iCnt
For $i = 1 To $iCnt
$sTMP = _POP3Top($i)
If @error Then Return SetError(@error, 0, 0)
For $j = 0 To $iInf - 1
$aTMP = StringRegExp($sTMP, '(?i)\n' & $vInf[$j] & ':\s*(.*?)\r', 3)
If Not @error Then $aRet[$i][$j] = $aTMP[0]
Next
Next
Return $aRet
EndIf
Return SetError($POP3_ERROR, 0, 0)
Else
Return SetError($POP3_ERROR_NO_AUTH, 0, 0)
EndIf
EndFunc ;==>_POP3Info
; #FUNCTION# ===================================================================
; Name ..........: _POP3Connect
; Description ...: Conects to the according pop3 server.
; AutoIt Version : V3.3.2.0
; Syntax ........: _POP3Connect($sLogin, $sPasswd[, $sServer = ""[, $iPort = 110]])
; Parameter(s): .: $sLogin -
; $sPasswd -
; $sServer - Optional: (Default = "") : pop3 server
; $iPort - Optional: (Default = 110) :
; Return Value ..: Success - 1
; Failure - 0
; @ERROR -
; Author(s) .....: Luc HENNINOT, Thorsten Willert
; Date ..........: Fri Jan 15 18:37:29 CET 2010
; Link ..........:
; Related .......:
; Example .......: No
; ==============================================================================
Func _POP3Connect($sLogin, $sPasswd, $sServer = "", $iPort = 110)
If $POP3_ISCONNECTED = 0 Then
If $iPort = 995 Then
ConsoleWriteError("_POP3Connect: Error: SSL not supported ..." & @CRLF)
Return SetError(1, 0, 0)
EndIf
If Not StringInStr($sServer, ".") Then
Local $aTMP = StringRegExp($sLogin, '.*?@(.*?)\.(.*)', 3)
If UBound($aTMP) Then
$sServer = $aTMP[0]
Local $sD = "." & $aTMP[1]
Else
ConsoleWriteError("_POP3Connect: Error: Can't find domain in login-name." & @CRLF)
Return SetError(1, 0, 0)
EndIf
Select
Case Ping("pop3." & $sServer & $sD, 2000)
$sServer = "pop3." & $sServer & $sD
Case Ping("pop." & $sServer & $sD, 2000)
$sServer = "pop." & $sServer & $sD
Case Ping("pop3." & $sServer & ".com", 2000)
$sServer = "pop3." & $sServer & ".com"
Case Ping("pop." & $sServer & ".com", 2000)
$sServer = "pop." & $sServer & ".com"
Case Else
ConsoleWriteError("_POP3Connect: Error: Can't find POP3-server." & @CRLF)
Return SetError(1, 0, 0)
EndSelect
EndIf
TCPStartup()
; Basic name to IP conversion
ConsoleWrite("_POP3Connect: connecting to: (" & $sServer & ") ")
If StringRegExp($sServer, "[a-zA-Z]") Then $sServer = TCPNameToIP($sServer)
ConsoleWrite($sServer & ":" & $iPort & @CRLF)
$POP3_SOCKET = TCPConnect($sServer, $iPort)
If @error Then
$POP3_ISCONNECTED = 0
ConsoleWriteError("_POP3Connect: Error: " & @error & @CRLF)
Return SetError($POP3_ERROR_TCPCONNECT_FAILED, 0, 0)
Else
$POP3_ISCONNECTED = 1
EndIf
; We need a first OK from pop3 server
__POP3WaitForOK()
If @error Then Return SetError($POP3_ERROR_NO_OK_RESPONSE, 0, 0)
; Send user
__POP3Cmd("USER " & $sLogin)
If @error Then Return SetError(@error, 0, 0)
; Send passwd
__POP3Cmd("PASS " & $sPasswd)
If @error Then Return SetError(@error, 0, 0)
$POP3_ISAUTH = 1
Return 1
Else
Return SetError($POP3_ERROR_ALREADY_CONNECTED, 0, 0)
EndIf
EndFunc ;==>_POP3Connect
; #FUNCTION# ===================================================================
; Name ..........: _POP3Dele
; Description ...: Delete msg n-msg_number.
; AutoIt Version : V3.3.2.0
; Syntax ........: _POP3Dele($iMsg)
; Parameter(s): .: $iMsg - msg-number
; Return Value ..: Success - server response
; Failure - 0
; @ERROR -
; Author(s) .....: Luc HENNINOT, Thorsten Willert
; Date ..........: Thu Jan 14 15:24:41 CET 2010
; Link ..........:
; Related .......:
; Example .......: No
; ==============================================================================
Func _POP3Dele($iMsg)
If $POP3_ISAUTH Then
__POP3Cmd("DELE " & $iMsg)
If @error Then Return SetError(@error, 0, 0)
Local $sRet = __POP3WaitTcpResponse()
If @error Then Return SetError($POP3_ERROR_NO_TCP_RESPONSE, 0, 0)
Return $sRet
Else
Return SetError($POP3_ERROR_NO_AUTH, 0, 0)
EndIf
EndFunc ;==>_POP3Dele
; #FUNCTION# ===================================================================
; Name ..........: _POP3Disconnect
; Description ...: Shuts down connection.
; AutoIt Version : V3.3.2.0
; Syntax ........: _POP3Disconnect()
; Parameter(s): .: -
; Return Value ..: Success - 1
; Failure - 0
; @ERROR -
; Author(s) .....: Luc HENNINOT, Thorsten Willert
; Date ..........: Thu Jan 14 11:15:16 CET 2010
; Remark(s) .....: Use _POP3Quit to exit !!
; Link ..........:
; Related .......:
; Example .......: No
; ==============================================================================
Func _POP3Disconnect()
If $POP3_ISCONNECTED <> 0 Then
TCPCloseSocket($POP3_SOCKET)
TCPShutdown()
$POP3_ISCONNECTED = 0
Return 1
Else
Return SetError($POP3_ERROR_NOT_CONNECTED, 0, 0)
EndIf
EndFunc ;==>_POP3Disconnect
; #FUNCTION# ===================================================================
; Name ..........: _POP3List
; Description ...: Returns an array with the msg number and its size (octets)
; AutoIt Version : V3.3.2.0
; Syntax ........: _POP3List([$iMsg = -1])
; Parameter(s): .: $iMsg - Optional: (Default = -1) :
; | -1 = all
; Return Value ..: Success - array[n][2]
; Failure - 0
; @ERROR -
; Author(s) .....: Luc HENNINOT, Thorsten Willert, Oscar
; Date ..........: Thu Feb 24 23:00:26 CET 2010
; Link ..........:
; Related .......: _POP3Uidl
; Example .......: No
; ==============================================================================
Func _POP3List($iMsg = -1)
If $POP3_ISAUTH Then
Local $aRet[1][2], $aTMP2
Local $sAddMsg = ""
If $iMsg <> -1 Then
$sAddMsg = " " & $iMsg
EndIf
; Send List
Local $sRet = __POP3Cmd("LIST" & $sAddMsg)
If @error Then Return SetError(@error, 0, 0)
While $iMsg = -1 And Not StringRegExp($sRet, "\r\n\.\r\n")
$sRet = $sRet & __POP3WaitTcpResponse()
If @error Then Return SetError($POP3_ERROR_NO_TCP_RESPONSE, 0, 0)
WEnd
$sRet = StringRegExpReplace($sRet, '.+?message.+\(.+\)\r\n', @LF) ; Yahoo-Support, by Oscar
; Stripping useless infos for complete listing
If $iMsg = -1 Then
$sRet = StringMid($sRet, 2, StringLen($sRet) - 6)
Else
$sRet = StringMid($sRet, 1, StringLen($sRet) - 2)
EndIf
Local $aTMP = StringSplit(StringStripCR($sRet), @LF)
Local $iE = UBound($aTMP)
ReDim $aRet[$iE][2]
$aRet[0][0] = $iE - 1
For $i = 1 To $iE - 1
$aTMP2 = StringSplit($aTMP[$i], " ", 2)
$aRet[$i][0] = $aTMP2[0]
$aRet[$i][1] = $aTMP2[1]
Next
Return $aRet
EndIf
EndFunc ;==>_POP3List
; #FUNCTION# ===================================================================
; Name ..........: _POP3Noop
; Description ...: Actually, does nothing.
; AutoIt Version : V3.3.2.0
; Syntax ........: _POP3Noop()
; Parameter(s): .: -
; Return Value ..: Success - 1
; Failure - 0
; @ERROR -
; Author(s) .....: Luc HENNINOT, Thorsten Willert
; Date ..........: Thu Jan 14 11:22:36 CET 2010
; Remark(s) .....: The most interesting command from RFC 1939 ;)
; Link ..........:
; Related .......:
; Example .......: No
; ==============================================================================
Func _POP3Noop()
If $POP3_ISAUTH Then
; Send NOOP
__POP3Cmd("NOOP")
If @error Then Return SetError($POP3_ERROR_USER_REFUSED, 0, 0)
Return 1
EndIf
EndFunc ;==>_POP3Noop
; #FUNCTION# ===================================================================
; Name ..........: _POP3Quit
; Description ...: Validates your actions (dele for example) and stops the connection as it should.
; AutoIt Version : V3.3.2.0
; Syntax ........: _POP3Quit()
; Parameter(s): .: -
; Return Value ..: Success - 1
; Failure - 0
; @ERROR -
; Author(s) .....: Luc HENNINOT, Thorsten Willert
; Date ..........: Thu Jan 14 11:25:00 CET 2010
; Link ..........:
; Related .......:
; Example .......: No
; ==============================================================================
Func _POP3Quit()
If $POP3_ISAUTH Then
__POP3Cmd("QUIT")
If @error Then Return SetError(@error, 0, 0)
Return 1
Else
Return SetError($POP3_ERROR_NO_AUTH, 0, 0)
EndIf
EndFunc ;==>_POP3Quit
; #FUNCTION# ===================================================================
; Name ..........: _POP3Retr
; Description ...: Downloads the according message
; AutoIt Version : V3.3.2.0
; Syntax ........: _POP3Retr([$iMsg = -1])
; Parameter(s): .: $iMsg - Optional: (Default = -1) :
; | -1 = newest
; Return Value ..: Success - string
; Failure - 0
; @ERROR -
; Author(s) .....: Luc HENNINOT, Thorsten Willert
; Date ..........: Thu Jan 14 17:23:03 CET 2010
; Link ..........:
; Related .......:
; Example .......: No
; ==============================================================================
Func _POP3Retr($iMsg = -1)
If $POP3_ISAUTH Then
If $iMsg = -1 Then
Local $aStat = _POP3Stat()
If Not @error Then $iMsg = $aStat[0]
EndIf
; Send Retr
Local $sRet = __POP3Cmd("RETR " & $iMsg)
If @error Then Return SetError(@error, 0, 0)
; Downloading until final dot and cariage return.
While Not StringRegExp($sRet, "\r\n\.\r\n")
$sRet = $sRet & __POP3WaitTcpResponse()
If @error Then Return SetError($POP3_ERROR_NO_TCP_RESPONSE, 0, 0)
WEnd
Return $sRet
Else
Return SetError($POP3_ERROR_NO_AUTH, 0, 0)
EndIf
EndFunc ;==>_POP3Retr
; #FUNCTION# ===================================================================
; Name ..........: _POP3Rset
; Description ...: Withdraw changes, such as dele orders
; AutoIt Version : V3.3.2.0
; Syntax ........: _POP3Rset()
; Parameter(s): .: -
; Return Value ..: Success - 1
; Failure - 0
; @ERROR -
; Author(s) .....: Luc HENNINOT, Thorsten Willert
; Date ..........: Thu Jan 14 11:34:52 CET 2010
; Link ..........:
; Related .......:
; Example .......: No
; ==============================================================================
Func _POP3Rset()
If $POP3_ISAUTH Then
; Send RSET
__POP3Cmd("RSET")
If @error Then Return SetError(@error, 0, 0)
Return 1
Else
Return SetError($POP3_ERROR_NO_AUTH, 0, 0)
EndIf
EndFunc ;==>_POP3Rset
; #FUNCTION# ===================================================================
; Name ..........: _POP3Stat
; Description ...: Gets the number of messages in the pop3 account (array[1]) and the size(array[2]) in octets
; AutoIt Version : V3.3.2.0
; Syntax ........: _POP3Stat()
; Parameter(s): .: -
; Return Value ..: Success - array
; Failure - array[-1,-1]
; @ERROR -
; Author(s) .....: Luc HENNINOT, Thorsten Willert
; Date ..........: Fri Jan 15 09:54:17 CET 2010
; Link ..........:
; Related .......: _POP3MsgCnt
; Example .......: No
; ==============================================================================
Func _POP3Stat()
Local $aRet[2] = [-1, -1]
If $POP3_ISAUTH Then
; Send STAT
Local $sRet = __POP3Cmd("STAT")
If @error Then Return SetError(@error, 0, 0)
$sRet = StringStripWS($sRet, 3)
$aRet = StringSplit($sRet, " ", 2)
If IsArray($aRet) Then
Return $aRet
Else
Return SetError($POP3_ERROR_STAT_BADRESPONSE, 0, $aRet)
EndIf
Else
Return SetError($POP3_ERROR_NO_AUTH, 0, $aRet)
EndIf
EndFunc ;==>_POP3Stat
; #FUNCTION# ===================================================================
; Name ..........: _POP3MsgCnt
; Description ...: Returns the number of messages
; AutoIt Version : V3.3.2.0
; Syntax ........: _POP3MsgCnt()
; Parameter(s): .: -
; Return Value ..: Success - number of messages
; Failure - -1
; @ERROR -
; Author(s) .....: Thorsten Willert
; Date ..........: Fri Jan 15 09:56:20 CET 2010
; Link ..........:
; Related .......: _POP3Stat
; Example .......: NO
; ==============================================================================
Func _POP3MsgCnt()
Local $a = _POP3Stat()
Return SetError(@error, 0, $a[0])
EndFunc ;==>_POP3MsgCnt
; #FUNCTION# ===================================================================
; Name ..........: _POP3Top
; Description ...: Retreives the mail headers, and the X first lines of the message
; AutoIt Version : V3.3.2.0
; Syntax ........: _POP3Top([$iMsg = -1[, $iLines = 0]])
; Parameter(s): .: $iMsg - Optional: (Default = -1) :
; | -1 : newest
; $iLines - Optional: (Default = 0) :
; Return Value ..: Success - string
; Failure - 0
; @ERROR -
; Author(s) .....: Luc HENNINOT, Thorsten Willert
; Date ..........: Thu Jan 14 17:26:42 CET 2010
; Link ..........:
; Related .......:
; Example .......: No
; ==============================================================================
Func _POP3Top($iMsg = -1, $iLines = 0)
If $POP3_ISAUTH Then
If $iMsg = -1 Then
Local $aStat = _POP3Stat()
If Not @error Then $iMsg = $aStat[0]
EndIf
; Send Top
Local $sRet = __POP3Cmd("TOP " & $iMsg & " " & $iLines)
If @error Then Return SetError(@error, 0, 0)
; Downloading until final dot and cariage return.
While Not StringRegExp($sRet, "\r\n\.\r\n")
$sRet = $sRet & __POP3WaitTcpResponse()
If @error Then Return SetError($POP3_ERROR_NO_TCP_RESPONSE, 0, 0)
WEnd
Return $sRet
Else
Return SetError($POP3_ERROR_NO_AUTH, 0, 0)
EndIf
EndFunc ;==>_POP3Top
; #FUNCTION# ===================================================================
; Name ..........: _POP3Uidl
; Description ...: Same as _POP3List(), but with UIDL identifiers instead of message size.
; AutoIt Version : V3.3.2.0
; Syntax ........: _POP3Uidl([$iMsg = -1])
; Parameter(s): .: $iMsg - Optional: (Default = -1) :
; Return Value ..: Success - array[n][2]
; Failure - 0
; @ERROR -
; Author(s) .....: Luc HENNINOT, Thorsten Willert
; Date ..........: Thu Jan 14 16:51:30 CET 2010
; Link ..........:
; Related .......: _POP3List
; Example .......: No
; ==============================================================================
Func _POP3Uidl($iMsg = -1)
If $POP3_ISAUTH Then
Local $aRet[1][2], $aTMP2
Local $sAddMsg = ""
If $iMsg <> -1 Then $sAddMsg = " " & $iMsg
; Send List
Local $sRet = __POP3Cmd("UIDL " & $sAddMsg)
If @error Then Return SetError(@error, 0, 0)
While $iMsg = -1 And Not StringRegExp($sRet, "\r\n\.\r\n")
$sRet = $sRet & __POP3WaitTcpResponse()
If @error Then Return SetError($POP3_ERROR_NO_TCP_RESPONSE, 0, 0)
WEnd
; Stripping useless infos for complete listing
If $iMsg = -1 Then
$sRet = StringMid($sRet, 2, StringLen($sRet) - 6)
Else
$sRet = StringMid($sRet, 1, StringLen($sRet) - 2)
EndIf
Local $aTMP = StringSplit(StringStripCR($sRet), @LF)
Local $iE = UBound($aTMP)
ReDim $aRet[$iE][2]
$aRet[0][0] = $iE - 1
For $i = 1 To $iE - 1
$aTMP2 = StringSplit($aTMP[$i], " ", 2)
$aRet[$i][0] = $aTMP2[0]
$aRet[$i][1] = $aTMP2[1]
Next
Return $aRet
Else
Return SetError($POP3_ERROR_NO_AUTH, 0, 0)
EndIf
EndFunc ;==>_POP3Uidl
; #INTERNAL_USE_ONLY# ==========================================================
; Name ..........: __POP3Cmd
; Description ...:
; AutoIt Version : V3.3.2.0
; Syntax ........: __POP3Cmd($sMSg)
; Parameter(s): .: $sMSg -
; Return Value ..: Success - string
; Failure - 0
; @ERROR -
; Author(s) .....: Thorsten Willert
; Date ..........: Thu Jan 14 17:07:08 CET 2010
; ==============================================================================
Func __POP3Cmd($sMSg)
If $POP3_TRACE Then ConsoleWrite(">: " & $sMSg & @CRLF)
TCPSend($POP3_SOCKET, $sMSg & @CRLF)
If @error Then Return SetError($POP3_ERROR_USER_REFUSED, 0, 0)
Local $sRet = __POP3WaitForOK()
If @error Then Return SetError($POP3_ERROR_NO_OK_RESPONSE, 0, 0)
Return $sRet
EndFunc ;==>__POP3Cmd
; #INTERNAL_USE_ONLY# ==========================================================
; Name ..........: __POP3WaitForOK
; Description ...: Returns the server response if it starts with "+OK"
; AutoIt Version : V3.3.2.0
; Syntax ........: __POP3WaitForOK()
; Parameter(s): .: -
; Return Value ..: Success - string
; Failure - ""
; @ERROR -
; Author(s) .....: Luc HENNINOT, Thorsten Willert
; Date ..........: Thu Jan 14 11:50:34 CET 2010
; ==============================================================================
Func __POP3WaitForOK()
; Wait for server response.
Local $sRet
Local $T = TimerInit()
While TimerDiff($T) < $POP3_SERVER_RESPONSE_TIMEOUT
$sRet = __POP3WaitTcpResponse()
If Not @error And StringRegExp($sRet, '\+OK') Then Return StringRegExpReplace($sRet, '\+OK\s?', "")
If StringRegExp($sRet, '\-ERR\s?') Then Return SetError($POP3_ERROR_ERR_RESPONSE, 0, "")
Sleep(100)
WEnd
Return SetError($POP3_ERROR_SERVER_RESPONSE_TIMEOUT, 0, "")
EndFunc ;==>__POP3WaitForOK
; #INTERNAL_USE_ONLY# ==========================================================
; Name ..........: __POP3WaitTcpResponse
; Description ...: Returns the server response
; AutoIt Version : V3.3.2.0
; Syntax ........: __POP3WaitTcpResponse([$iTimeOut = 30000])
; Parameter(s): .: $iTimeOut - Optional: (Default = 30000) :
; Return Value ..: Success - string
; Failure - 0
; @ERROR -
; Author(s) .....: Luc HENNINOT, Thorsten Willert
; Date ..........: Thu Jan 14 11:51:07 CET 2010
; ==============================================================================
Func __POP3WaitTcpResponse($iTimeOut = 30000)
;Timeout to 30 s, should be enough in most cases. Overwright it if needed.
Local $sRet = ""
Local $T = TimerInit()
While TimerDiff($T) < $iTimeOut
$sRet = TCPRecv($POP3_SOCKET, 512)
If $POP3_TRACE And $sRet Then ConsoleWrite("<: " & $sRet)
If $sRet <> "" Then Return $sRet
Sleep(100)
WEnd
Return SetError($POP3_ERROR_TCPRECV_TIMEOUT, 0, 0)
EndFunc ;==>__POP3WaitTcpResponse