Android Question POP3 GMail reading problem. (Solved)

ELCHARO

Member
Licensed User
Longtime User
HI.

I use this code to read mail. Enter in the server and read 6 mails.

log this Leyendo Mail, de1de17
( 1 of 17)
if run again not begin in the first of 17
log this Leyendo Mail, de1de11
( 1 of 11)

In the web gmail the mail remains 17 , never delete

What happens. How begin reading for first newer mail again?
I continue go to 0 mail, but are 17 in the server.
Of course, run only when new mail arrives (if enter 5 over 17) , see only 5 in the app.
Is a gmail account
("Server","pop.gmail.com")
("Port","995")


I try like activity ,and try like a service. And have the same problem.
Somebody know why?


Thanks


B4X:
#Region  Service Attributes
    #StartAtBoot: False
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim POP As POP3
    Dim maxmes As Int
    Dim vt,mt As Int
End Sub

Sub Service_Create
    Log("Entrando al Servidor.")
    POP.UseSSL = True 'Gmail requires SSL.
    POP.Initialize(Main.manager.GetString("Server"),Main.manager.GetString("Port"),Main.manager.GetString("MailAlert"),Main.manager.GetString("Password"),"pop")
    
    'repeat because 1 not work before or after
    POP.UseSSL = True 'Gmail requires SSL.
    

End Sub

Sub Service_Start (StartingIntent As Intent)
    If POP.IsInitialized = True Then
        ToastMessageShow("POP=IS_INIT",True)
        
        POP.ListMessages
    Else
        ToastMessageShow("Revisar: Cuenta de Mail-Password-Ports",True)   
    End If   
End Sub

Sub Service_Destroy
'    If POP.IsInitialized = False Then
        POP.CloseNow
'    End If   
End Sub



Sub POP_ListCompleted (Success As Boolean, Messages As Map)
    Dim nummes  As Int
    Dim Vibrate As PhoneVibrate

    Log("POP2="&Messages.Size&"-"&Success)
    vt=0
    mt =0
    If Success Then
        If Messages.Size >= 1 Then
            nummes=Messages.Size
'            maxmes=Main.manager.GetString("MaxMailRead")
            maxmes=6
            If nummes >= maxmes Then
                nummes=maxmes
            End If
            Log (nummes)
            For    i=1 To nummes           

                Log ("Leyendo Mail, de"  & i & "de" &Messages.Size )
                POP.DownloadMessage(Messages.GetKeyAt(Messages.Size-i), False) 'Download all messages and delete them
            Next
            Vibrate.Vibrate(30)
            ToastMessageShow(Messages.Size&" Mail's",True)
            '    CallSub(Main, "Dibuja")
            Vibrate.Vibrate(30)
                
        Else
            ToastMessageShow("SinMail",True)
            Log("Sin Mail.")
        End If   
    Else
        ToastMessageShow("Error Server Mail: (CHECK CUENTA)"&LastException.Message,True)
        Log("HUUUUU"&LastException.Message)
    End If
    
End Sub
Sub POP_DownloadCompleted (Success As Boolean, MessageId As Int, Mensaje As String)
    
    Log("POP3"&MessageId)
    If Success Then
        Dim m As Message
        m=Extract.ParseMail(Mensaje,MessageId)
        LogColor(m.Subject,Colors.Magenta)
        Log("Leyo:"&m.Subject)

        Log(m.Subject)
            If m.Subject.Contains("viirs") Then  'LOCAL SATELITES
                If vt=0 Then
                    File.WriteString(File.DirDefaultExternal, "viirs.csv", m.Body)
                else if vt=1 Then
                    File.WriteString(File.DirDefaultExternal, "viirs2.csv", m.Body)
                End If
                vt=vt+1
            Else
                If mt=0 Then
                    File.WriteString(File.DirDefaultExternal, "modis.csv", m.Body)
                else if mt=1 Then
                    File.WriteString(File.DirDefaultExternal, "modis2.csv", m.Body)
                End If
                mt=mt+1
            End If   
            Dim suma As Int
'            suma=vt+mt
'            Log(vt&"v-m"&mt&"-----"&maxmes    )   
'            If suma = maxmes Then
'                Log("SISSI")
'                CallSubDelayed(Main, "Dibuja")
'            End If
    Else
        Log("No Parse Mail" & MessageId)
    End If


End Sub
 
Top