Func _Pop3()
$MyPopServer = 'pop3.mail.ru'
$MyLogin = ''
$MyPasswd = ''
_pop3Connect($MyPopServer, $MyLogin, $MyPasswd)
If @error Then
MsgBox(0, "Error", "Unable to connect to " & $MyPopServer & @CR & @error)
Exit
Else
ConsoleWrite("Connected to server pop3 " & $MyPopServer & @CR)
EndIf
$aPop3Stat = _Pop3Stat()
If @error Then
MsgBox(0, "Error", "Unable get statistics " & $MyPopServer & @CR & @error)
ConsoleWrite(_Pop3Quit() & @CR)
_pop3Disconnect()
Exit
Else
;_ArrayDisplay($aPop3Stat)
ConsoleWrite('TOTAL MSG:' & $aPop3Stat[1] & @CRLF)
ConsoleWrite('SIZE MSG:' & $aPop3Stat[2] & @CRLF)
EndIf
Local $From = 'unknown'
Local $Subject = 'unknown'
Local $Date = 'unknown'
Local $ContentType = 'unknown'
Local $ContentEncoding = 'unknown'
Local $aData
For $iMsg = 1 To $aPop3Stat[1]
$aPop3List = _Pop3List($iMsg)
If Not IsArray($aPop3List) Then ContinueLoop
;_ArrayDisplay($aPop3List)
$Size = StringSplit($aPop3List[1], ' ', 2)
$sHeaders = _Pop3Top($iMsg, 0) ; вернем заголовки
;$sHeaders = _Pop3Top($iMsg, -1) ; вернем заголовки и текст письма
;ConsoleWrite($sHeaders & @CRLF )
$aData = StringRegExp($sHeaders, '(?m)^Content-Type:\s*(.+)$', 1)
If IsArray($aData) Then
$ContentType = StringStripCR($aData[0])
EndIf
$aData = StringRegExp($sHeaders, '(?m)^Content-Transfer-Encoding:\s*(.+)$', 1)
If IsArray($aData) Then
$ContentEncoding = StringStripCR($aData[0])
EndIf
$aData = StringRegExp($sHeaders, '(?m)^From:\s*(.+)$', 1)
If IsArray($aData) Then
$From = StringStripCR($aData[0])
$From = ContentTransferEncoding($ContentEncoding,$From)
EndIf
$aData = StringRegExp($sHeaders, '(?m)^Subject:\s*(.+)$', 1)
If IsArray($aData) Then
$Subject = StringStripCR($aData[0])
$Subject = ContentTransferEncoding($ContentEncoding,$Subject)
EndIf
$aData = StringRegExp($sHeaders, '(?m)^Date:\s*(.+)$', 1)
If IsArray($aData) Then
$Date =StringStripCR($aData[0])
EndIf
ConsoleWrite( _
'====================================' & @CRLF & _
'№ MSG: ' & $iMsg & @CRLF & _
'SIZE: ' & $Size[1] & @CRLF & _
'Content-Type: ' & $ContentType & @CRLF & _
'Encoding: ' & $ContentEncoding & @CRLF & _
'DATE: ' & $Date & @CRLF & _
'FROM: ' & $From & @CRLF & _
'SUBJECT: ' & $Subject & @CRLF _
)
Next
EndFunc
Func ContentTransferEncoding($sType,$Data)
;ConsoleWrite('=====================================' &@CRLF)
;ConsoleWrite('GetCyrillic:' & _Encoding_GetCyrillicANSIEncoding($Data)&@CRLF)
Local $IsCyrillic = _Encoding_GetCyrillicANSIEncoding($Data)
If $IsCyrillic Then Return _Encoding_CyrillicTo1251($Data)
Local $Email ='', $aData
Local $sPattern='(?i)(?:UTF-8B|utf-8B|UTF-8Q|utf-8Q|KOI8-RB|windows-1251B)([A-Za-z0-9+/.@!]+)(\s<.*>)?'
$CleanData=StringRegExpReplace($Data,'[=?]','')
If Not @error Then $Data=$CleanData
;ConsoleWrite('[=?]:' & $Data & @CRLF)
$aData = StringRegExp($Data,$sPattern,2)
If Not @error Then
$Data = $aData[1]
If Ubound($aData)>2 Then
$Email = $aData[2]
;ConsoleWrite('PATTERN:' & $Data & $Email & @CRLF)
Else
$Email=''
EndIf
EndIf
Switch $sType
Case 'quoted-printable'
Return _Encoding_CyrillicTo1251(_Encoding_QuotedPrintableToANSI($Data)) & $Email
Case Else
If Not _Encoding_Base64Decode($Data) Then Return $Data
Return _Encoding_CyrillicTo1251(_Encoding_Base64Decode($Data)) & $Email
EndSwitch
EndFunc