Overblog Tous les blogs Top blogs Technologie & Science Tous les blogs Technologie & Science
Editer l'article Suivre ce blog Administration + Créer mon blog
MENU

This is a bunch of tips and techniques related to Oracle PL/SQL and Forms.

Publicité

A bean to read a POP3 server

Purpose

Here is a Java bean that allows querying a POP3 server

POP3 reader

It uses the commons-net-1.4.1.jar JAR file from the Jakarta project.
http://jakarta.apache.org/site/downloads/downloads_commons-net.cgi .

This bean does not use all the functionnalities of the org.apache.commons.net.pop3 classes.
See the documentation provided on the original site to get all availables methods.


The Java code

     POP3Reader.java



The implementation class of the Bean Item

     oracle.forms.fd.POP3Reader


The methods you can call



Set the login information and get the messages
  
 
Set_Custom_Property( 'BL.BEAN', 1, 'SET_LOGIN_INFO', 'login_info' );

login_info is : POP3 server name, username, password
  


e.g. :
LC$Log := 'pop3.free.fr,me@free.fr,my_password' ;
Set_Custom_Property( 'BL.BEAN', 1, 'SET_LOGIN_INFO', LC$Log ) ;
   
 

Clear the message list

Set_Custom_Property( 'BL.BEAN', 1, 'CLEAR_LIST', '' );

Set the maximum length of the message body retrieved

Set_Custom_Property( 'BL.BEAN', 1, 'SET_MAX_LENGTH', 'max_length' );

login_info is : POP3 server name, username, password


e.g. :
Set_Custom_Property( 'BL.BEAN', 1, 'SET_MAX_LENGTH', '32000' ) ;
   
 


Set the message number to get

Set_Custom_Property( 'BL.BEAN', 1, 'SET_MESSAGE', 'num_message' );

In order to get the message content (header and body), you have to set the message number.

e.g. :
Set_Custom_Property( 'BL.BEAN', 1, 'SET_MESSAGE', '3' ) ;
   
 



The properties you can get



Get the total amount of messages available

char := Get_Custom_Property( 'BL.BEAN', 1, 'GET_MESSAGE_COUNT' )  ;

 

  
 
 

 

 

Get the header of the preselected message

LC$Line := Get_Custom_Property( 'BL.BEAN', 1, 'GET_HEADER' )  ;

the string returned contains the subject, from and date information.
The separator is the ^ character.
the sample form contain a function (Split) that is similar to the StringTokenizer Java function

e.g. :
LC$Line := Get_Custom_Property( 'BL.BEAN', 1, 'GET_HEADER' )  ;  
:ENTRIES.SUBJECT := Split( LC$Line, 1, '^' ) ;
:ENTRIES.MFROM := Split( LC$Line, 2, '^' ) ;
:ENTRIES.MDATE := Split( LC$Line, 3, '^' ) ;
   
 

Get the text of the preselected message

char := Get_Custom_Property( 'BL.BEAN', 1, 'GET_MESSAGE' )  ;


e.g. :
message := Get_Custom_Property( 'BL.BEAN', 1, 'GET_MESSAGE' )
   
 

The event received from the Bean

SENDMSG

 

This event tells Forms that a message is sent by the Java Bean.
You can get it in a WHEN-CUSTOM-ITEM-EVENT event:

Declare
 LC$Text        Varchar2(200);
 LC$Rec         Varchar2(10) ;
 LC$Count       Varchar2(10) ; 
 LC$Line        Varchar2(1024);
 eventValues    ParamList;
 eventValueType Number;
Begin
  -- get the message info --
  eventValues := get_parameter_list(:system.custom_item_event_parameters);
  get_parameter_attr(eventValues,'MSGINFO',eventValueType, LC$Text);
  get_parameter_attr(eventValues,'MSGNUM',eventValueType, LC$Rec);
  get_parameter_attr(eventValues,'MSGCOUNT',eventValueType, LC$Count);
  clear_message;
  Message(LC$Text, no_acknowledge) ;

  Set_Custom_Property( 'BL.BEAN', 1, 'SET_MESSAGE', LC$Rec );
 LC$Line := Get_Custom_Property( 'BL.BEAN', 1, 'GET_HEADER' )  ; 
 Go_Block('ENTRIES');
  If To_Number(LC$Rec) > 1 Then Create_Record ; End if ;
 :ENTRIES.NUM := LC$Rec ;
 :ENTRIES.SUBJECT := Split( LC$Line, 1, '^' ) ;
 :ENTRIES.MFROM := Split( LC$Line, 2, '^' ) ;
 :ENTRIES.MDATE := Split( LC$Line, 3, '^' ) ;  
 :ENTRIES.TEXT  := Substr(
                   Get_Custom_Property( 'BL.BEAN', 1, 'GET_MESSAGE' )
                   ,1, 32000 ) ;
 
  Synchronize ;
  If LC$Rec = LC$Count Then
    First_Record ;
    Set_Block_Property('ENTRIES', INSERT_ALLOWED, PROPERTY_FALSE ) ;
    Set_Block_Property('ENTRIES', UPDATE_ALLOWED, PROPERTY_FALSE ) ;    
  End if ;
End;

Java security policy

You need to add the following line to your .../Java/jre1.5.0_11/lib/security/java.policy file:

   permission java.security.AllPermission;

 


The sample dialog

     . Download the pop3reader.zip file
     . Unzip the file
     . copy both commons-net-1.4.1.jar and POP3Reader.jar files in the <ORACLE_HOME>/forms/java directory
     . Edit your /forms/server/formsweb.cfg file
     . Open the pop3reader.fmb module (Oracle Forms 10.1 .2)
     . Compile all and run the module


Publicité
Retour à l'accueil
Partager cet article
Repost0
Pour être informé des derniers articles, inscrivez vous :
Commenter cet article