Sample POP/400 RPG Exit Program - POPEX003C/POPEX003R - Support

Sample POP/400 RPG Exit Program - POPEX003C/POPEX003R

From Support

Jump to: navigation, search

The following RPG Sample Program can be used to read thru all lines in a retreived POP/400 message member. Thie sample reads all email messages from a POP3 account and then calls program POPEX003C which then calls POPEX003R to process each line of the email message. In POPEX003R you would write any custom logic to parse the email message text.

Contents

Requirements

The POP/400 library RJSPOP3 version 1.10 or above is needed.

Calling POPGET and then calling POPEX003C/POPEX003R for each message downloaded

This command line connects to a POP3 server, retrieves all messages and then processes them with program POPEX003C. For our example we do not delete messages after download, but in production you should normally do so.

ADDLIBLE RJSPOP3

POPGET POP3HOST('1.1.1.1') USER('test@yourcompany.com') PASSWORD('test')
GETMSGHDRS(*YES) GETMESSAGE(*YES) DELETEMSG(*YES) LOGSESSION(*YES) 
DSPSESSION(*YES) EXITPGM RJSPOP3/POPEX003C)                                                   

Sample CL Program - POPEX003C

/********************************************************************/
/* This is a sample exit program that is called directly after a    */
/* new message is created from the POPGET command.                  */
/*                                                                  */
/* Parm 1: AS/400 Message File                                      */
/* Parm 2: AS/400 Message File Library                              */
/* Parm 3: AS/400 Message File Mamber                               */
/* Parm 4: Email Message Date  (Date:)                              */
/* Parm 5: Email Message Author (From:)                             */
/* Parm 6: Email Message Recip (To:)                                */
/* Parm 7: Email Message Subject (Subject:)                         */
/********************************************************************/
             PGM        PARM(&IFILE &ILIB &IMBR &IDATE &IFROM &ITO +  
                          &ISUBJECT)                                  
                                                                      
/* DECLARE PARAMETERS */     

             DCL        VAR(&IFILE) TYPE(*CHAR) LEN(10)               
             DCL        VAR(&ILIB) TYPE(*CHAR) LEN(10)                
             DCL        VAR(&IMBR) TYPE(*CHAR) LEN(10)                
             DCL        VAR(&IDATE) TYPE(*CHAR) LEN(100)              
             DCL        VAR(&IFROM) TYPE(*CHAR) LEN(150)              
             DCL        VAR(&ITO) TYPE(*CHAR) LEN(150)                
             DCL        VAR(&ISUBJECT) TYPE(*CHAR) LEN(150)           
                                                                      
             MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(ERRORS))      
                                                                      
/***************************************************************/     
/* DO SOME PROCESSING                                          */     
/* OUR SAMPLE SIMPLY SENDS BACK INFO MESSAGES TO THE JOB LOG   */     
/***************************************************************/     
             OVRDBF     FILE(POPMSG) TOFILE(&ILIB/&IFILE) MBR(&IMBR)  
             CALL       PGM(POPEX003R)                                
             DLTOVR     FILE(POPMSG)                                  

                                                                       
/***************************************************************/     
/* REMOVE MEMBER IF YOU DON'T WANT TO KEEP IT                  */     
/***************************************************************/     
/**            RMVM       FILE(&ILIB/&IFILE) MBR(&IMBR)     ****/     
                                                                      
/***************************************************************/     
/* NORMAL END OF PROCESSING                                    */     
/***************************************************************/     
             RETURN                                                   
                                                                      
/***************************************************************/     
/* HANDLE ERRORS                                               */     
/***************************************************************/     
ERRORS:                                                               
                                                                      
   /* SEND EXIT MESSAGE ON ERROR */                                   
             SNDPGMMSG  MSGID(POP9898) MSGF(POPMSGF) MSGDTA('Errors + 
                          occurred during POP/400 exit point +        
                          message processing for msg Member:' |< +    
                          &ILIB |< '/' |< &IFILE |< '.' |< &IMBR) +   
                          TOUSR(*SYSOPR)                              
             ENDPGM                                                   

Sample RPG Program - POPEX003R

     ********************************************************************* 
     * Program Name: POPEX003R                                             
     * Purpose: Read All Lines from Selected Message                       
     * MOD LEVEL:  1.00                                                    
     * MOD DATE:   xx/xx/xxxx                                              
     * MOD DESC:   Initial Dev                                             
     ********************************************************************* 
    FPopMsg    IF   F  500        Disk                                     
                                                                       
    D WorkFld         S            500A                                    
                                                                       
    IPopMsg    AA  01                                                      
    I                                  1  500  InData                      
     *---------------------------------------------------------------------
     * Main Program Processing                                             
     *---------------------------------------------------------------------
     *---------------------------------------------------------------------
     * Incoming Parameter List                                             
     *---------------------------------------------------------------------
                                                                          
     *---------------------------------------------------------------------
     * Read all relevent message text lines and do something with them     
     *---------------------------------------------------------------------
     * Don't start reading until after Content-Type: text/plain record     
    C                   Z-add     0             EOF1              1 0      
    C                   Z-add     0             CurLn             5 0      
    C                   Z-add     0             StartInput        1 0      
    C                   Z-add     1000          MaxLines          5 0      
                                                                      
    C*                  ** Read until entire message read or 1000 lines    
    C*                  ** whichever comes first.                          
    C                   DOW       EOF1 = 0 AND                             
    C                             CurLn <= MaxLines                        
                                                                      
    C                   READ      PopMsg                                 70
    C   70              Z-ADD     1             EOF1                       
    C                   IF        EOF1 = 0                                 
                                                                      
    C*                  ** If we're past Content-Type record               
    C*                  ** then we can process any lines as needed         
    C*                  ** Parse the InData field to get any               
    C*                  ** relevent information from the message line      
    C*                  ** In our example we just move the line input      
    C*                  ** data in InData to the field WorkFld             
    C                   IF        StartInput = 1                           
    C                   Eval      CurLn = CurLn + 1                        
    C                   MOVEL     InData        WorkFld                    
    C                   Endif  
                                           
    C*                  ** If StartInput = 0 then we will scan to          
    C*                  ** see if this is the Content-Type: record.        
    C*                  ** This line signals the beginning of text data    
    C                   IF        %SCAN('Content-Type: text/plain;':       
    C                                   InData) > 0                        
    C                   Eval      StartInput = 1                           
    C                   Endif                                              
                                                                      
    C                   ENDIF                                              
                                                                        
    C                   ENDDO                                              
                                                                        
    C                   Eval      *INLR = *ON                              
    C                   RETURN                                             
This article has been proofread by Jordan as of 12:04, 18 June 2007 (Central Daylight Time)
Personal tools