FUNCTION EMI_100_MB_GETIMAP( STRSERVER, STRACCOUNT, STRPASSWORD , cReal )
LOCAL NRET
LOCAL OIMAP
LOCAL AENVELOPE
LOCAL AMESSAGES
LOCAL NCOUNT := 0
LOCAL N := 1
LOCAL oEnvelopes
LOCAL cFolder := "INBOX"
LOCAL i := 1
LOCAL cLogfile := GetlogFileName("Imap")
OIMAP := TOLEAUTO():NEW( "MAILBEE.IMAP4" )
OIMAP:LICENSEKEY := CMB_MAILKEY
OIMAP:SERVERNAME := AllTrim( STRSERVER )
OIMAP:USERNAME := AllTrim( STRACCOUNT )
OIMAP:PASSWORD := AllTrim( STRPASSWORD )
IF LOGIMAP = .T.
OIMAP:ENABLELOGGING := .T.
ELSE
OIMAP:ENABLELOGGING := .F.
ENDIF
* OIMAP:LOGFILEPATH := cLogfile
*OIMAP:CLEARLOG()
IF OIMAP:CONNECT() = .F.
ENDIF
IF OIMAP:selectMailBox( cFolder ) = .f.
ENDIF
oEnvelopes := OIMAP:RetrieveEnvelopes( 1, 10000, .f. )
NCOUNT := OIMAP:messageCount()
DO CASE
CASE NCOUNT = 0
CASE NCOUNT = 1
CASE NCOUNT > 1
ENDCASE
INB_100:SETORDER( 1 )
FOR N = 1 TO NCOUNT
CSEEK := ALLTRIM( UPPER( STRACCOUNT ) ) + "-" + ALLTRIM( STR( OENVELOPES [ N ]:UID ) )
IF INB_100:SEEK( cSeek ) = .f.
INB_100:BLANK()
INB_100:SUBJECT := oEnvelopes [ N ]:SUBJECT
INB_100:IMAPID := AllTrim( Upper( STRACCOUNT ) ) + "-" + AllTrim( Str( oEnvelopes [ N ]:UID ) )
objMsg := OIMAP:RetrieveSingleMessage( oEnvelopes [ N ]:UID , .T. )
INB_100:REAL_NAME := clean( cReal )
INB_100:MESSAGE := objMsg:bodyText
* EBM_100:FROM := oEnvelopes [n] :FROM
INB_100:FROMADRR := oEnvelopes [ N ] :FROMADDR
INB_100:FLAGS := oEnvelopes [ N ] :FLAGS
INB_100:SIZE := oEnvelopes [ N ] :SIZE
INB_100:Date := oEnvelopes [ N ]
ate
INB_100:RFC822DATE := oEnvelopes [ N ] :RFC822DATE
INB_100:EDIT_ID := MYL_100_EDIT_ID()
INB_100:APPEND()
INB_100:SAVE()
i ++
NEXT
OIMAP:DISCONNECT()
OIMAP:Disconnect()
RETURN .t.