Announcement

Collapse
No announcement yet.

project mailboy, pop3 email reader processor

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • project mailboy, pop3 email reader processor

    here is what the mailboy project is suppose to do for me.
    using console programs with returned errlevels for batch file processing
    using pop3 protocol
    read email from server, save email, delete email on pop3 server
    read emails by order of first in first out, an accounting term.
    process emails according to some standards
    scan emails saved for possible spam.
    scrub emails for text only emails, all others then placed on hold.
    scrub emails placed on hold for only html code then covert those to text, while rejecting all others placed on hold.
    any emails placed on a hold status, respond back to email sender of email policy.
    any emails placed on hold can be filtered by sender whitelist then processed, others keep on hold then deleted after a certain date.
    info on emails placed on hold will be listed inside a text file for viewing the email sender, date, etc.

    emails that are text only filtered are read and have a response sent back to the sender of either, email was read or some kind of personal response.

    those are basically the building blocks.
    i will list code as i go
    maybe others will kick in ideas too or valuable information for processing emails.
    Last edited by Paul Purvis; 22 May 2008, 03:11 PM.
    p purvis

  • #2
    here is a rough first program to get the emails from a server using pop3 protocol.
    this program will not delete emails on server as coded, unremark section of code to delete emails on server

    pop3deletemessage from Clay Clear
    most all other code from Lance Edmonds, providing the skeleton program from which i worked.
    http://www.powerbasic.com/support/pb...hlight=msgsize

    there are many other things need in this program
    i want to have where mutliple passwords are used
    i want to have the program do a second pass after the first
    i want the program to do mutiple passes if the first pass is not success in loginning onto the server.
    i want if possible to use mutltiple pop3 accounts for the reason if a user is changing email account service
    i am going to save the files email files differently
    i am going to place other information about the email in the first serveral lines of the email that is stored to file, probably use the first twenty lines as place for my information lines and place a beginning and ending mark of the email received.

    the saved files will named incrementally and possibly have a date attached to the file name.

    there will also be a log file created by the program on its progress
    and a log of emails received will be logged into a daily or monthly log file having the date in the log file name.
    there also needs to be a configuration file for the program, setting up preferences.



    i believe mailboy was what they called a person in a company distributing the mail in a large building, so my programs will be named in honor of him.


    Code:
    'mailboy1.bas
    'this program uses the POP3 protocol and retrieves emails from a pop3 server
    'the will usually delete emails as they are read but for testing purposes
    '   it has been remarked out to delete emails on the server.
    'this code does not check for an internet connection
    '
    #COMPILE EXE
    #DIM ALL
    
    #INCLUDE "WIN32API.INC"
    #INCLUDE "c:\pbcc40\SAMPLES\internet\TCP\TCP32.INC"
    GLOBAL gspop3server AS STRING
    GLOBAL gsusername AS STRING
    GLOBAL gspassword AS STRING
    
    '!supply your own information
    FUNCTION initializeuserinfo() AS LONG
    !
    gsPop3Server = "mail.example.com"         ' Your pop3 address
    gsUserName   = "myuseraccount"                ' Your user name
    gsPassword   = "myuserpassword"                ' Your password
    END FUNCTION
    
    
    FUNCTION Pop3DeleteMessage (BYVAL nTCP AS DWORD, BYVAL MessageNumber AS LONG) EXPORT AS LONG
    FUNCTION=0
        LOCAL Buffer AS STRING
        TCP PRINT nTCP, USING$("DELE #", MessageNumber)
        TCP LINE ntcp, buffer
        IF LEN(buffer)<3 THEN EXIT FUNCTION
        IF LEFT$(Buffer, 3) = "+OK" THEN
          STDOUT "   deleted on server"
          FUNCTION=1
          END IF
    END FUNCTION
    
    
    FUNCTION PBMAIN()
        DIM y AS LONG
        DIM x AS LONG
        DIM hfile AS LONG
        DIM hTcp AS LONG
        DIM Result AS LONG
        DIM MsgQty AS LONG
        DIM MsgSize AS LONG
        DIM errlevelexit AS LONG
        DIM exiterrlevelmessage(0:6) AS STRING
        
        
        DIM soutputfilename AS STRING
        DIM Message(1:1) AS STRING
        exiterrlevelmessage(0)="unknown error"
        exiterrlevelmessage(1)="failure to login server"
        exiterrlevelmessage(2)="server response failure"
        exiterrlevelmessage(3)="failure on receiving emails"
        exiterrlevelmessage(4)="failure on saving emails"
        exiterrlevelmessage(5)="no emails on server"
        exiterrlevelmessage(6)="emails saved"
      
        
        errlevelexit=0
       
        initializeuserinfo
        CONSOLE NAME "Pop3 E-mail Server Check Example"
    
        STDOUT "Logging into pop3 server"
        STDOUT "servername "+gsPop3Server
       
        hTcp = Pop3Connect(gsPop3Server, gsUserName, gsPassword)
        IF ISFALSE hTcp THEN
            STDOUT "Error logging in to server (Error code "+TRIM$(STR$(ERR))+")"
            errlevelexit=1
            GOTO finished:
        ELSE
            STDOUT "Logged in Ok. Handle = "+TRIM$(STR$(hTcp))
        END IF
    
        Result = Pop3GetStat(hTcp, MsgQty, MsgSize)
    
        IF Result THEN
            STDOUT "No Emails on server"
            STDOUT "or an error ocurred!"
            STDOUT "Error code "+STR$(Result)
            errlevelexit=2
            GOTO closeconnection
        ELSE
            errlevelexit=3
          IF msgqty>0 THEN
            errlevelexit=4  ' email exist on server but not yet retrieved
            STDOUT "Number of Emails found "+TRIM$(STR$(MsgQty))
            STDOUT FORMAT$(MsgSize,"#,")+" total bytes"
            STDOUT "============================='
            STDOUT "Retreiving Email(s)..."
            ELSE
            STDOUT "No Emails listed on server"
            errlevelexit=5
            GOTO closeconnection
            END IF
            FOR x = msgqty TO 1 STEP -1   'this line will probably read the emails from from received to last received
           ' FOR x = 1 TO MsgQty          'this line will probably read the emails from last received to first received back
                STDOUT "Retreiving email - "+TRIM$(STR$(x))
                errlevelexit=3
                Result = Pop3RetrMessage(hTcp, x, Message())
                IF Result THEN
                    '  ARRAY SCAN Message(), FROM 1 TO 8, COLLATE UCASE, = "SUBJECT:", TO y
                    '  IF y THEN
                    '      STDOUT "Email " TRIM$(message(y))
                    '  END IF
                    errlevelexit=4
                    hfile=FREEFILE
                    STDOUT "   Saving email - "+TRIM$(STR$(x))+" of "+TRIM$(STR$(msgqty))
                    soutputfilename=TRIM$(STR$(msgqty-x+1))+".emalboy1.tmp"
                    OPEN soutputfilename FOR OUTPUT AS #hfile
                    STDOUT "   in " +soutputfilename
                     FOR y = 1 TO Result
                     'there is a way to write the array faster to disk but i forgot how
                       PRINT #hfile,USING$("&",message(y))
                     NEXT y
                    CLOSE #hfile
                    STDOUT "   email saved"
                    
                    SLEEP(30)
                END IF
    'delete the email from the server
    'unremark the next line to delete the email from the pop3 server
    !
    'Pop3DeleteMessage (hTCP,x)
    
    getnextmessage:
            NEXT x
    errlevelexit=6
        END IF
    closeconnection:
        STDOUT "Logging out"
    
        Pop3Quit hTCP
        TCP CLOSE #hTcp
    
        STDOUT "Logged out of server..."
    finished:
        FUNCTION=errlevelexit
        STDOUT "ERRLEVEL"+STR$(errlevelexit)+" returned"
        STDOUT exiterrlevelmessage(errlevelexit)
        STDOUT "Finished!..."
        'SLEEP(5000)
        STDOUT "press key to continue"
        WAITKEY$
    END FUNCTION
    Last edited by Paul Purvis; 22 May 2008, 03:18 PM.
    p purvis

    Comment

    Working...
    X