Oracle Email Application Developer's Guide Release 2 (9.0.4) Part Number B10721-01 |
|
|
View PDF |
This chapter describes the Oracle Email JAVA APIs that can be used to create customized clients, integrate applications, and support certain extensions.
This chapter contains the following topics:
The Oracle Javamail API (OJMA) Service Provider implements the abstract JavaMailTM 1.2 API (JMA) provided by Sun Microsystems, Inc., and is designed to integrate directly with the mail store in the Oracle database. This approach does not depend upon a standards-based protocol server and calls PL/SQL APIs in the mail store over JDBC.
JMA provides a set of abstract classes that model a mail system. The API provides a platform independent and protocol independent framework to build Java technology-based mail and messaging applications. The JMA implementations typically go over a standards-based protocol such as IMAP or POP3. The JMA is implemented as a Java platform optional package and is also available as part of the Java 2 platform, Enterprise Edition. More details are available at the following URL:
http://java.sun.com/products/javamail
Within JMA, a user connects to a message store. The store contains a list of folders, and a user can perform folder and message operations based on the IMAP Protocol (RFC 2060).
In addition to the standard functionality available with JMA operating over an IMAP protocol service provider, the Oracle Javamail API Service Provider supports several extensions to the IMAP protocol and JMA. These enhancements do not interfere with the basic JMA interface, and clients using basic JMA can seamlessly integrate with the Oracle Javamail API Service Provider.
Oracle Javamail API Service Provider supports the following enhancements:
Also, because the Oracle Javamail API Service provider works directly with the Oracle database, system requirements are reduced since there is no overhead involved in conversing with a standards-based server, such as IMAP or POP3, and tasks such as sorting, lookups, and message sharing are efficiently handled by the Oracle database.
This section provides the following examples for using the JavaMail API:
The following example shows how to read all the messages for a particular user's inbox:
import java.util.*; import javax.mail.*; import javax.mail.internet.*; import java.io.*; import oracle.mail.ldap.ESDSConstants; import oracle.mail.sdk.esmail.OracleAuthenticator; public class ReadMessage { static String password = null; static String user = null; static String ldapHost = null; static int ldapPort = -1; static String mbox = "INBOX"; public static void main (String argv[]) throws Exception { for (int i = 0; i < argv.length; i++) { if (argv[i].equals("-U")) user = argv[++i]; else if (argv[i].equals("-P")) password = argv[++i]; else if (argv[i].equals("-D")) ldapHost = argv[++i]; else if (argv[i].equals("-I")) ldapPort = Integer.parseInt(argv[++i]); else if (argv[i].equals("--")) { i++; break; } else if (argv[i].startsWith("-")) { System.out.println( "Usage: ReadMessage [-D ldapHost] [-I ldapPort] [-U user] [-P password]"); System.exit(1); } else { break; } } Properties props = System.getProperties(); // Set system properties - it is necessary to set up these // properties to obtain the database connect information // from oid. The database connect information is available only // to privileged users. // NOTE: The password may be different // for your installation. props.setProperty("oracle.mail.ldap.admin_ dn","cn=umadmin,cn=emailservercontainer,cn=products,cn=oraclecontext"); props.setProperty("oracle.mail.ldap.admin_password","umadmin"); Session session = Session.getDefaultInstance(props,new OracleAuthenticator()); session.setDebug(true); Store store = null; store = session.getStore("esmail"); if (user != null && password != null && ldapPort != 0 && ldapHost != null){ store.connect(ldapHost, ldapPort, user, password); // Open the folder - after store has connected Folder folder = store.getDefaultFolder(); folder = folder.getFolder(mbox); if (folder == null) { System.out.println("Invalid folder"); System.exit(1); } else { System.out.println("Folder name : " + folder.getName()); } // try to open read/write and if that fails try read-only try { folder.open(Folder.READ_WRITE); } catch (MessagingException ex) { folder.open(Folder.READ_ONLY); } int totalMessages = folder.getMessageCount(); if (totalMessages == 0) { System.out.println("Empty folder"); folder.close(false); store.close(); System.exit(1); } else { System.out.println("Total messages: " + totalMessages); Message[] msgs = folder.getMessages(); if (msgs != null) System.out.println("ReadMessage: Number of messages: " + msgs.length); int my_uid = 0; for (int i = 0; i < msgs.length; i++) { System.out.println("----------------------------"); System.out.println("This is the message uid# : " + (int)msgs[i].getMessageNumber()); my_uid = msgs[i].getMessageNumber(); if (my_uid > 0) { Message msg = folder.getMessage(my_uid); System.out.println("Sent Date: " + msg.getSentDate()); System.out.println("Msg Size: " + msg.getSize()); System.out.println("Received Date: " + msg.getReceivedDate()); dumpPart(msg); } else { System.out.println("No messages returned"); } } //end for } } } public static void dumpPart(Part p) throws Exception { if (p instanceof Message) dumpEnvelope((Message)p); System.out.println("----------------------------"); pr("CONTENT-TYPE: " + p.getContentType()); if (p.isMimeType("text/plain")) { pr("This is plain text"); pr("---------------------------"); System.out.println((String)p.getContent()); } else if (p.isMimeType("multipart/*")) { pr("This is a Multipart"); pr("---------------------------"); Multipart mp = (Multipart)p.getContent(); int count = mp.getCount(); for (int i = 0; i < count; i++) dumpPart(mp.getBodyPart(i)); } else if (p.isMimeType("message/rfc822")) { pr("This is a Nested Message"); pr("---------------------------"); dumpPart((Part)p.getContent()); } else if (p.isMimeType("image/jpeg")) { pr("--------> image/jpeg"); Object o = p.getContent(); if (o instanceof InputStream) { } InputStream x = (InputStream)o; // Construct the required byte array System.out.println("x.length = " + x.available()); int i = 0; byte[] bArray = new byte[x.available()]; while ((i = (int)((InputStream)x).available()) > 0) { int result = (int)(((InputStream)x).read(bArray)); if (result == -1) break; } FileOutputStream f2 = new FileOutputStream("/tmp/image.jpg"); f2.write(bArray); } else { Object o = p.getContent(); if (o instanceof String) { pr("This is a string"); pr("---------------------------"); System.out.println((String)o); } else if (o instanceof InputStream) { pr("This is just an input stream"); pr("---------------------------"); InputStream is = (InputStream)o; is = (InputStream)o; int c; while ((c = is.read()) != -1) System.out.write(c); } else { pr("This is an unknown type"); pr("---------------------------"); pr(o.toString()); } } } public static void dumpEnvelope(Message m) throws Exception { pr("This is the message envelope"); pr("---------------------------"); Address[] a; // FROM if ((a = m.getFrom()) != null) { for (int j = 0; j < a.length; j++) pr("FROM: " + a[j].toString()); } // TO if ((a = m.getRecipients(Message.RecipientType.TO)) != null) { for (int j = 0; j < a.length; j++) pr("TO: " + a[j].toString()); } // SUBJECT if (m.getSubject() != null) pr("SUBJECT: " + m.getSubject()); // DATE Date d = m.getSentDate(); pr("SendDate: " + (d != null ? d.toString() : "UNKNOWN")); } public static void pr(String s){ System.out.println(s); } }
The following example shows how to create a shared folder and grant permissions to a user. The shared folder name and the user (grantee) are taken in as parameters in addition to the shared folder owner and the owner password.
import java.util.*; import javax.mail.*; import javax.mail.internet.*; import java.io.*; import oracle.mail.sdk.esmail.*; public class SharedFolderCreate { static String password = null; static String user = null; static String aSharedFolderUser = null; static String aSharedFolderName = null; static String ldapHost = null; static int ldapPort = -1; static String mbox = "INBOX"; public static void main (String argv[]) throws Exception { for (int i = 0; i < argv.length; i++) { if (argv[i].equals("-U")) user = argv[++i]; else if (argv[i].equals("-P")) password = argv[++i]; else if (argv[i].equals("-S")) aSharedFolderUser = argv[++i]; else if (argv[i].equals("-N")) aSharedFolderName = argv[++i]; else if (argv[i].equals("--")) { i++; break; } else if (argv[i].startsWith("-")) { System.out.println( "Usage: SharedFolderCreate [-U user] [-P password] [-S sharedFolderUser] [-N sharedFolderName]"); System.exit(1); } else { break; } } // This property is used to set the default oracle home // in the iasv2 environment. The default ldap host and // ldap port information is picked up from the // $ORACLE_HOME/config/ias.properties config file // In the store.connect method, the ldapHost is set to // null and the ldapPort is set to -1 to make sure that // the default values are used. In this example, the oracle // home is retrieved from a system level ORACLE_HOME // property. Properties props = System.getProperties(); String orclHome = System.getProperty("ORACLE_HOME"); props.setProperty("oracle.mail.ldap.oracle_home",orclHome); Session session = Session.getDefaultInstance(props,null); session.setDebug(true); Store store = null; store = session.getStore("esmail"); if (user != null && password != null){ store.connect(null, -1, user, password); // Open the folder - after store has connected Folder folder = store.getFolder(aSharedFolderName); if (!folder.exists()) { System.out.println("Folder does not exist"); folder.create(Folder.HOLDS_MESSAGES); } System.out.println("Folder name : " + folder.getName()); System.out.println("Creating Shared Folder"); ((OracleFolder)folder).addACI(aSharedFolderUser, OracleACI.READACI); //((OracleFolder)folder).modifyACI(aSharedFolderUser, OracleACI.READACI + OracleACI.WRITEACI); System.out.println("Done Creating Shared Folder"); } } }
The following example shows how to append a simple message to a user's inbox.
import java.io.*; import java.net.InetAddress; import java.util.Properties; import java.util.Date; import javax.mail.*; import javax.mail.internet.*; public class TestAppendMime { static String password = null; static String user = null; static String host = null; static String ldapHost = null; static int ldapPort = -1; static String mbox = "INBOX"; public static void main(String[] argv) throws Exception{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); for (int i = 0; i < argv.length; i++) { if (argv[i].equals("-U")) user = argv[++i]; else if (argv[i].equals("-P")) password = argv[++i]; else if (argv[i].equals("-D")) ldapHost = argv[++i]; else if (argv[i].equals("-I")) ldapPort = Integer.parseInt(argv[++i]); else if (argv[i].equals("--")) { i++; break; } else if (argv[i].startsWith("-")) { System.out.println( "Usage: TestAppendMime [-D ldapHost] [-I ldapPort] [-U user] [-P password]"); System.exit(1); } else { break; } } Properties props = System.getProperties(); // Set system properties - it is necessary to set up these // properties to obtain the database connect information // from oid. The database connect information is available only // to privileged users. // NOTE: The password may be different // for your installation. props.setProperty("oracle.mail.ldap.admin_ dn","cn=umadmin,cn=emailservercontainer,cn=products,cn=oraclecontext"); props.setProperty("oracle.mail.ldap.admin_password","umadmin"); // Get a Session object Session session = Session.getDefaultInstance(props, null); session.setDebug(true); Store store = null; store = session.getStore("esmail"); System.out.println(ldapHost + "\n" + ldapPort + "\n" + user + "\n" + password); store.connect(ldapHost, ldapPort, user, password); // Get record Folder. Create if it does not exist. Folder folder = store.getFolder("INBOX"); Message msg = new MimeMessage(session); msg.setFrom(new InternetAddress("oracle@oracle.com")); msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse("testuser1@umdev.us.oracle.com", false)); msg.setSubject("Welcome!!!"); //collect(in, msg); msg.setText("Hello welcome\n"); msg.setSentDate(new Date()); System.out.println("Total Number of messages : " + folder.getMessageCount()); Message[] msgs = new Message[1]; msgs[0] = msg; folder.appendMessages(msgs); System.out.println("Total Number of messages : " + folder.getMessageCount()); System.out.println("Mail was recorded successfully."); } public static void collect(BufferedReader in, Message msg) throws MessagingException, IOException { String line; StringBuffer sb = new StringBuffer(); while ((line = in.readLine()) != null) { sb.append(line); sb.append("\n"); } // If the desired charset is known, you can use // setText(text, charset) msg.setText(sb.toString()); } }
The following example shows folder operations. The basic functionality of creating folder, copying messages to folder, listing folders, renaming folders, and deleting messages are demonstrated through this script.
/ public class TestFolder { static String password = null; static String user = null; static String host = null; static int port = -1; static String mbox = "INBOX"; static String root = null; static boolean recursive = false; static String pattern = "*"; static boolean verbose = false; static String namespace = null; public static void main (String argv[]) throws Exception { for (int i = 0; i < argv.length; i++) { if (argv[i].equals("-U")) user = argv[++i]; else if (argv[i].equals("-P")) password = argv[++i]; else if (argv[i].equals("-D")) host = argv[++i]; else if (argv[i].equals("-I")) port = Integer.parseInt(argv[++i]); else if (argv[i].equals("--")) { i++; break; } else if (argv[i].startsWith("-")) { System.out.println( "Usage: TestFolder [-D ldap_host] [-I ldap_port] [-U user] [-P password]"); System.exit(1); } else { break; } } Properties props = System.getProperties(); Session session = Session.getDefaultInstance(props,null); session.setDebug(false); Store store = null; store = session.getStore("esmail"); if (user != null && password != null && port != 0 && host != null){ store.connect(host, port, user, password); namespace = user.substring(0, user.indexOf('@')); // Open the folder - after store has connected Folder folder = store.getDefaultFolder(); if (folder == null) { System.out.println("Invalid folder"); System.exit(1); } else { /*** List folders ***************/ Folder[] f = folder.list(pattern); for (int i = 0; i < f.length; i++) { System.out.println("Name: " + f[i].getName()); System.out.println("Full Name: " + f[i].getFullName()); } /*** Create folder ***************/ System.out.println("Creating folder xyz"); Folder aFolder = store.getFolder("/" + namespace + "/xyz"); if (!aFolder.exists()) //create { System.out.println("Creating folder...."); aFolder.create(Folder.HOLDS_MESSAGES); } Folder aNewFolder = store.getFolder("/" + namespace + "/temp"); /****** Renaming Folder ***************/ System.out.println("Renaming Folder to temp"); aFolder.renameTo(aNewFolder); /***** List folder again **************/ f = folder.list(pattern); for (int i = 0; i < f.length; i++) { System.out.println("Name: " + f[i].getName()); System.out.println("Full Name: " + f[i].getFullName()); } /***** Copy messages into folder ****/ Folder mbox = store.getFolder("/" + namespace + "/INBOX"); mbox.open(Folder.READ_WRITE); Message[] msgArray = new Message[3]; System.out.println("********" + mbox.getMessageCount()); //Message[] mboxArray = new Message[mbox.getMessageCount()]; for (int j = 0; j < 3; j++) msgArray[j] = mbox.getMessage(j+1); //msgArray = mbox.getMessages(1,3); mbox.copyMessages(msgArray, aFolder); /***** Get message count **********/ System.out.println("Number of messages in folder " + aFolder.getFullName() + " is " + aFolder.getMessageCount()); /***** delete messages in folder ****/ System.out.println("DELETING two MESSAGES "); System.out.println("---> Number of messages in folder after delete " + aFolder.getFullName() + " is " + aFolder.getMessageCount()); aFolder.open(Folder.READ_WRITE); Message aMessage = aFolder.getMessage(1); Message aMessage2 = aFolder.getMessage(2); aMessage.setFlag(Flags.Flag.DELETED,true); aMessage2.setFlag(Flags.Flag.DELETED,true); /******* expunge folder *************/ System.out.println("EXPUNGING"); aFolder.expunge(); aFolder.close(true); System.out.println("---> Number of messages in folder after expunge " + aFolder.getFullName() + " is " + aFolder.getMessageCount()); /******* msg count of folder ********/ /***** List folder again **************/ System.out.println("***********LIST ***********"); f = folder.list(pattern); for (int i = 0; i < f.length; i++) { System.out.println("Name: " + f[i].getName()); System.out.println("Full Name: " + f[i].getFullName()); } /****** Delete Folder *******/ System.out.println("*********** DELETE ***********"); aFolder.delete(true); /***** List folder again **************/ f = folder.list(pattern); for (int i = 0; i < f.length; i++) { System.out.println("Name: " + f[i].getName()); System.out.println("Full Name: " + f[i].getFullName()); } } } store.close(); } public static void dumpFolder(Folder folder, boolean recurse, String tab) throws Exception { System.out.println(tab + "Name: " + folder.getName()); System.out.println(tab + "Full Name: " + folder.getFullName()); System.out.println(tab + "URL: " + folder.getURLName()); if (verbose) { if (!folder.isSubscribed()) System.out.println(tab + "Not Subscribed"); if ((folder.getType() & Folder.HOLDS_MESSAGES) != 0) { if (folder.hasNewMessages()) System.out.println(tab + "Has New Messages"); System.out.println(tab + "Total Messages: " + folder.getMessageCount()); System.out.println(tab + "New Messages: " + folder.getNewMessageCount()); System.out.println(tab + "Unread Messages: " + folder.getUnreadMessageCount()); } if ((folder.getType() & Folder.HOLDS_FOLDERS) != 0) System.out.println(tab + "Is Directory"); } System.out.println(); if ((folder.getType() & Folder.HOLDS_FOLDERS) != 0) { if (recurse) { Folder[] f = folder.list(); for (int i = 0; i < f.length; i++) dumpFolder(f[i], recurse, tab + " "); } } } }
SharedFolderRead.java import java.util.*; import javax.mail.*; import javax.mail.internet.*; import java.io.*;
The following example shows basic shared folder and fetch message fetching functionality:
public class SharedFolderRead { static String user = null; static String password = null; static String ldapHost = null; static int ldapPort = -1; static String mbox = "INBOX"; static String pattern = "*"; public static void main (String argv[]) throws Exception { for (int i = 0; i < argv.length; i++) { if (argv[i].equals("-U")) user = argv[++i]; else if (argv[i].equals("-P")) password = argv[++i]; else if (argv[i].equals("-D")) ldapHost = argv[++i]; else if (argv[i].equals("-I")) ldapPort = Integer.parseInt(argv[++i]); else if (argv[i].equals("--")) { i++; break; } else if (argv[i].startsWith("-")) { System.out.println( "Usage: SharedFolderRead [-D ldap_host] [-I ldap_port] [-U user] [-P password]"); System.exit(1); } else { break; } } Properties props = System.getProperties(); // Set system properties - it is necessary to set up these // properties to obtain the database connect information // from oid. The database connect information is available only // to privileged users. // NOTE: The passwordmay be different // for your installation. props.setProperty("oracle.mail.ldap.admin_ dn","cn=umadmin,cn=emailservercontainer,cn=products,cn=oraclecontext"); props.setProperty("oracle.mail.ldap.admin_password","umadmin"); Session session = Session.getDefaultInstance(props,null); session.setDebug(false); Store store = null; store = session.getStore("esmail"); if (user != null && password != null && ldapPort != 0 && ldapHost != null){ store.connect(ldapHost, ldapPort, user, password); Folder aLocalFolder = store.getFolder(mbox); if (aLocalFolder == null) { System.out.println("NULL FOLDER " + mbox); System.exit(1); } else { System.out.println("Folder Name: " + aLocalFolder.getFullName()); } try { aLocalFolder.open(Folder.READ_WRITE); } catch (MessagingException ex) { aLocalFolder.open(Folder.READ_ONLY); } int totalMessages = aLocalFolder.getMessageCount(); System.out.println("Total Number of messages in folder " + aLocalFolder.getFullName() + " is " + totalMessages); Folder[] aSharedNSArray = store.getSharedNamespaces(); if (aSharedNSArray == null) { System.out.println("No shared namespaces"); System.exit(1); } else { //For each namespace, list System.out.println("Number of shared namespace : " + aSharedNSArray.length); Folder folder = null; for (int i = 0; i < aSharedNSArray.length; i++) { folder = aSharedNSArray[i]; System.out.println("Folder fullname : " + folder.getFullName()); } Folder[] f = folder.list(pattern); int aNum =0; for (int j = 0; j < f.length; j++) { System.out.println("Name: " + f[j].getName()); System.out.println("Full Name: " + f[j].getFullName()); aNum = j; try { f[aNum].open(Folder.READ_WRITE); } catch (MessagingException ex) { f[aNum].open(Folder.READ_ONLY); } System.out.println("Shared Folder fullname : " + f[aNum].getFullName()); // Select and fetch messages from Shared Folder int total_messages = f[aNum].getMessageCount(); System.out.println("Number of messages in " + f[aNum].getFullName() + " is " + f[aNum].getMessageCount()); if (total_messages == 0) { System.out.println("Empty folder " + f[aNum].getFullName()); f[aNum].close(false); } else { int my_uid = 0; Message[] msgs = f[aNum].getMessages(); if (msgs != null) System.out.println("Number of messages : " + msgs.length); for (int i = 0; i < msgs.length; i++) { my_uid = msgs[i].getMessageNumber(); System.out.println("MSG_NUMBER : " + my_uid); if (my_uid > 0) { System.out.println("Retrieving msg_num : " + my_uid); Message msg = f[aNum].getMessage(my_uid); dumpPart(msg); } } // Copy message from shared folder to local folder //System.out.println("----- BEFORE COPY -------"); //f[aNum].copyMessages(msgs, aLocalFolder); //System.out.println("----- AFTER COPY -------"); } } } } store.close(); } //Fetch message part by part public static void dumpPart(Part p) throws Exception { if (p instanceof Message) //pr("Envelope out of order------------>"); dumpEnvelope((Message)p); //InputStream is = p.getInputStream(); //System.out.println("SIZE of INPUT STREAM : " + is.available()); System.out.println("----------------------------"); pr("CONTENT-TYPE: " + p.getContentType()); if (p.isMimeType("text/plain")) { pr("This is plain text"); pr("---------------------------"); System.out.println((String)p.getContent()); } else if (p.isMimeType("multipart/*")) { pr("This is a Multipart"); pr("---------------------------"); Multipart mp = (Multipart)p.getContent(); int count = mp.getCount(); for (int i = 0; i < count; i++) dumpPart(mp.getBodyPart(i)); } else if (p.isMimeType("message/rfc822")) { pr("This is a Nested Message"); pr("---------------------------"); dumpPart((Part)p.getContent()); } else { Object o = p.getContent(); if (o instanceof String) { pr("This is a string"); pr("---------------------------"); System.out.println((String)o); } else if (o instanceof InputStream) { pr("This is just an input stream"); pr("---------------------------"); InputStream is = (InputStream)o; //is = (InputStream)o; int c; while ((c = is.read()) != -1) System.out.write(c); } else { pr("This is an unknown type"); pr("---------------------------"); pr(o.toString()); } } } public static void dumpEnvelope(Message m) throws Exception { pr("This is the message envelope"); pr("---------------------------"); Address[] a; // FROM if ((a = m.getFrom()) != null) { for (int j = 0; j < a.length; j++) pr("FROM: " + a[j].toString()); } // TO if ((a = m.getRecipients(Message.RecipientType.TO)) != null) { for (int j = 0; j < a.length; j++) pr("TO: " + a[j].toString()); } // SUBJECT pr("SUBJECT: " + m.getSubject()); // DATE Date d = m.getSentDate(); pr("SendDate: " + (d != null ? d.toString() : "UNKNOWN")); } public static void pr(String s){ System.out.println(s); } ////-------------- }
The directory management API is a set of Java classes that can be used to create, access, and manage various entries, such as mail users, public distribution lists, and private address book entries (contact information and private distribution lists). The entries are stored in Oracle Internet Directory for a given domain.
This section contains the following topics:
In Oracle Email, an e-mail system can contain more than one domain. Mail users and public distribution lists exist for a particular domain. A mail user for a given domain is a valid user in that domain who can send and receive e-mail and use all of the exposed e-mail server functionality.
A public distribution list is a mailing list that has its own e-mail ID and contains a group of e-mail IDs or other mailing lists. When an e-mail is sent to a public distribution list, all the members of the list receive the e-mail. A valid mail user can subscribe to any public distribution list.
Private address book entries consist of private contacts and private mailing lists belonging to a particular mail user.
A private distribution list consists of private contact information, such as the contact's phone number, e-mail ID, and address. Users can use the private address book entries from WebMail to send and receive e-mails. These entries are also used by the Calendar application.
Before a caller can access any of the directory components, they must be authenticated with the Oracle Internet Directory using the oracle.mail.OESContext
class
. Once authenticated, the oracle.mail.OESContext
instance representing a trusted session must be passed to all of the directory APIs.
The following example shows how to authenticate an application with the debug option turned off.
OESContext oesctx = new OESContext(DirectoryConstants.DS_CALLERTYPE_APP, false); //Authenticate to the directory oesctx.authenticate(null, args[0]);
Before an entry is created in the directory, the caller needs to retrieve the metadata for that particular entry from the directory. The metadata for a particular entry consists of the mandatory and optional attributes the caller must set in order to create an entry. It also contains information about all the attributes, such as the syntax, multiplicity of the attributes, and default values for attributes (if any defaults are set in the directory).
When the caller sets the attribute value on the metadata object, validation is performed to ensure that the caller sets the value of an attribute that is present in that particular entry. In UI-based applications using the metadata, the caller can perform any input validations for the data entered.
The following example shows how to retrieve the metadata. It assumes that ldapobj
is an instance of the DirectoryObject
class.
//Getting the mandatory attributes from the metadata if (ldapobj.getMandatoryAttribs() != null) { Enumeration enum = ldapobj.getMandatoryAttribs().elements(); while (enum.hasMoreElements()) { String attr = enum.nextElement().toString(); // Name of the attribute //Retrieve the metadata for this attribute DirectoryAttributeMetaData mdata = ldapobj.getMetaData(attr); // The multiplicity of the attribute returns "SINGLE" or "MULTIPLE" String mult = mdata.getMultiplicity(); // Returns the syntax of the string, "String", "byte", "boolean" or "int" String syntax = mdata.getAttributeType(); //Returns a vector of String values if any default has been set, else returns null Vector defaultvals = mdata.getDefaultValues(); } }
Similarly, the ldapobj.getOptionalAttribs()
method returns the list of optional attributes and in a similar manner, the optional attributes and the metadata can be retrieved. After retrieving the metadata, the user can set the value of an attribute in the following manner. When creating an entry, the attribute value can be set using the setAttributeValue
method of the DirectoryObject class.
This example sets the value for the telephonenumber
attribute to the default values provided mdata.getDefaultValues()
is not null.
ldapobj.setAttributeValue("telephonenumber", mdata.getDefaultValues()); Vector newVals = new Vector(); newVals.add("408 7394050"); newVals.add("650 7394050"); ldapobj.setAttributeValue("telephonenumber", newVals);
While modifying an entry, the attribute value can be set using the modifyAttributeValue
method of the DirectoryObject class. The caller needs to specify the type of modification.
The permitted modifications are:
DirectoryConstants.DS_MODIFY_ADD
: This adds the given set of values to the existing valuesDirectoryConstants.DS_MODIFY_DELETE
: This deletes the given set of values from the existing valuesDirectoryConstants.DS_MODIFY_REPLACE
: This replaces all the existing values with a new set of valuesThis example adds two new values for the telephonenumber
attribute.
Vector newVals = new Vector(); newVals.add("408 7394050"); newVals.add("650 7394050"); ldapobj.modifyAttributeValue("telephonenumber", newVals, DirectoryConstants.DS_ MODIFY_ADD);
This section provides following examples for Directory Management APIs.
Note: To run these examples, the CLASSPATH environment variable must include |
The following examples show how to use the mail user APIs to create, modify, look up, and delete a mail user.
This example creates a mail user. The attributes of the mail user are set to default values. This example shows how to set values of an attribute to a non default value by setting the orclMailVoiceQuota
parameter.
*/ import java.util.Enumeration; import java.util.Vector; import oracle.mail.OESContext; import oracle.mail.sdk.ldap.DirectoryAccess; import oracle.mail.sdk.ldap.DirectoryAttributeMetaData; import oracle.mail.sdk.ldap.DirectoryConstants; import oracle.mail.sdk.ldap.DirectoryException; import oracle.mail.sdk.ldap.DirectoryObject; class CreateMailUser { public static void main(String[] args) { if (args.length < 3) { System.out.println("Usage: java CreateMailUser <ORAHOME> <mailid> <publicuserdn>"); System.exit(1); } try { OESContext oesctx = new OESContext( DirectoryConstants.DS_CALLERTYPE_APP, false); //Authenticate to the directory if (oesctx.authenticate(null, args[0]) != true) { System.err.println("APP authentication failed"); System.exit(1); } else { DirectoryAccess access = new DirectoryAccess(); String mail = args[1]; String domain = null; if (mail.indexOf('@') != -1) { domain = mail.substring(mail.indexOf('@') + 1, mail.length()); //Retrieve Metadata DirectoryObject ldapobj = access.GetMailUserMetaData( oesctx, domain); System.out.println("Retrieved Metadata."); System.out.println("Setting mandatory attributes of the mailuser."); //Set mandatory and optional attributes of a mailuser to defaults if (ldapobj.getMandatoryAttribs() != null) { Enumeration enum = ldapobj.getMandatoryAttribs().elements(); while (enum.hasMoreElements()) { String attr = enum.nextElement().toString(); DirectoryAttributeMetaData mdata = ldapobj.getMetaData(attr); if (attr.equalsIgnoreCase("mail")) { Vector vals = new Vector(); vals.add(mail); ldapobj.setAttributeValue(attr, vals); continue; } else { ldapobj.setAttributeValue(attr, mdata.getDefaultValues()); continue; } } } System.out.println("Setting optional attributes of the mailuser."); if (ldapobj.getOptionalAttribs() != null) { Enumeration enum = ldapobj.getOptionalAttribs().elements(); while (enum.hasMoreElements()) { String attr = enum.nextElement().toString(); DirectoryAttributeMetaData mdata = ldapobj.getMetaData(attr); if (mdata.getDefaultValues() != null) ldapobj.setAttributeValue(attr, mdata.getDefaultValues()); } } //Setting voice quota to 40MB Vector vals = new Vector(); vals.add("40000000"); ldapobj.setAttributeValue("orclMailVoiceQuota", vals); System.out.println("Creating Mailuser .." + mail); //Create the mailuser access.CreateMailUser(oesctx, args[2], ldapobj); System.out.println("Created Mailuser .."); } } System.gc(); } catch (Exception e) { System.err.println("Error Occured " + e.getMessage()); System.gc(); } } }
This example performs a lookup for the mail user.
*/ import java.util.Vector; import oracle.mail.OESContext; import oracle.mail.sdk.ldap.DirectoryAccess; import oracle.mail.sdk.ldap.DirectoryAttributeMetaData; import oracle.mail.sdk.ldap.DirectoryConstants; import oracle.mail.sdk.ldap.DirectoryException; import oracle.mail.sdk.ldap.DirectoryObject; class ModifyMailUser { public static void main(String[] args) { if (args.length < 2) { System.out.println("Usage: java ModifyMailUser <ORAHOME> <mailid>"); System.exit(1); } try { OESContext oesctx = new OESContext( DirectoryConstants.DS_CALLERTYPE_APP, false); //Authenticate to the directory if (oesctx.authenticate(null, args[0]) != true) { System.err.println("APP authentication failed"); System.exit(1); } else { DirectoryAccess access = new DirectoryAccess(); DirectoryObject ldapObj = access.LookupMailUser(oesctx, args[1]); if (ldapObj != null) { //Retrieving Metadata of orclMailQuota attribute DirectoryAttributeMetaData mdata = ldapObj.getMetaData( "orclMailQuota"); //Retrieving the values of this attribute Vector values = mdata.getDefaultValues(); if (values != null) { for (int i = 0; i < values.size(); i++) System.out.println("orclMailQuota Values --> " + (String)values.elementAt(i)); } //Use DirectoryConstants.DS_MODIFY_DELETE to delete the given set of //values from the existing values of the attribute //DirectoryConstants.DS_MODIFY_REPLACE to replace the existing values // of the attribute with the new set of values //DirectoryConstants.DS_MODIFY_ADD to add the given set of values to //the existing values of the attribute //Setting mail quota to 100MB, this replaces the existing mail quota //with the new values values = new Vector(); values.add("100000000"); ldapObj.modifyAttributeValue("orclMailQuota", values, DirectoryConstants.DS_MODIFY_ REPLACE); System.out.println("Modifying Mailuser .."); access.ModifyMailUser(oesctx, args[1], ldapObj); System.out.println("Modified Mailuser .."); } } System.gc(); } catch (Exception e) { System.err.println("Error Occured " + e.getMessage()); System.gc(); } } }
This example deletes a mail user.
import oracle.mail.OESContext; import oracle.mail.sdk.ldap.DirectoryAccess; import oracle.mail.sdk.ldap.DirectoryConstants; import oracle.mail.sdk.ldap.DirectoryException; class DeleteMailUser { public static void main(String[] args) { if (args.length < 2) { System.out.println("Usage: java DeleteMailUser <ORAHOME> <mailid>"); System.exit(1); } try { OESContext oesctx = new OESContext( DirectoryConstants.DS_CALLERTYPE_APP, false); //Authenticate to the directory if (oesctx.authenticate(null, args[0]) != true) { System.err.println("APP authentication failed"); System.exit(1); } else { DirectoryAccess access = new DirectoryAccess(); System.out.println("Deleting User " + args[1]); //Deleting the mailuser access.DeleteMailUser(oesctx, args[1]); System.out.println("Deleted User "); } System.gc(); } catch (Exception e) { System.err.println("Error Occured " + e.getMessage()); System.gc(); } } }
This example queries for all mail users in a domain.
import java.util.Vector; import oracle.mail.OESContext; import oracle.mail.sdk.ldap.DirectoryAccess; import oracle.mail.sdk.ldap.DirectoryConstants; import oracle.mail.sdk.ldap.DirectoryException; class QueryMailUsers { public static void main(String[] args) { if (args.length < 2) { System.out.println("Usage: java QueryMailUsers <ORAHOME> <domain>"); System.exit(1); } try { OESContext oesctx = new OESContext( DirectoryConstants.DS_CALLERTYPE_APP, false); //Authenticate to the directory if (oesctx.authenticate(null, args[0]) != true) { System.err.println("APP authentication failed"); System.exit(1); } else { DirectoryAccess access = new DirectoryAccess(); System.out.println("Querying Users "); //Query for all mailusers, similarly other search criteria could also //be given for the query, for example, t* Vector users = access.QueryMailUsers(oesctx, "*", args[1]); if (users != null) { for (int i = 0; i < users.size(); i++) System.out.println("User " + (i + 1) + " " + (String)users.elementAt(i)); } else { System.out.println("Nothing matches the search criteria "); } } System.gc(); } catch (Exception e) { System.err.println("Error Occured " + e.getMessage()); System.gc(); } } }
This example creates a public distribution list in the directory. The attributes of the distribution list are set to the default values.
import java.util.Enumeration; import java.util.Hashtable; import java.util.Vector; import oracle.mail.OESContext; import oracle.mail.sdk.ldap.DirectoryAccess; import oracle.mail.sdk.ldap.DirectoryAttributeMetaData; import oracle.mail.sdk.ldap.DirectoryConstants; import oracle.mail.sdk.ldap.DirectoryException; import oracle.mail.sdk.ldap.DirectoryObject; class CreateDistributionList { public static void main(String[] args) { if (args.length < 4) { System.out.println("Usage: java CreateDistributionList <ORAHOME> <domain> <dl_mailid> <user_member_mailid>"); System.exit(1); }
try { OESContext oesctx = new OESContext( DirectoryConstants.DS_CALLERTYPE_APP, false); //Authenticate to the directory if (oesctx.authenticate(null, args[0]) != true) { System.err.println("APP authentication failed"); System.exit(1); } else { DirectoryAccess access = new DirectoryAccess(); DirectoryObject ldapobj = access.GetDistributionListMetaData( oesctx, args[1]); System.out.println("Retrieved Metadata."); System.out.println("Setting mandatory attributes of the DL."); if (ldapobj.getMandatoryAttribs() != null) { Enumeration enum = ldapobj.getMandatoryAttribs().elements(); while (enum.hasMoreElements()) { String attr = enum.nextElement().toString(); DirectoryAttributeMetaData mdata = ldapobj.getMetaData( attr); if (attr.equalsIgnoreCase("mail")) { Vector vals = new Vector(); vals.add(args[2]); ldapobj.setAttributeValue(attr, vals); continue; } else { ldapobj.setAttributeValue(attr, mdata.getDefaultValues()); continue; } } } System.out.println("Setting optional attributes of the DL."); if (ldapobj.getOptionalAttribs() != null) { Enumeration enum = ldapobj.getOptionalAttribs().elements(); while (enum.hasMoreElements()) { String attr = enum.nextElement().toString(); DirectoryAttributeMetaData mdata = ldapobj.getMetaData( attr); if (mdata.getDefaultValues() != null) ldapobj.setAttributeValue(attr, mdata.getDefaultValues()); } } System.out.println("Creating DL .." + args[2]); //Creating DL with one user member, similarly other types of members //could also be added Hashtable members = new Hashtable(); Vector usrs = new Vector(); usrs.add(args[3]); members.put(DirectoryConstants.DS_USER, usrs); // returns a hashtable of elements that couldn't be added Hashtable failed = access.CreateDistributionList(oesctx, ldapobj, members); System.out.println("Created DL .."); if (failed != null) { System.out.println("Some member additions failed."); } else { System.out.println("Successfully added all members."); } } System.gc(); } catch (Exception e) { System.err.println("Error Occured " + e.getMessage()); System.gc(); } } }
This example looks up the given distribution list and modifies an attribute of this existing public distribution list.
import java.util.Vector; import oracle.mail.OESContext; import oracle.mail.sdk.ldap.DirectoryAccess; import oracle.mail.sdk.ldap.DirectoryConstants; import oracle.mail.sdk.ldap.DirectoryException; import oracle.mail.sdk.ldap.DirectoryObject; class ModifyDistributionList { public static void main(String[] args) { if (args.length < 2) { System.out.println("Usage: java ModifyDistributionList <ORAHOME> <dl_mailid>"); System.exit(1); } try { OESContext oesctx = new OESContext( DirectoryConstants.DS_CALLERTYPE_APP, false); //Authenticate to the directory if (oesctx.authenticate(null, args[0]) != true) { System.err.println("APP authentication failed"); System.exit(1); } else { DirectoryAccess access = new DirectoryAccess(); System.out.println("Looking up DL.. " + args[1]); DirectoryObject ldapObj = access.LookupDistributionList(oesctx, args[1]); System.out.println("Found DL \n Printing Old Values of orclMailGroupInfoText"); Vector values = ldapObj.getAttributeValue("orclmailgroupinfotext"); if (values != null) { for (int i = 0; i < values.size(); i++) System.out.println("orclMailGroupInfoText Values --> " + (String)values.elementAt(i)); } else { System.out.println("No value set for orclMailGroupInfoText"); } System.out.println("Adding orclmailgroupinfotext to this DL"); //Use DirectoryConstants.DS_MODIFY_DELETE to delete the given set of //values from the existing values of the attribute //DirectoryConstants.DS_MODIFY_REPLACE to replace the existing values // of the attribute with the new set of values //DirectoryConstants.DS_MODIFY_ADD to add the given set of values to //the existing values of the attribute //Setting orclmailgroupinfotext to some new values values = new Vector(); values.add("Test DL"); ldapObj.modifyAttributeValue("orclmailgroupinfotext", values, DirectoryConstants.DS_MODIFY_ADD); System.out.println("Modifying DL .."); access.ModifyDistributionList(oesctx, args[1], ldapObj); System.out.println("Modified DL .."); } System.gc(); } catch (Exception e) { System.err.println("Error Occured " + e.getMessage()); System.gc(); } } }
This example deletes a public Distribution List.
import java.util.Enumeration; import java.util.Vector; import oracle.mail.OESContext; import oracle.mail.sdk.ldap.DirectoryAccess; import oracle.mail.sdk.ldap.DirectoryConstants; import oracle.mail.sdk.ldap.DirectoryException; class DeleteDistributionList { public static void main(String[] args) { if (args.length < 2) { System.out.println("Usage: java DeleteDistributionList <ORAHOME> <mailid>"); System.exit(1); } try { OESContext oesctx = new OESContext( DirectoryConstants.DS_CALLERTYPE_APP, false); //Authenticate to the directory if (oesctx.authenticate(null, args[0]) != true) { System.err.println("APP authentication failed"); System.exit(1); } else { DirectoryAccess access = new DirectoryAccess(); System.out.println("Deleting DL " + args[1]); //Deleting the DL access.DeleteDistributionList(oesctx, args[1]); System.out.println("Deleted DL"); } System.gc(); } catch (Exception e) { System.err.println("Error Occured " + e.getMessage()); System.gc(); } } }
This example shows how to resolve a public distribution list.
*/ import java.util.Hashtable; import java.util.Vector; import oracle.mail.OESContext; import oracle.mail.sdk.ldap.DirectoryAccess; import oracle.mail.sdk.ldap.DirectoryConstants; import oracle.mail.sdk.ldap.DirectoryException; class ResolveDistributionList { public static void main(String[] args) { if (args.length < 2) { System.out.println("Usage: java ResolveDistributionList <ORAHOME> <dl_mailid>"); System.exit(1); } try { OESContext oesctx = new OESContext( DirectoryConstants.DS_CALLERTYPE_APP, false); //Authenticate to the directory if (oesctx.authenticate(null, args[0]) != true) { System.err.println("APP authentication failed"); System.exit(1); } else { DirectoryAccess access = new DirectoryAccess(); Hashtable members = access.ResolveDistributionList(oesctx, args[1]); System.out.println("Printing Members.."); //Key of the hashtable is the type of member and value is a vector of //values if (members != null) { Vector users = (Vector)members.get(DirectoryConstants.DS_ USER); if (users != null) { for (int i = 0; i < users.size(); i++) System.out.println("User Member :: " + users.elementAt(i).toString()); } Vector dls = (Vector)members.get(DirectoryConstants.DS_ LIST); if (dls != null) { for (int i = 0; i < dls.size(); i++) System.out.println("DL Member :: " + dls.elementAt(i).toString()); } Vector foreign = (Vector)members.get(DirectoryConstants.DS_ FOREIGN); if (foreign != null) { for (int i = 0; i < foreign.size(); i++) System.out.println("DL Member :: " + foreign.elementAt(i).toString()); } Vector aliases = (Vector)members.get(DirectoryConstants.DS_ ALIAS); if (aliases != null) { for (int i = 0; i < aliases.size(); i++) System.out.println("DL Member :: " + aliases.elementAt(i).toString()); } } else { System.out.println("DL doesn't contain any member"); } } System.gc(); } catch (Exception e) { System.err.println("Error Occured " + e.getMessage()); System.gc(); } } }
The following example shows how to use the private address book contact information APIs to create, modify, look up, resolve, and search contacts.
Getting Contact Info Metadata And Creating A New Contact Info **/ ESDSLdapObject ldapobj = dirAccess.GetContactInfoMetaData(oesctx);
This example sets the name and e-mail ID of the new contact. Other attributes can be set in a similar way.
ldapobj.setAttributeValue("name","myfriend1"); ldapobj.setAttributeValue("orclmailemail","test@hotmail.com"); // Now Create The Contact dirAccess. CreateContactInfo(oesctx, ldapobj); /** Looking up a Contact Info **/ ldapobj = dirAccess.LookupContactInfo(oesctx,"myfriend1"); /*** Modifying a Contact **/ //Modifying the given name of the contact Vector modify = new Vector(); modify.add ("myfriend_name"); ldapobj.modifyAttributeValue("givenname", modify, ESDSConstants.DS_MODIFY_ADD); dirAccess.ModifyContactInfo(oesctx, "myfriend1",ldapobj); /*** Delete A Contact Info ***/ dirAccess.DeleteContactInfo(oesctx,"friend "); /** Get All Contacts **/ String[] contacts = dirAccess.GetAllContacts(oesctx); /** Get All Contacts For a Given Filter **/ contacts = dirAccess.SearchContacts(oesctx,"name=t*");
The following example shows how to use the private distribution list APIs to create, modify, look up, resolve, and search contacts.
This example creates a private contact for a given user.
import java.util.Vector; import oracle.mail.OESContext; import oracle.mail.sdk.ldap.DirectoryAccess; import oracle.mail.sdk.ldap.DirectoryConstants; import oracle.mail.sdk.ldap.DirectoryException; import oracle.mail.sdk.ldap.DirectoryObject; class CreateContact { public static void main(String[] args) { if (args.length < 3) { System.out.println("Usage: java CreateContact <ORAHOME> <user_ mailid> <user_password>"); System.exit(1); } try { OESContext oesctx = new OESContext( DirectoryConstants.DS_CALLERTYPE_APP, false); //Authenticate to the directory if (oesctx.authenticate(null, args[0]) != true) { System.err.println("APP authentication failed"); System.exit(1); } else { //Authenticate the user now OESContext clientCtx = new OESContext(DirectoryConstants.DS_ CALLERTYPE_MAILUSER); clientCtx.authenticate(args[1], args[2], oesctx); DirectoryAccess access = new DirectoryAccess(); DirectoryObject ldapobj = access.GetContactInfoMetaData( clientCtx); System.out.println("Retrieved Metadata."); //Setting some attributes of the contact ldapobj.setAttributeValue("name", "friend1"); ldapobj.setAttributeValue("givenname", "myfriend"); ldapobj.setAttributeValue("orclmailemail", "test1@abc.com"); Vector tel = new Vector(); tel.add("405 7777777"); tel.add("650 7777777"); ldapobj.setAttributeValue("telephonenumber", tel); access.CreateContactInfo(clientCtx, ldapobj); System.out.println("Created Contact .."); } System.gc(); } catch (Exception e) { System.err.println("Error Occured " + e.getMessage()); System.gc(); } } }
This example looks up a contact and modifies it.
import java.util.Vector; import oracle.mail.OESContext; import oracle.mail.sdk.ldap.DirectoryAccess; import oracle.mail.sdk.ldap.DirectoryConstants; import oracle.mail.sdk.ldap.DirectoryException; import oracle.mail.sdk.ldap.DirectoryObject; class ModifyContact { public static void main(String[] args) { if (args.length < 4) { System.out.println("Usage: java ModifyContact <ORAHOME> <user_ mailid> <user_password> <user_contact_name>"); System.exit(1); } try { OESContext oesctx = new OESContext( DirectoryConstants.DS_CALLERTYPE_APP, false); //Authenticate to the directory if (oesctx.authenticate(null, args[0]) != true) { System.err.println("APP authentication failed"); System.exit(1); } else { //Authenticate the user now OESContext clientCtx = new OESContext(DirectoryConstants.DS_ CALLERTYPE_MAILUSER); clientCtx.authenticate(args[1], args[2], oesctx); DirectoryAccess access = new DirectoryAccess(); DirectoryObject ldapobj = access.LookupContactInfo(clientCtx, args[3]); System.out.println("Found Contact"); Vector values = ldapobj.getAttributeValue("telephonenumber"); System.out.println("Printing old values of telephonenumber of the contact"); if (values != null) { for (int i = 0; i < values.size(); i++) System.out.println("telephonenumber Values --> " + (String)values.elementAt(i)); } else { System.out.println("No values set for telephonenumber"); } values = new Vector(); values.add("6506070000"); ldapobj.modifyAttributeValue("telephonenumber", values, DirectoryConstants.DS_MODIFY_ADD); Vector tel = new Vector(); tel.add("408 7431234"); tel.add("650 0000000"); ldapobj.setAttributeValue("mobile", tel); access.ModifyContactInfo(clientCtx, ldapobj); System.out.println("Modified Contact .."); } System.gc(); } catch (Exception e) { System.err.println("Error Occured " + e.getMessage()); System.gc(); } } }
This example deletes a contact info.
import oracle.mail.OESContext; import oracle.mail.sdk.ldap.DirectoryAccess; import oracle.mail.sdk.ldap.DirectoryConstants; import oracle.mail.sdk.ldap.DirectoryException; class DeleteContact { public static void main(String[] args) { if (args.length < 4) { System.out.println("Usage: java DeleteContact <ORAHOME> <user_ mailid> <user_password> <user_contact_name>"); System.exit(1); } try { OESContext oesctx = new OESContext( DirectoryConstants.DS_CALLERTYPE_APP, false); //Authenticate to the directory if (oesctx.authenticate(null, args[0]) != true) { System.err.println("APP authentication failed"); System.exit(1); } else { //Authenticate the user now OESContext clientCtx = new OESContext(DirectoryConstants.DS_ CALLERTYPE_MAILUSER); clientCtx.authenticate(args[1], args[2], oesctx); DirectoryAccess access = new DirectoryAccess(); System.out.println("Deleting Contact " + args[3]); //Deleting the contact access.DeleteContactInfo(clientCtx, args[3]); System.out.println("Deleted Contact"); } System.gc(); } catch (Exception e) { System.err.println("Error Occured " + e.getMessage()); System.gc(); } } }
This example shows various queries for contacts in a user's private addressbook.
import java.util.Enumeration; import java.util.Hashtable; import java.util.Vector; import oracle.mail.OESContext; import oracle.mail.sdk.ldap.DirectoryAccess; import oracle.mail.sdk.ldap.DirectoryConstants; import oracle.mail.sdk.ldap.DirectoryException; class QueryContacts { public static void main(String[] args) { if (args.length < 3) { System.out.println("Usage: java QueryContacts <ORAHOME> <user_ mailid> <user_password>"); System.exit(1); } try { OESContext oesctx = new OESContext( DirectoryConstants.DS_CALLERTYPE_APP, false); //Authenticate to the directory if (oesctx.authenticate(null, args[0]) != true) { System.err.println("APP authentication failed"); System.exit(1); } else { //Authenticate the user now OESContext clientCtx = new OESContext(DirectoryConstants.DS_ CALLERTYPE_MAILUSER); clientCtx.authenticate(args[1], args[2], oesctx); DirectoryAccess access = new DirectoryAccess(); System.out.println("Retrieving All Contacts"); //Retrieving all contacts in the user's addressbook String[] contacts = access.GetAllContacts(clientCtx); if (contacts != null) for (int i = 0; i < contacts.length; i++) System.out.println("Contact " + (i + 1) + " " + contacts[i]); //Retrieves all Contacts for the user logged on for the given search //criteria. "name=t*" returns all the contacts starting with "t". System.out.println("Retrieving Contacts Matching name=friend*"); contacts = access.SearchContacts(clientCtx, "name=friend*"); if (contacts != null) for (int i = 0; i < contacts.length; i++) System.out.println("Contact " + (i + 1) + " " + contacts[i]); } System.gc(); } catch (Exception e) { System.err.println("Error Occured " + e.getMessage()); System.gc(); } } }
The following examples show how to use the private list APIs to create, modify, look up, and delete lists.
This example creates a private distribution list for a given user.
import java.util.Vector; import oracle.mail.OESContext; import oracle.mail.sdk.ldap.DirectoryAccess; import oracle.mail.sdk.ldap.DirectoryConstants; import oracle.mail.sdk.ldap.DirectoryException; import oracle.mail.sdk.ldap.DirectoryObject; class CreatePrivateDL { public static void main(String[] args) { if (args.length < 3) { System.out.println("Usage: java CreatePrivateDL <ORAHOME> <user_ mailid> <user_password>"); System.exit(1); } try { OESContext oesctx = new OESContext( DirectoryConstants.DS_CALLERTYPE_APP, false); //Authenticate to the directory if (oesctx.authenticate(null, args[0]) != true) { System.err.println("APP authentication failed"); System.exit(1); } else { //Authenticate the user now OESContext clientCtx = new OESContext(DirectoryConstants.DS_ CALLERTYPE_MAILUSER); clientCtx.authenticate(args[1], args[2], oesctx); DirectoryAccess access = new DirectoryAccess(); DirectoryObject ldapobj = access.GetPrivateListMetaData( clientCtx); System.out.println("Retrieved Metadata."); //Setting some attributes of the dl ldapobj.setAttributeValue("name", "friends"); ldapobj.setAttributeValue("orclmailemail", "School Friends"); Vector vect = new Vector(); vect.add("test1@abc.com"); vect.add("test2@abc.com"); vect.add("test1@hotmail.com"); ldapobj.setAttributeValue("orclmailemail", vect); access.CreatePrivateList(clientCtx, ldapobj); System.out.println("Created 1st List .."); //Now it will create another list and add the first list to this one. ldapobj = access.GetPrivateListMetaData(clientCtx); //Setting some attributes of the dl ldapobj.setAttributeValue("name", "staff"); ldapobj.setAttributeValue("orclmailemail", "Staff"); vect = new Vector(); vect.add("test1@yahoo.com"); vect.add("test2@yahoo.com"); ldapobj.setAttributeValue("orclmailemail", vect); //Add friends to staff, Similarly contact infos also can be added to a //private DL ldapobj.setAttributeValue("uniquemember", "friends"); access.CreatePrivateList(clientCtx, ldapobj); System.out.println("Created 2nd List .."); } System.gc(); } catch (Exception e) { System.err.println("Error Occured " + e.getMessage()); System.gc(); } } }
This example looks up a private distribution list and modifies it.
import java.util.Vector; import oracle.mail.OESContext; import oracle.mail.sdk.ldap.DirectoryAccess; import oracle.mail.sdk.ldap.DirectoryConstants; import oracle.mail.sdk.ldap.DirectoryException; import oracle.mail.sdk.ldap.DirectoryObject; class ModifyPrivateDL { public static void main(String[] args) { if (args.length < 4) { System.out.println("Usage: java ModifyPrivateDL <ORAHOME> <user_ mailid> <user_password> <PrivateDL_name>"); System.exit(1); } try { OESContext oesctx = new OESContext( DirectoryConstants.DS_CALLERTYPE_APP, false); //Authenticate to the directory if (oesctx.authenticate(null, args[0]) != true) { System.err.println("APP authentication failed"); System.exit(1); } else { //Authenticate the user now OESContext clientCtx = new OESContext(DirectoryConstants.DS_ CALLERTYPE_MAILUSER); clientCtx.authenticate(args[1], args[2], oesctx); DirectoryAccess access = new DirectoryAccess(); DirectoryObject ldapobj = access.LookupPrivateList(clientCtx, args[3]); System.out.println("Found PrivateDL"); Vector values = ldapobj.getAttributeValue("orclmailemail"); System.out.println("Printing old values of mail ids of the PrivateDL members"); if (values != null) { for (int i = 0; i < values.size(); i++) System.out.println("Mail ids of members --> " + (String)values.elementAt(i)); } values = new Vector(); values.add("user1@test.net"); values.add("user2@oracle.com"); ldapobj.modifyAttributeValue("orclmailemail", values, DirectoryConstants.DS_MODIFY_ADD); access.ModifyPrivateList(clientCtx, ldapobj); System.out.println("Modified PrivateDL .."); } System.gc(); } catch (Exception e) { System.err.println("Error Occured " + e.getMessage()); System.gc(); } } }
This example deletes a private distribution list from the user's addressbook.
import oracle.mail.OESContext; import oracle.mail.sdk.ldap.DirectoryAccess; import oracle.mail.sdk.ldap.DirectoryConstants; import oracle.mail.sdk.ldap.DirectoryException; class DeletePrivateDL { public static void main(String[] args) { if (args.length < 4) { System.out.println("Usage: java DeletePrivateDL <ORAHOME> <user_ mailid> <user_password> <user_DL_name>"); System.exit(1); } try { OESContext oesctx = new OESContext( DirectoryConstants.DS_CALLERTYPE_APP, false); //Authenticate to the directory if (oesctx.authenticate(null, args[0]) != true) { System.err.println("APP authentication failed"); System.exit(1); } else { //Authenticate the user now OESContext clientCtx = new OESContext(DirectoryConstants.DS_ CALLERTYPE_MAILUSER); clientCtx.authenticate(args[1], args[2], oesctx); DirectoryAccess access = new DirectoryAccess(); System.out.println("Deleting private list " + args[3]); //Deleting the DL access.DeletePrivateList(clientCtx, args[3]); System.out.println("Deleted private list"); } System.gc(); } catch (Exception e) { System.err.println("Error Occured " + e.getMessage()); System.gc(); } } }
This example queries for private distribution lists based on the query criteria.
import oracle.mail.OESContext; import oracle.mail.sdk.ldap.DirectoryAccess; import oracle.mail.sdk.ldap.DirectoryConstants; import oracle.mail.sdk.ldap.DirectoryException; class QueryPrivateDLs { public static void main(String[] args) { if (args.length < 4) { System.out.println("Usage: java QueryPrivateDLs <ORAHOME> <user_ mailid> <user_password> <ldap_query_filter_(eg. name=friend*)>"); System.exit(1); } try { OESContext oesctx = new OESContext( DirectoryConstants.DS_CALLERTYPE_APP, false); //Authenticate to the directory if (oesctx.authenticate(null, args[0]) != true) { System.err.println("APP authentication failed"); System.exit(1); } else { //Authenticate the user now OESContext clientCtx = new OESContext(DirectoryConstants.DS_ CALLERTYPE_MAILUSER); clientCtx.authenticate(args[1], args[2], oesctx); DirectoryAccess access = new DirectoryAccess(); System.out.println("Retrieving All DLs"); //Retrieve all private dls present in the user's addressbook String[] dls = access.GetAllPrivateLists(clientCtx); if (dls != null) for (int i = 0; i < dls.length; i++) System.out.println("DL " + (i + 1) + " " + dls[i]); //Retrieves all DLs for the user logged on for the given search //criteria. "name=t*" returns all the DLs starting with "t". System.out.println("Retrieving DLs Matching " + args[3]); dls = access.SearchPrivateLists(clientCtx, args[3]); if (dls != null) for (int i = 0; i < dls.length; i++) System.out.println("DL " + (i + 1) + " " + dls[i]); } System.gc(); } catch (Exception e) { System.err.println("Error Occured " + e.getMessage()); System.gc(); } } }
This example resolves the given private list for e-mail addresses.
import java.util.Vector; import oracle.mail.OESContext; import oracle.mail.sdk.ldap.DirectoryAccess; import oracle.mail.sdk.ldap.DirectoryConstants; import oracle.mail.sdk.ldap.DirectoryException; class ResolvePrivateList { public static void main(String[] args) { if (args.length < 4) { System.out.println("Usage: java ResolvePrivateLists <ORAHOME> <user_ mailid> <user_password> <private_dl_name>"); System.exit(1); } try { OESContext oesctx = new OESContext( DirectoryConstants.DS_CALLERTYPE_APP, false); //Authenticate to the directory if (oesctx.authenticate(null, args[0]) != true) { System.err.println("APP authentication failed"); System.exit(1); } else { //Authenticate the user now OESContext clientCtx = new OESContext(DirectoryConstants.DS_ CALLERTYPE_MAILUSER); clientCtx.authenticate(args[1], args[2], oesctx); DirectoryAccess access = new DirectoryAccess(); System.out.println("Resolving this DL for email ids.."); Vector resolved = access.ResolvePrivateList(clientCtx, args[3], "orclmailemail"); if (resolved != null) for (int i = 0; i < resolved.size(); i++) System.out.println("Email" + (i + 1) + " " + (String)resolved.elementAt(i)); } System.gc(); } catch (Exception e) { System.err.println("Error Occured " + e.getMessage()); System.gc(); } } }
This example retrieves the user state from the user context. This can be helpful when both e-mail servers are running and caller applications need to decide which system to connect to.
import java.util.Vector; import oracle.mail.OESContext; import oracle.mail.sdk.ldap.DirectoryAccess; import oracle.mail.sdk.ldap.DirectoryConstants; import oracle.mail.sdk.ldap.DirectoryException; class RetrieveUserState { public static void main(String[] args) { if (args.length < 3) { System.out.println("Usage: java RetrieveUsetState <ORAHOME> <user_ mailid> <user_password> "); System.exit(1); } try { OESContext oesctx = new OESContext( DirectoryConstants.DS_CALLERTYPE_APP, false); //Authenticate to the directory if (oesctx.authenticate(null, args[0]) != true) { System.err.println("APP authentication failed"); System.exit(1); } else { //Authenticate the user now OESContext clientCtx = new OESContext(DirectoryConstants.DS_ CALLERTYPE_MAILUSER); clientCtx.authenticate(args[1], args[2], oesctx); DirectoryAccess access = new DirectoryAccess(); System.out.println("Retrieving user state"); Vector state = access.RetrieveAttribValueFromCache(clientCtx, "orclmailuserstate"); if (state!= null) System.out.println("User State is " + (String)state.elementAt(0)); //Callers can check if the state is "active" or "migrating" and decide their action based on that. } System.gc(); } catch (Exception e) { System.err.println("Error Occured " + e.getMessage()); System.gc(); } }
The rule management API is a set of Java classes that can be used to create, access and manage server side rules. Rules are represented as Java objects and can be saved persistently in the Oracle Internet Directory as an attribute of a user.
This section contains the following topics:
A mail rule is a potential action that, when a certain event happens and a certain condition is satisfied, is taken upon an e-mail message on behalf of the owner of the rule. Rules can be created and stored persistently on the mail server.
The following is an example of a rule, expressed in English:
If an e-mail message arrives in my inbox and its subject contains the phrase "Get paid to surf," then delete the message.
In this example:
Each event represents a change of state of a particular message during its lifecycle in the mail server. In the above example, the event changes the state of the message from To be delivered
to Delivered
.
Conditions are similar to Boolean expressions, in which relational and logical operations test message attributes. In the example, the subject is the mail attribute to be tested, and the conditional expression is a relational operation that tests whether the attribute contains "Get paid to surf."
Optionally, multiple conditions can be combined using logical operators such as And and Or to form compound conditions. Additionally, a condition can be an external function call that returns a Boolean value.
Actions are operations that can act upon a message, such as the deletion of the message. In addition, an action can be any external procedure that is callable in PL/SQL from within the mail server.
Rules are owned by either individual users or a group of users collectively. The top-level entity owning the rules can therefore be either a mail user, a domain, or an entire e-mail system, which can contain more than one domain. The top-level entities are referred to as accounts.
For every account, one can have rules defined under a set of events, such as when new mail is delivered or when the message is read. Each event is associated with a rule list, and an account can have several rule lists, with at most one per event. For any event, a rule list can contain a list of rules that are executed sequentially when the event occurs.
A rule is defined by a condition and a list of actions. A rule with no condition is said to be unconditional, therefore the actions are always carried out.
Conditions can be simple and complex. For example, a condition that compares an attribute with a literal value using the relational operator "contains" is a simple condition. A complex condition can combine several sub-conditions. A condition can be also be a user-defined procedure, referred to as an external condition. There is also a special kind of condition, called an InSection condition, which performs a content-based search on a message.
When a rule's conditions are met, actions are taken. Actions are defined by the rule's commands, such as "move message to a folder" or "forward message to a recipient," and associated parameters, such as the name of the folder to which the message is moved or the address of the recipient to whom the message is forwarded. Once all the rules for a user are constructed in Java objects, the RuleParser object can be used to save it.
Before a caller can access a user's rules, it must be authorized. The caller must authenticate with Oracle Internet Directory using the oracle.mail.OESContext class
. Once authenticated, the instance of the oracle.mail.OESContext class
representing a trusted session must be passed into the RuleParser rule management class using the setAuthContext()
method.
RuleParser parser = new RuleParser(); parser.setAuthContext(oesctx);
Before a rule is created on the server, the content of the rule is validated, preventing illegal rules from being executed at runtime. You can disable validation using the RuleParser.setValidation()
method, which is useful if you want to temporarily save an incomplete rule. A non-validated rule can be saved persistently, but cannot be run during runtime.
Validation is disabled as follows:
parser.setValidation(false);
A rule has several attributes that are classified as follows:
A rule can be visible or invisible. An invisible rule functions as a normal rule, except that it is not shown to the user. The actual implementation of hiding a rule is left to the caller. The API is able to retrieve both visible and invisible rules.
Visibility is set using the setVisible()
RuleType class method.
A rule can be active or inactive. An inactive rule exists on the server but is not executed at runtime.
Activeness is set using the setActive()
RuleType class method.
A rule can belong to a group. All rules belonging to the same group can be retrieved, activated, and disabled together in one call.
Group affiliation is set using the setGroup()
RuleType class method.
RuleType rule_t = new RuleType(); rule_t.setVisible("no"); rule_t.setActive("no"); rule_t.setGroup("group1");
An external condition is a PL/SQL function that takes the following format:
function <func_name> (p_sessionid in integer, p_msgobj in mail_message_obj) return integer;
Given the session ID and a message object, the function should return a number that indicates whether the condition is met.
If the return value is 0, the server regards it as a positive condition match, and if the return value is non-zero, it is regarded as a failed condition match. If a rule uses an external condition function, it must be manually loaded to the database server where the user resides before the condition can take effect.
To set a condition to be an external condition, use the ConditionType class method addProcCall()
.
ConditionType cond_t = new ConditionType(); cond_t.addProcCall("ext_func_name");
An external action is a PL/SQL procedure that takes the following format:
procedure <proc_name>(p_event in number, p_sessionid in number, p_msgobj in mail_message_obj, p_param1 in varchar2, p_param2 in varchar2, p_status out number);The event ID parameter takes the following possible values: es_rule.c_copy es_rule.c_deliver es_rule.c_expunge es_rule.c_flagchange
The procedure also takes a session ID, current message object and two user-defined parameters set at rule creation time. After the procedure is completed, it should put a execution result value in the status parameter. A zero value in status indicates a normal execution, and a positive status indicates an abnormal execution.
To set an external action using server-side rules, use the Action Type class addCommand()
method, then call addParameter()
three times, with the first added parameter being the procedure name, and the second and third parameters being the user-defined parameters p_param1
and p_param2
above.
ActionType action_t = new ActionType(); action_t.addCommand("call"); action_t.addParameter("ext_proc_name"); action_t.addParameter("param1"); action_t.addParameter("param2");
Some rules require an action to generate a new message as a reply or a notification. The reply or notification can be stored in the rule content as templates containing substitutable parameters denoted by a parameter name enclosed by two percent (%) signs.
For example, an auto-reply template can be "Your e-mail regarding %rfc822subject% sent on %rfc822date% has been received." When the rule engine generates the reply message, the %rfc822subject%
and %rfc822date%
variables are replaced by the actual subject and date sent information obtained from the incoming message. The set of supported parameters is the same as the set of supported message attributes.
See Also:
The Javadoc for Oracle Email API Reference (Java Doc) for information on the |
Message template text is used as parameter values for rule actions such as Notify, Reply, Replyall, and Forward.
ActionType action_t = new ActionType(); action_t.addCommand("notify"); action_t.addParameter("jdoe@acme.com"); action_t.addParameter("Message Alert"); action_t.addParameter("You have received email from %rfc822from% regarding %rfc822subject%");
To prevent auto-reply messages from flooding user inboxes, there is an effective duration for a specific reply action. The duration is specified as a number of days. If an auto-reply is sent to a particular address using a particular message template, the same reply is not sent to the same user again for the period of the effective duration, starting from the time when the first reply is sent. The value is required in rule actions Reply and Replyall.
ActionType action_t = new ActionType(); action_t.addCommand("reply"); action_t.addParameter("7"); action_t.addParameter("Message received"); action_t.addParameter("Your email regarding %rfc822subject% sent on %rfc822date% has been received.");
Rule data can be serialized, or converted into plain text format using XML. It can then be easily transported between applications or stored off line. In fact, the rule API internally uses XML as the format to store in the Oracle Internet Directory. To flatten rule Java objects into XML text, use the print()
method from the Account class.
XMLOutputStream out = new XMLOutputStream(System.out); account.print(out); out.writeNewLine(); out.flush();
The following example shows using the API to compose a simple rule:
import oracle.xml.classgen.InvalidContentException; import oracle.xml.parser.v2.XMLOutputStream; import java.util.*; import java.io.*; import oracle.mail.*; import oracle.mail.sdk.rule.*; import oracle.mail.sdk.ldap.*; public class Demo { public static main (String args[]) throws Exception { // login to LDAP using Directory APIs OESContext appCtx = new OESContext(DirectoryConstants.DS_CALLERTYPE_ APP); appCtx.uthenticate(null, "/your/local/oracle/home"); // authenticate as a rule owner OESContext clientCtx = new OESContext(ESDSConstants.DS_CALLERTYPE_ MAILUSER); clientCtx.authenticate("testuser1@oracle.com", null, appLogin); // set authentication context in RuleParser parser = new RuleParser(); parser.setAuthContext(clientCtx); // first create the top level user account type object AccountType acnt_t = new AccountType(); // set ownerType, either system, domain or user (default) acnt_t.setOwnerType("user"); // for system rules, this is the installation name in LDAP, // such as "install1", for domain rules this is the domain // name, such as "oracle.com", for user rules this is the // fully qualified username, such as testuser1@oracle.com acnt_t.setQualifiedName("testuser1@oracle.com"); // create a rulelist type object, set the event RuleListType rlist_t = new RuleListType(); rlist_t.setEvent("deliver"); // create a rule type object RuleType rule_t = new RuleType(); rule_t.setDescription("a new rule"); rule_t.setGroup("group1"); // create a condition type object ConditionType cond_t = new ConditionType(); // create a simple attribute: cond_t.addAttribute("rfc822subject"); // or create an attribute object with parameters: // // AttributeType attr_t = new AttributeType("xheader"); // attr_t.setParam("X-Priority"); // cond_t.addAttribute(attr_t); // create a simple operator: cond_t.addOperator("contains"); cond_t.addOperand("Hello"); // create an external condition ConditionType cond_t2 = new ConditionType(); cond_t2.addProcCall("extern_cond"); // create a negation of disjunction of above two conditions // (i.e. not (cond1 or cond2) ) ConditionType cond_t3 = new ConditionType(); cond_t3.setJunction("or"); cond_t3.setNegation("yes"); cond_t3.addCondition(cond_t); cond_t3.addCondition(cond_t2); // add the condition object to the rule type object rule_t.addCondition(cond_t3); // create an action type object ActionType action_t = new ActionType(); action_t.addCommand("moveto"); action_t.addParameter("/testuser1/folder1"); // add the action to the rule object rule_t.addAction(action_t); // create a second action object and add it in the rule type ActionType action2_t = new ActionType(); action2_t.addCommand("call"); action_t.addParameter("extern_action"); action_t.addParameter("param1"); action_t.addParameter("param2"); rule_t.addAction(action2_t); // add the rule object in the rulelist type object rlist_t.addRule(rule_t); // add the rulelist object in the account type object acnt_t.addRulelist(rlist_t); // create an account object on based the type object Account acnt = new Account(acnt_t); parser.setValidation(true); // default parser.setRuleObjects(acnt); } }
To efficiently access e-mail over mobile devices or over a slow link, it is necessary to have filters on folders that enable only a small subset of e-mails to be downloaded. The wireless filters and profiles feature enables the user to define search criteria on folders. When a search criteria is defined and the folder is opened, only messages that meet the criteria are selected and are visible to the client. In addition, it also enables the user to define multiple criteria on a folder, through the use of profiles for accessing different sets of messages.
The different wireless filters and profiles components are:
INBOX
folder called WP1 with the criteria "show urgent messages," and defines a second profile on the INBOX
folder called WP2 with the criteria "show messages from sender john
and from sender scott
." When the user logs in as username#wp1@domain_name
and selects INBOX
, the only messages that appear are those marked urgent. However, if the user logs in as username#wp2@domain_name
and selects INBOX
, the messages from sender <ohn
and scott
are displayed.
The various interfaces supporting virtual folders are:
The following example shows how to list wireless filters:
import java.util.*; import javax.mail.*; import javax.mail.internet.*; import java.io.*; import javax.mail.search.*; import oracle.mail.sdk.esmail.OracleEsProfile; import oracle.mail.sdk.esmail.OracleEsFilter; import oracle.mail.sdk.esmail.OracleStore; public class ListFilter { static String password = null; static String user = null; static String host = null; static int port = -1; static String mbox = "INBOX"; static String root = null; static boolean recursive = false; static String pattern = "*"; static boolean verbose = false; static String namespace = null; public static void main (String argv[]) throws Exception { for (int i = 0; i < argv.length; i++) { if (argv[i].equals("-U")) user = argv[++i]; else if (argv[i].equals("-P")) password = argv[++i]; else if (argv[i].equals("-D")) host = argv[++i]; else if (argv[i].equals("-I")) port = Integer.parseInt(argv[++i]); else if (argv[i].equals("--")) { i++; break; } else if (argv[i].startsWith("-")) { System.out.println( "Usage: ListFilter [-D ldap_host] [-I ldap_port] [-U user] [-P password]"); System.exit(1); } else { break; } } Properties props = System.getProperties(); Session session = Session.getDefaultInstance(props,null); session.setDebug(true); Store store = null; store = session.getStore("esmail"); if (user != null && password != null && port != 0 && host != null){ store.connect(host, port, user, password); OracleEsProfile wp2 = new OracleEsProfile(store, "wp2", "Wireless Profile 2"); wp2.create(); OracleEsProfile[] profiles = ((OracleStore)store).listProfile(); System.out.println("Number of profiles = " + profiles.length); for (int i = 0; i < profiles.length; i++) { System.out.println("PROFILE " + (i+1)); System.out.println("profile name = " + profiles[i].getName()); System.out.println("profile description = " + profiles[i].getDescription()+ "\n"); System.out.println("List the filters:"); OracleEsFilter[] filtersList = profiles[i].listFilters(); System.out.println("Number of filters : " + filtersList.length); for (int j = 0; j < filtersList.length; j++) { System.out.println("filter folder = " + filtersList[j].getFolder().getFullName()); System.out.println("filter description = " + filtersList[j].getDescription()); SearchTerm st = filtersList[j].getCriteria(); if (st instanceof FromTerm) System.out.println("from term"); } } } store.close(); } }
The following example shows how to add a wireless filter to a profile:
import java.util.*; import javax.mail.*; import javax.mail.internet.*; import java.io.*; import javax.mail.search.*; import javax.mail.Address; import javax.mail.internet.InternetAddress; import oracle.mail.sdk.esmail.OracleEsProfile; import oracle.mail.sdk.esmail.OracleEsFilter; import oracle.mail.sdk.esmail.OracleStore; public class AddFilter { static String password = null; static String user = null; static String host = null; static int port = -1; static String mbox = "INBOX"; static String root = null; static boolean recursive = false; static String pattern = "*"; static boolean verbose = false; static String namespace = null; public static void main (String argv[]) throws Exception { for (int i = 0; i < argv.length; i++) { if (argv[i].equals("-U")) user = argv[++i]; else if (argv[i].equals("-P")) password = argv[++i]; else if (argv[i].equals("-D")) host = argv[++i]; else if (argv[i].equals("-I")) port = Integer.parseInt(argv[++i]); else if (argv[i].equals("--")) { i++; break; } else if (argv[i].startsWith("-")) { System.out.println( "Usage: AddFilter [-D ldap_host] [-I ldap_port] [-U user] [-P password]"); System.exit(1); } else { break; } } Properties props = System.getProperties(); Session session = Session.getDefaultInstance(props,null); session.setDebug(false); Store store = null; store = session.getStore("esmail"); if (user != null && password != null && port != 0 && host != null){ store.connect(host, port, user, password); OracleEsProfile wp2 = new OracleEsProfile(store, "wp2", "Wireless Profile 2"); wp2.create(); OracleEsProfile[] profiles = ((OracleStore)store).listProfile(); System.out.println("Number of profiles = " + profiles.length); for (int i = 0; i < profiles.length; i++) { System.out.println("PROFILE " + (i+1)); System.out.println("profile name = " + profiles[i].getName()); System.out.println("profile description = " + profiles[i].getDescription()+ "\n"); } Folder folder = store.getFolder("xyz"); OracleEsFilter filter = new OracleEsFilter(folder, "F2", new FromTerm(new InternetAddress("tuser1@us.oracle.com"))); profiles[0].addFilter(filter); } store.close(); } }