adding new srcs
git-svn-id: svn://10.0.0.236/trunk@8397 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
45
mozilla/msgsdk/java/highlevel/examples/ReadMe.txt
Normal file
45
mozilla/msgsdk/java/highlevel/examples/ReadMe.txt
Normal file
@@ -0,0 +1,45 @@
|
||||
This directory contains three example programs that demonstrate the use of
|
||||
Netscape Messaging SDK convenience API. In particular use of the IMTransport
|
||||
and IMAttachment classes is shown. The use of the netscape MIME API for
|
||||
building MIME messages and MIME encoding the same, is also demonstrated
|
||||
by one of the programs.
|
||||
|
||||
The example programs are:
|
||||
-------------------------
|
||||
|
||||
sendMessage.java
|
||||
testsendMessage.java and
|
||||
testSendDocs.java
|
||||
|
||||
sendMessage.java
|
||||
----------------
|
||||
|
||||
Demonstrates the use of IMTransport.sendMessage() method, that is
|
||||
used to send an existing MIME message. The MIME message to be sent
|
||||
is NOT built and assumed to be available.
|
||||
|
||||
testsendMessage.java
|
||||
--------------------
|
||||
|
||||
Demonstrates the use of IMTransport.sendMessage() method, that is
|
||||
used to send an existing MIME message. The MIME message to be sent
|
||||
itself is built using the MIME API, which is also demonstrated.
|
||||
|
||||
testSendDocs.java
|
||||
-----------------
|
||||
|
||||
Demonstrates the use of IMTransport.sendDocuments() method that is
|
||||
used to send >=1 files (documents) as MIME message.
|
||||
|
||||
This program also demonstrates the use of IMAttachment class that is
|
||||
passed to the sendDocuments() method.
|
||||
|
||||
To Compile:
|
||||
-----------
|
||||
Set CLASSPATH to include the full path names of the proapi.jar file
|
||||
and the coapi.jar file and invoke javac compiler on the source files.
|
||||
|
||||
The proapi.jar and coapi.jar files are the Java archive files that
|
||||
contain the classes for the Netscape Messaging SDK protocol APIs and
|
||||
the Convenience API respectively. These two jar files are copied to
|
||||
the packages directory under the install root when you install the SDK.
|
||||
109
mozilla/msgsdk/java/highlevel/examples/sendMessage.java
Normal file
109
mozilla/msgsdk/java/highlevel/examples/sendMessage.java
Normal file
@@ -0,0 +1,109 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape Messaging Access SDK Version 3.5 code,
|
||||
* released on or about June 15, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998 Netscape
|
||||
* Communications Corporation. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): ______________________________________.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 and 1998 Netscape Communications Corporation
|
||||
* (http://home.netscape.com/misc/trademarks.html)
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
|
||||
import netscape.messaging.mime.*;
|
||||
import netscape.messaging.convenience.*;
|
||||
|
||||
|
||||
/* Simple Send Message Application using Netscape Messaging SDK Convenience API.
|
||||
*
|
||||
* This examples shows how to send a message already in MIME canaonical form
|
||||
* using the sendMessage() Convenience API.
|
||||
*
|
||||
* Please other examples in this directory and Netscape Messaging SDK MIME API,
|
||||
* for details on how to build and encode a MIME message.
|
||||
*
|
||||
* Author: Prasad Yendluri <prasad@netscape.com>, Mar-1998.
|
||||
*/
|
||||
|
||||
public class sendMessage
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Private data members.
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private String filename = null;
|
||||
private String filename_lastnode = null;
|
||||
private String host, sender, To, subject;
|
||||
public String tmpdir = "/tmp/";
|
||||
private static String textMsg = "Hello this is a test Message";
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// Constructor
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
public sendMessage ()
|
||||
{
|
||||
String sep = System.getProperty ("path.separator");
|
||||
if (sep.equals (";"))
|
||||
tmpdir = "C:\\temp"; // its windoz
|
||||
else
|
||||
tmpdir = "/tmp";
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// ----------------- MAIN -------------------------------
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
public static void main (String args[])
|
||||
{
|
||||
if (args.length != 4)
|
||||
{
|
||||
System.out.println("usage: java sendMessage host sender To <file-name> ");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
sendMessage testClient = new sendMessage();
|
||||
|
||||
testClient.host = args[0];
|
||||
testClient.sender = args[1];
|
||||
testClient.To = args[2];
|
||||
testClient.filename = args[3];
|
||||
|
||||
|
||||
// Now send it!
|
||||
try
|
||||
{
|
||||
// The file must contain a message encoded in MIME canonical form.
|
||||
FileInputStream fis = new FileInputStream (testClient.filename);
|
||||
|
||||
String[] rejrecips = IMTransport.sendMessage (testClient.host,
|
||||
testClient.sender,
|
||||
testClient.To,
|
||||
fis);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
System.out.println("IMTransport.sendMessage() threw exception! " + e.getMessage()+ "\n");
|
||||
e.printStackTrace();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
146
mozilla/msgsdk/java/highlevel/examples/testSendDocs.java
Normal file
146
mozilla/msgsdk/java/highlevel/examples/testSendDocs.java
Normal file
@@ -0,0 +1,146 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape Messaging Access SDK Version 3.5 code,
|
||||
* released on or about June 15, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998 Netscape
|
||||
* Communications Corporation. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): ______________________________________.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 and 1998 Netscape Communications Corporation
|
||||
* (http://home.netscape.com/misc/trademarks.html)
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
|
||||
import netscape.messaging.mime.*;
|
||||
import netscape.messaging.convenience.*;
|
||||
|
||||
|
||||
/* Demo Message Send Application using Netscape Messaging SDK Convenience API.
|
||||
*
|
||||
* This example demonstrates the use of the sendDocuments() Convenience API.
|
||||
* This API privides simple interface for sending files / documents as attachments
|
||||
* in a MIME message over SMTP transport.
|
||||
*
|
||||
* Author: Prasad Yendluri <prasad@netscape.com>, Mar-1998.
|
||||
*/
|
||||
|
||||
public class testSendDocs
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Private data members.
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private String filename1 = null, filename2 = null;
|
||||
private String filename_lastnode = null;
|
||||
private String host, sender, To, subject;
|
||||
private String tmpdir = "/tmp/";
|
||||
private boolean fUseTempFiles;
|
||||
private static String textMsg = "Hello this is a test Message";
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// Constructor
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
public testSendDocs ()
|
||||
{
|
||||
/*
|
||||
String sep = System.getProperty ("path.separator");
|
||||
if (sep.equals (";"))
|
||||
tmpdir = "C:\\temp"; // its windoz
|
||||
else
|
||||
tmpdir = "/tmp";
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// ----------------- MAIN -------------------------------
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
public static void main (String args[])
|
||||
{
|
||||
if (args.length < 5 || args.length > 7)
|
||||
{
|
||||
System.out.println("usage: java testSendDocs host sender To subject <file-name> [<file-name>] [T|F]");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
testSendDocs testClient = new testSendDocs();
|
||||
|
||||
testClient.host = args[0];
|
||||
testClient.sender = args[1];
|
||||
testClient.To = args[2];
|
||||
testClient.subject = args[3];
|
||||
testClient.filename1 = args[4];
|
||||
testClient.fUseTempFiles = false;
|
||||
|
||||
if (args.length > 5)
|
||||
{
|
||||
if (args[5].equalsIgnoreCase("T"))
|
||||
testClient.fUseTempFiles = true;
|
||||
else if (args[5].equalsIgnoreCase("F"))
|
||||
testClient.fUseTempFiles = false;
|
||||
else
|
||||
testClient.filename2 = args[5];
|
||||
}
|
||||
|
||||
if (args.length > 6)
|
||||
{
|
||||
if (args[6].equalsIgnoreCase("T"))
|
||||
testClient.fUseTempFiles = true;
|
||||
else if (args[6].equalsIgnoreCase("F"))
|
||||
testClient.fUseTempFiles = false;
|
||||
}
|
||||
|
||||
int encoding = -1;
|
||||
|
||||
// Now send the specified files to the specified recipients.
|
||||
// The sendDocuments() method builds and encodes a MIME message
|
||||
// with the specified attachments and other parameters and sends
|
||||
// the message over SMTP transport.
|
||||
try
|
||||
{
|
||||
IMAttachment [] attchments = new IMAttachment [2];
|
||||
|
||||
attchments [0] = new IMAttachment (testClient.filename1, -1, null, null, -1, -1);
|
||||
|
||||
if (testClient.filename2 != null)
|
||||
{
|
||||
attchments [1] = new IMAttachment (testClient.filename2, -1, null, null, -1, -1);
|
||||
}
|
||||
|
||||
System.out.println("fUseTempFiles = " + testClient.fUseTempFiles);
|
||||
|
||||
String[] rejrecips = IMTransport.sendDocuments (testClient.host,
|
||||
testClient.sender,
|
||||
testClient.To,
|
||||
testClient.subject,
|
||||
null,
|
||||
null,
|
||||
attchments,
|
||||
testClient.fUseTempFiles);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
System.out.println("IMTransport.sendDocuments() threw exception! " + e.getMessage()+ "\n");
|
||||
e.printStackTrace();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
209
mozilla/msgsdk/java/highlevel/examples/testsendMessage.java
Normal file
209
mozilla/msgsdk/java/highlevel/examples/testsendMessage.java
Normal file
@@ -0,0 +1,209 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape Messaging Access SDK Version 3.5 code,
|
||||
* released on or about June 15, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998 Netscape
|
||||
* Communications Corporation. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): ______________________________________.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 and 1998 Netscape Communications Corporation
|
||||
* (http://home.netscape.com/misc/trademarks.html)
|
||||
*/
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
|
||||
import netscape.messaging.mime.*;
|
||||
import netscape.messaging.convenience.*;
|
||||
|
||||
|
||||
/* Demo Message Send Application using Netscape Messaging SDK Convenience API.
|
||||
*
|
||||
* This example has two parts:
|
||||
*
|
||||
* Part 1> Shows how to build a MIME message given a file to send as a
|
||||
* MIME attachment. For this the Messaging SDK MIME API is used.
|
||||
*
|
||||
* Part 2> Shows how to send the MIME message built above using the Messaging SDK
|
||||
* Convenience API sendMessage().
|
||||
*
|
||||
* Author: Prasad Yendluri <prasad@netscape.com>, Mar-1998.
|
||||
*/
|
||||
|
||||
public class testsendMessage
|
||||
{
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Private data members.
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
private String filename = null;
|
||||
private String filename_lastnode = null;
|
||||
private String host, sender, To, subject;
|
||||
public String tmpdir = "/tmp/";
|
||||
private static String textMsg = "Hello this is a test Message";
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// Constructor
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
public testsendMessage ()
|
||||
{
|
||||
String sep = System.getProperty ("path.separator");
|
||||
if (sep.equals (";"))
|
||||
tmpdir = "C:\\temp"; // its windoz
|
||||
else
|
||||
tmpdir = "/tmp";
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// Send the Message out. On success return false and true on failure.
|
||||
// On detection of any errors Pop up a Dialog Box asking user to check
|
||||
// for the needed fields.
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
public InputStream endcodeit (String sender, String To,
|
||||
String subject, String filename, int encoding)
|
||||
{
|
||||
try
|
||||
{
|
||||
return getMIMEMessage (sender, To, subject, filename, encoding);
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
System.out.println("endcodeit() Exception!"+ e.getMessage());
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
// Build a MIME Message and return an inputStream
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
public InputStream getMIMEMessage (String sender, String To,
|
||||
String subject, String fullfilename, int encoding)
|
||||
{
|
||||
return MultiPartMIMEMessage (sender, To, subject, fullfilename, encoding);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Build and return an InputStream for MIME-Multi-Part-Message
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
public InputStream MultiPartMIMEMessage (String sender, String To,
|
||||
String subject, String fullfilename, int encoding)
|
||||
{
|
||||
FileInputStream fis, fdis;
|
||||
FileOutputStream fos;
|
||||
ByteArrayInputStream bins;
|
||||
|
||||
MIMEMessage mmsg;
|
||||
|
||||
try
|
||||
{
|
||||
// >>>> Build and retrun a Multi-pArt MIME Message <<<<
|
||||
|
||||
// Get an inputStream to user entered text
|
||||
bins = new ByteArrayInputStream (textMsg.getBytes());
|
||||
|
||||
// Create a new Multi-part MIMEMessage with the above text and the file passed
|
||||
mmsg = new MIMEMessage(bins, fullfilename, encoding);
|
||||
|
||||
// set the user entered headers on the message
|
||||
mmsg.setHeader ("From", sender);
|
||||
mmsg.setHeader ("Reply-To", sender);
|
||||
mmsg.setHeader ("To", To);
|
||||
|
||||
if (subject != null && subject.length() != 0 )
|
||||
mmsg.setHeader ("Subject", subject);
|
||||
|
||||
// Add any other desired headers.
|
||||
mmsg.setHeader ("X-MsgSdk-Header", "This is a Text Message");
|
||||
|
||||
String mimefile = new String (tmpdir + "/SDKMIMEMsg.out");
|
||||
fos = new FileOutputStream (mimefile);
|
||||
|
||||
// Encode the message in MIME Canaonical form for transmission
|
||||
mmsg.putByteStream (fos);
|
||||
|
||||
// Return an inputStream to the encoded MIME message
|
||||
fis = new FileInputStream (mimefile);
|
||||
return fis;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("MultiPartMIMEMessage() Exception!"+ e.getMessage());
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
// ----------------- MAIN -------------------------------
|
||||
/////////////////////////////////////////////////////////////////////
|
||||
public static void main (String args[])
|
||||
{
|
||||
if (args.length != 5 && args.length != 6)
|
||||
{
|
||||
System.out.println("usage: java testsendMessage host sender To subject <file-name> <B|Q>");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
testsendMessage testClient = new testsendMessage();
|
||||
|
||||
testClient.host = args[0];
|
||||
testClient.sender = args[1];
|
||||
testClient.To = args[2];
|
||||
testClient.subject = args[3];
|
||||
testClient.filename = args[4];
|
||||
|
||||
int encoding = -1;
|
||||
|
||||
if (args.length > 5)
|
||||
{
|
||||
if (args[5].equalsIgnoreCase("B"))
|
||||
encoding = MIMEBodyPart.BASE64;
|
||||
|
||||
if (args[5].equalsIgnoreCase("Q"))
|
||||
encoding = MIMEBodyPart.QP;
|
||||
}
|
||||
|
||||
|
||||
// Build and encode a MIME message with the given file-name encoding type and
|
||||
// other parameters (sender, subject, recipients).
|
||||
InputStream mimeMsgStream = testClient.endcodeit (testClient.sender, testClient.To,
|
||||
testClient.subject, testClient.filename,
|
||||
encoding);
|
||||
|
||||
// Now send the MIME encoded message from above using the convenience method sendMessage.
|
||||
try
|
||||
{
|
||||
String[] rejrecips = IMTransport.sendMessage (testClient.host,
|
||||
testClient.sender,
|
||||
testClient.To,
|
||||
mimeMsgStream);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
System.out.println("IMTransport.sendMessage() threw exception! " + e.getMessage()+ "\n");
|
||||
e.printStackTrace();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
157
mozilla/msgsdk/java/highlevel/src/IMAttachment.java
Normal file
157
mozilla/msgsdk/java/highlevel/src/IMAttachment.java
Normal file
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape Messaging Access SDK Version 3.5 code,
|
||||
* released on or about June 15, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998 Netscape
|
||||
* Communications Corporation. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): ______________________________________.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 and 1998 Netscape Communications Corporation
|
||||
* (http://home.netscape.com/misc/trademarks.html)
|
||||
*/
|
||||
|
||||
package netscape.messaging.convenience;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* The IMAttachment class represents a MIME attachment for an
|
||||
* email message.
|
||||
* @author Prasad Yendluri
|
||||
*/
|
||||
public class IMAttachment
|
||||
{
|
||||
protected int content_type;
|
||||
protected String content_subtype;
|
||||
protected String content_params;
|
||||
protected int content_disposition;
|
||||
protected int mime_encoding;
|
||||
protected InputStream attach_stream;
|
||||
protected String attach_file;
|
||||
|
||||
/**
|
||||
* Constructor for an IMAttachment object.
|
||||
*
|
||||
* @param dataStream InputStream to attachment data. Cannot be null.
|
||||
* @param contentPrimaryType Primary content-type of the message.
|
||||
* @see IMTransport#TEXT
|
||||
* @see IMTransport#AUDIO
|
||||
* @see IMTransport#IMAGE
|
||||
* @see IMTransport#VIDEO
|
||||
* @see IMTransport#APPLICATION
|
||||
* @param contentSubType Strings representing the content sub-types.
|
||||
* @param contentParameters Strings representing the content-type parameters.
|
||||
* @param contentDisposition Can only be IMTransport.INLINE or IMTransport.ATTACHMENT
|
||||
* @see IMTransport#INLINE
|
||||
* @see IMTransport#ATTACHMENT
|
||||
* @param encodings Can only be IMTransport.BASE64 or IMTransport.QP or IMTransport.NONE
|
||||
* @see IMTransport#BASE64
|
||||
* @see IMTransport#QP
|
||||
* @see IMTransport#NONE
|
||||
*/
|
||||
public IMAttachment (InputStream dataStream,
|
||||
int contentPrimaryType,
|
||||
String contentSubType,
|
||||
String contentParameters,
|
||||
int contentDisposition,
|
||||
int encoding) throws IMException
|
||||
{
|
||||
if (dataStream == null)
|
||||
throw new IMException ("Invalid Parameter: dataStream = null");
|
||||
|
||||
if (contentPrimaryType < IMTransport.TEXT ||
|
||||
contentPrimaryType > IMTransport.APPLICATION)
|
||||
throw new IMException ("Invalid Parameter: contentPrimaryType = "
|
||||
+ contentPrimaryType);
|
||||
if (contentSubType == null)
|
||||
throw new IMException ("Invalid parameter: contentSubType = null");
|
||||
|
||||
if (contentDisposition > 0 && contentDisposition != IMTransport.INLINE &&
|
||||
contentDisposition != IMTransport.ATTACHMENT)
|
||||
throw new IMException ("Invalid parameter: contentDisposition = "
|
||||
+ contentDisposition);
|
||||
|
||||
if (encoding > -1 && encoding != IMTransport.BASE64 && encoding != IMTransport.QP &&
|
||||
encoding != IMTransport.NONE)
|
||||
throw new IMException ("Invalid parameter: encoding = " + encoding);
|
||||
|
||||
attach_stream = dataStream;
|
||||
attach_file = null;
|
||||
content_type = contentPrimaryType;
|
||||
content_subtype = contentSubType;
|
||||
content_params = contentParameters;
|
||||
content_disposition = contentDisposition;
|
||||
mime_encoding = encoding;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructor for an IMAttachment object that includes a filename.
|
||||
* @param fullfileName Full name (including path) of a file that contains attachment data.
|
||||
* @param contentPrimaryType Primary content-type of the message.
|
||||
* @see IMTransport#TEXT
|
||||
* @see IMTransport#AUDIO
|
||||
* @see IMTransport#IMAGE
|
||||
* @see IMTransport#VIDEO
|
||||
* @see IMTransport#APPLICATION
|
||||
* @param contentSubType Strings representing the content sub-types.
|
||||
* @param contentParameters Strings representing the content-type parameters.
|
||||
* @param contentDisposition Can only be IMTransport.INLINE or IMTransport.ATTACHMENT
|
||||
* @see IMTransport#INLINE
|
||||
* @see IMTransport#ATTACHMENT
|
||||
* @param encodings Can only be IMTransport.BASE64 or IMTransport.QP or IMTransport.NONE
|
||||
* @see IMTransport#BASE64
|
||||
* @see IMTransport#QP
|
||||
* @see IMTransport#NONE
|
||||
*/
|
||||
public IMAttachment (String fullfileName,
|
||||
int contentPrimaryType,
|
||||
String contentSubType,
|
||||
String contentParameters,
|
||||
int contentDisposition,
|
||||
int encoding) throws IMException
|
||||
{
|
||||
|
||||
if (fullfileName == null)
|
||||
throw new IMException ("Invalid Parameter: fullfileName = null");
|
||||
|
||||
if ((contentPrimaryType > -1) && (contentPrimaryType < IMTransport.TEXT ||
|
||||
contentPrimaryType > IMTransport.APPLICATION))
|
||||
throw new IMException ("Invalid Parameter: contentPrimaryType = "
|
||||
+ contentPrimaryType);
|
||||
|
||||
if (contentSubType == null && contentPrimaryType > -1)
|
||||
throw new IMException ("Invalid parameter: contentSubType = null");
|
||||
|
||||
if (contentDisposition > 0 && contentDisposition != IMTransport.INLINE &&
|
||||
contentDisposition != IMTransport.ATTACHMENT)
|
||||
throw new IMException ("Invalid parameter: contentDisposition = "
|
||||
+ contentDisposition);
|
||||
if (encoding > -1 && encoding != IMTransport.BASE64 && encoding != IMTransport.QP &&
|
||||
encoding != IMTransport.NONE)
|
||||
throw new IMException ("Invalid parameter: encoding = " + encoding);
|
||||
|
||||
attach_stream = null;
|
||||
attach_file = fullfileName;
|
||||
content_type = contentPrimaryType;
|
||||
content_subtype = contentSubType;
|
||||
content_params = contentParameters;
|
||||
content_disposition = contentDisposition;
|
||||
mime_encoding = encoding;
|
||||
}
|
||||
}
|
||||
54
mozilla/msgsdk/java/highlevel/src/IMException.java
Normal file
54
mozilla/msgsdk/java/highlevel/src/IMException.java
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape Messaging Access SDK Version 3.5 code,
|
||||
* released on or about June 15, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998 Netscape
|
||||
* Communications Corporation. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): ______________________________________.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 and 1998 Netscape Communications Corporation
|
||||
* (http://home.netscape.com/misc/trademarks.html)
|
||||
*/
|
||||
|
||||
package netscape.messaging.convenience;
|
||||
import java.io.*;
|
||||
|
||||
/**
|
||||
* The IMException class represents an internal error in
|
||||
* the Convenience API implementation of the Messaging Access SDK.
|
||||
* @see IMTransport
|
||||
* @author Prasad Yendluri
|
||||
*/
|
||||
public class IMException extends Exception {
|
||||
|
||||
/**
|
||||
* Constructs an IMException object.
|
||||
* Default constructor for the IMException class.
|
||||
*/
|
||||
public IMException() {
|
||||
super();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Constructs an IMException object given a descriptive string.
|
||||
* @param s String that describes the exception.
|
||||
*/
|
||||
public IMException(String s) {
|
||||
super(s);
|
||||
}
|
||||
}
|
||||
|
||||
129
mozilla/msgsdk/java/highlevel/src/IMMessageSummary.java
Normal file
129
mozilla/msgsdk/java/highlevel/src/IMMessageSummary.java
Normal file
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape Messaging Access SDK Version 3.5 code,
|
||||
* released on or about June 15, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998 Netscape
|
||||
* Communications Corporation. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): ______________________________________.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 and 1998 Netscape Communications Corporation
|
||||
* (http://home.netscape.com/misc/trademarks.html)
|
||||
*/
|
||||
|
||||
package netscape.messaging.convenience;
|
||||
import java.io.*;
|
||||
import java.lang.*;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* IMMessageSummary
|
||||
* @author Prasad Yendluri
|
||||
* Message Summary
|
||||
*/
|
||||
public class IMMessageSummary
|
||||
{
|
||||
/**
|
||||
* Name of the folder this message belongs to.
|
||||
*/
|
||||
private String folderName;
|
||||
|
||||
/**
|
||||
* Name of the sender of this message.
|
||||
*/
|
||||
private String sender;
|
||||
|
||||
/**
|
||||
* Subject of this message.
|
||||
*/
|
||||
private String subject;
|
||||
|
||||
/**
|
||||
* Date of this message.
|
||||
*/
|
||||
private String date;
|
||||
|
||||
/**
|
||||
* message size.
|
||||
*/
|
||||
private String size;
|
||||
|
||||
/**
|
||||
* message sequence number in the folder.
|
||||
*/
|
||||
private int msgnum;
|
||||
|
||||
/**
|
||||
* Constructor for the IMMessageSummary
|
||||
*/
|
||||
public IMMessageSummary ()
|
||||
{
|
||||
// Do any initialization
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Foldername the Message belongs to.
|
||||
*/
|
||||
public String getFolder ()
|
||||
{
|
||||
String cts = new String ("INBOX");
|
||||
return (cts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Sender of the Message.
|
||||
*/
|
||||
public String getSender ()
|
||||
{
|
||||
String cts = new String ("Prasad");
|
||||
return (cts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Subject of the Message.
|
||||
*/
|
||||
public String getSubject ()
|
||||
{
|
||||
String cts = new String ("Hello");
|
||||
return (cts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Date of the Message.
|
||||
*/
|
||||
public String getDate ()
|
||||
{
|
||||
String cts = new String ("Date");
|
||||
return (cts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Size of the Message.
|
||||
*/
|
||||
public int getSize ()
|
||||
{
|
||||
return (0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sequence number of the Message in the folder.
|
||||
*/
|
||||
public int getMsgNum ()
|
||||
{
|
||||
return (1);
|
||||
}
|
||||
|
||||
}
|
||||
221
mozilla/msgsdk/java/highlevel/src/IMSMTPSink.java
Normal file
221
mozilla/msgsdk/java/highlevel/src/IMSMTPSink.java
Normal file
@@ -0,0 +1,221 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape Messaging Access SDK Version 3.5 code,
|
||||
* released on or about June 15, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998 Netscape
|
||||
* Communications Corporation. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): ______________________________________.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 and 1998 Netscape Communications Corporation
|
||||
* (http://home.netscape.com/misc/trademarks.html)
|
||||
*/
|
||||
|
||||
package netscape.messaging.convenience;
|
||||
import netscape.messaging.smtp.*;
|
||||
|
||||
|
||||
/*
|
||||
* Implemnts IMSMTPSink.
|
||||
* Copyright 1998 Netscape Communications Corporation, all rights reserved.
|
||||
* Author: Prasad Yendluri <prasad@netscape.com>, Feb 1998.
|
||||
*/
|
||||
|
||||
public class IMSMTPSink extends SMTPSink
|
||||
{
|
||||
public boolean m_cmdStatus;
|
||||
public boolean m_cmdStatusPending;
|
||||
public boolean m_ehloStatus;
|
||||
public boolean m_expnStatus;
|
||||
public boolean m_debug;
|
||||
public String m_thrCmd;
|
||||
public int m_failCode;
|
||||
private static int FAILCODE = 400;
|
||||
|
||||
public IMSMTPSink ()
|
||||
{
|
||||
m_cmdStatus = false;
|
||||
m_cmdStatusPending = true;
|
||||
m_ehloStatus = false;
|
||||
}
|
||||
|
||||
public boolean tryProcessResponses(SMTPClient p_client)
|
||||
{
|
||||
m_cmdStatus = false;
|
||||
m_cmdStatusPending = false;
|
||||
m_failCode = 0;
|
||||
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
p_client.processResponses();
|
||||
|
||||
if (m_cmdStatusPending != true)
|
||||
return m_cmdStatus;
|
||||
}
|
||||
/*
|
||||
catch (InterruptedIOException e)
|
||||
{
|
||||
if (m_debug)
|
||||
System.out.println ("*** processResponses()> InterruptedIOException"
|
||||
+ e.getMessage());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
if (m_debug)
|
||||
System.out.println ("*** processResponses()> IOException"
|
||||
+ e.getMessage());
|
||||
m_cmdStatus = false;
|
||||
return m_cmdStatus;
|
||||
}
|
||||
*/
|
||||
catch (Exception e)
|
||||
{
|
||||
if (m_debug)
|
||||
System.out.println ("*** processResponses()> Exception"
|
||||
+ e.getMessage());
|
||||
m_cmdStatus = false;
|
||||
return m_cmdStatus;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Notification for error()
|
||||
*/
|
||||
public void error (int respCode, StringBuffer respMsg) throws SMTPServerException
|
||||
{
|
||||
m_cmdStatus = respCode < FAILCODE ? true : false;
|
||||
m_cmdStatusPending = false;
|
||||
m_failCode = respCode;
|
||||
|
||||
if (m_cmdStatus != false)
|
||||
throw new SMTPServerException ("respCode = " + respCode +
|
||||
" server response = " + respCode);
|
||||
} // end error
|
||||
|
||||
|
||||
/**
|
||||
* Notification for connect() response
|
||||
*/
|
||||
public void connect (int respCode, StringBuffer respMsg)
|
||||
{
|
||||
m_cmdStatus = respCode < FAILCODE ? true : false;
|
||||
m_cmdStatusPending = false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Notification for the response to the DATA command.
|
||||
*/
|
||||
public void data (int respCode, StringBuffer respMsg)
|
||||
{
|
||||
m_cmdStatus = respCode < FAILCODE ? true : false;
|
||||
m_cmdStatusPending = false;
|
||||
}
|
||||
|
||||
/**
|
||||
*Notification for the response to the EHLO command.
|
||||
*/
|
||||
public void ehlo (int respCode, StringBuffer respMsg)
|
||||
{
|
||||
m_ehloStatus = respCode < FAILCODE ? true : false;
|
||||
m_cmdStatusPending = true;
|
||||
}
|
||||
|
||||
/**
|
||||
*Notification for the completion of the EHLO command.
|
||||
*/
|
||||
public void ehloComplete()
|
||||
{
|
||||
|
||||
m_cmdStatusPending = false;
|
||||
m_cmdStatus = m_ehloStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
*Notification for the response to the EXPN command.
|
||||
*/
|
||||
public void expand (int respCode, StringBuffer respMsg)
|
||||
{
|
||||
m_expnStatus = respCode < FAILCODE ? true : false;
|
||||
m_cmdStatusPending = true;
|
||||
}
|
||||
|
||||
/**
|
||||
*Notification for the completion of the EXPN command.
|
||||
*/
|
||||
public void expandComplete ()
|
||||
{
|
||||
m_cmdStatusPending = false;
|
||||
m_cmdStatus = m_expnStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
*Notification for the response to the MAIL FROM command.
|
||||
*/
|
||||
public void mailFrom (int respCode, StringBuffer respMsg)
|
||||
{
|
||||
m_cmdStatus = respCode < FAILCODE ? true : false;
|
||||
m_cmdStatusPending = false;
|
||||
}
|
||||
|
||||
/**
|
||||
*Notification for the response to the NOOP command.
|
||||
*/
|
||||
public void noop (int respCode, StringBuffer respMsg)
|
||||
{
|
||||
m_cmdStatus = respCode < FAILCODE ? true : false;
|
||||
m_cmdStatusPending = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Notification for the QUIT response
|
||||
*/
|
||||
public void quit (int respCode, StringBuffer respMsg)
|
||||
{
|
||||
m_cmdStatus = respCode < FAILCODE ? true : false;
|
||||
m_cmdStatusPending = false;
|
||||
}
|
||||
|
||||
/**
|
||||
*Notification for the response to the RCPT TO command.
|
||||
*/
|
||||
public void rcptTo (int respCode, StringBuffer respMsg)
|
||||
{
|
||||
m_cmdStatus = respCode < FAILCODE ? true : false;
|
||||
m_cmdStatusPending = false;
|
||||
}
|
||||
|
||||
/**
|
||||
*Notification for the response to the RSET command.
|
||||
*/
|
||||
public void reset (int respCode, StringBuffer respMsg)
|
||||
{
|
||||
m_cmdStatus = respCode < FAILCODE ? true : false;
|
||||
m_cmdStatusPending = false;
|
||||
}
|
||||
|
||||
/**
|
||||
*Notification for the response to data sent to the server.
|
||||
*/
|
||||
public void send (int respCode, StringBuffer respMsg)
|
||||
{
|
||||
m_cmdStatus = respCode < FAILCODE ? true : false;
|
||||
m_cmdStatusPending = false;
|
||||
}
|
||||
|
||||
}
|
||||
77
mozilla/msgsdk/java/highlevel/src/IMSearchTerm.java
Normal file
77
mozilla/msgsdk/java/highlevel/src/IMSearchTerm.java
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape Messaging Access SDK Version 3.5 code,
|
||||
* released on or about June 15, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998 Netscape
|
||||
* Communications Corporation. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): ______________________________________.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 and 1998 Netscape Communications Corporation
|
||||
* (http://home.netscape.com/misc/trademarks.html)
|
||||
*/
|
||||
|
||||
|
||||
package netscape.messaging.convenience;
|
||||
import java.io.*;
|
||||
import java.lang.*;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* IMSearchTerm
|
||||
* @author Prasad Yendluri
|
||||
* The Search Term
|
||||
*/
|
||||
public class IMSearchTerm
|
||||
{
|
||||
/**
|
||||
* Name of the field to search in.
|
||||
* The special String "TextBody" will search all text bodyParts.
|
||||
*/
|
||||
public String fieldName;
|
||||
/**
|
||||
* Actual string to search for.
|
||||
*/
|
||||
public String value;
|
||||
|
||||
/**
|
||||
* This term must be present to satisfy the search.
|
||||
*/
|
||||
public static final int AND = 1;
|
||||
|
||||
/**
|
||||
* This term may be present to satisfy the search.
|
||||
* It is valid to not have matched this term to satisfy this search,
|
||||
* if it is satisfied otherwise.
|
||||
*/
|
||||
public static final int OR = 0;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor for the IMSearchTerm
|
||||
* @param name Name of the header field to search in.
|
||||
* The String "TextBody" stands for all text bodyParts.
|
||||
* @param value Actual string to search for (in the field specified above).
|
||||
* @param AndOR Should the search for this be on OR / AND basis?
|
||||
* @see IMSearchTerm#AND
|
||||
* @see IMSearchTerm#OR
|
||||
*/
|
||||
public IMSearchTerm (String name, String value, int AndOR)
|
||||
{
|
||||
// Do any initialization
|
||||
}
|
||||
|
||||
}
|
||||
90
mozilla/msgsdk/java/highlevel/src/IMSendThr.java
Normal file
90
mozilla/msgsdk/java/highlevel/src/IMSendThr.java
Normal file
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape Messaging Access SDK Version 3.5 code,
|
||||
* released on or about June 15, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998 Netscape
|
||||
* Communications Corporation. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): ______________________________________.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 and 1998 Netscape Communications Corporation
|
||||
* (http://home.netscape.com/misc/trademarks.html)
|
||||
*/
|
||||
|
||||
|
||||
package netscape.messaging.convenience;
|
||||
import java.io.*;
|
||||
import java.lang.*;
|
||||
import java.util.*;
|
||||
|
||||
import netscape.messaging.smtp.*;
|
||||
import netscape.messaging.mime.*;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* IMSendThr
|
||||
* @author Prasad Yendluri
|
||||
* Internet Message Store
|
||||
*/
|
||||
class IMSendThr extends Thread
|
||||
{
|
||||
PipedInputStream msg_inputStream;
|
||||
String host;
|
||||
String sender;
|
||||
String recipients;
|
||||
Vector rejects;
|
||||
|
||||
/**
|
||||
* Default constructor for IMSendThr
|
||||
*/
|
||||
public IMSendThr (PipedInputStream is,
|
||||
String host,
|
||||
String sender,
|
||||
String recipients,
|
||||
Vector rejects)
|
||||
{
|
||||
this.msg_inputStream = is;
|
||||
this.host = host;
|
||||
this.sender = sender;
|
||||
this.recipients = recipients;
|
||||
this.rejects = rejects;
|
||||
}
|
||||
|
||||
|
||||
public void run ()
|
||||
{
|
||||
String [] l_rejects;
|
||||
|
||||
try
|
||||
{
|
||||
l_rejects = IMTransport.sendMessage2 (host,
|
||||
sender,
|
||||
recipients,
|
||||
msg_inputStream);
|
||||
|
||||
if (l_rejects != null)
|
||||
for (int i = 0, len = l_rejects.length; i < len; i++)
|
||||
{
|
||||
rejects.addElement (l_rejects [i]);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
System.out.println("ImSendThr Exception! = " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
205
mozilla/msgsdk/java/highlevel/src/IMStore.java
Normal file
205
mozilla/msgsdk/java/highlevel/src/IMStore.java
Normal file
@@ -0,0 +1,205 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape Messaging Access SDK Version 3.5 code,
|
||||
* released on or about June 15, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998 Netscape
|
||||
* Communications Corporation. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): ______________________________________.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 and 1998 Netscape Communications Corporation
|
||||
* (http://home.netscape.com/misc/trademarks.html)
|
||||
*/
|
||||
|
||||
|
||||
package netscape.messaging.convenience;
|
||||
import java.io.*;
|
||||
import java.lang.*;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
* IMStore
|
||||
* @author Prasad Yendluri
|
||||
* Internet Message Store
|
||||
*/
|
||||
public class IMStore
|
||||
{
|
||||
/**
|
||||
* Default constructor for IMStore
|
||||
*/
|
||||
public IMStore ()
|
||||
{
|
||||
// Do any initialization
|
||||
}
|
||||
|
||||
/**
|
||||
* Connects to the message store specified, at the default port based on protocol.
|
||||
* @param host name of the host to connect to.
|
||||
* @param protocol protocol to use to connect. Valid values are "POP3" and "IMAP4"
|
||||
* @exception IOException If the socket connection can not be opened with the host.
|
||||
* @see IMStore#disconnect
|
||||
*
|
||||
*/
|
||||
public void connect (String host, String protocol) throws IOException
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs into message store as the specified user.
|
||||
* @param user username to login with
|
||||
* @param pass password to login with
|
||||
* @exception IMException If not logged in earlier
|
||||
* @see IMStore#logout
|
||||
*/
|
||||
public void login (String user, String pass) throws IMException
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of sub-folders one level below the specified folder.
|
||||
* @param rootFolder Name of the folder to list sub-folders.
|
||||
* @return array of names of sub-folders. null if no sub-folders.
|
||||
* @exception IMException If rootFolder is not a valid name.
|
||||
* @exception IOException If IO error.
|
||||
*/
|
||||
public String[] listSubFolders (String rootFolder) throws IOException, IMException
|
||||
{
|
||||
String[] flist = new String[2];
|
||||
flist[0] = "junk1";
|
||||
flist[2] = "junk2";
|
||||
return (flist);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the summary list for the messages in the specified folder.
|
||||
* @param folder Name of the folder. A NULL value assumes the folder INBOX.
|
||||
* @return array of IMMessageSummary objects.
|
||||
* @exception IMException If invalid folder.
|
||||
* @exception IOException If IO error.
|
||||
*/
|
||||
public IMMessageSummary[] listMessages (String folder) throws IOException, IMException
|
||||
{
|
||||
IMMessageSummary[] ims = new IMMessageSummary[2];
|
||||
ims[0] = new IMMessageSummary ();
|
||||
ims[1] = new IMMessageSummary ();
|
||||
return (ims);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes the specified message from the folder.
|
||||
* @param folder Name of the folder. A NULL value assumes the folder INBOX.
|
||||
* @param msgnum Message sequence number.
|
||||
* @return false if the message can not be deleted, true otherwise.
|
||||
*/
|
||||
public boolean delete (String folder, int msgnum)
|
||||
{
|
||||
return (true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Moves the specified message from the source folder to destination folder.
|
||||
* @param source Name of the folder. A NULL value assumes the folder INBOX.
|
||||
* @param destination Name of the folder. A NULL value assumes the folder INBOX.
|
||||
* @return false if the message can not be moved, true otherwise.
|
||||
*/
|
||||
public boolean move (String source, String destination, int msgnum)
|
||||
{
|
||||
return (true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copies the specified message from the source folder to destination folder.
|
||||
* @param source Name of the folder. A NULL value assumes the folder INBOX.
|
||||
* @param destination Name of the folder. A NULL value assumes the folder INBOX.
|
||||
* @return false if the message can not be copied, true otherwise.
|
||||
*/
|
||||
public boolean copy (String source, String destination, int msgnum)
|
||||
{
|
||||
return (true);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves the specified message from the message store.
|
||||
* @param folder Name of the folder. A NULL value assumes the folder INBOX.
|
||||
* @param msgnum Message sequence number.
|
||||
* @exception IOException If an IO error occurs.
|
||||
* @exception IMException If the message does not exist.
|
||||
* @return Returns an inputstream with the Message in MIME format.
|
||||
*/
|
||||
public InputStream retrieve (String folder, int msgnum) throws IOException, IMException
|
||||
{
|
||||
DataInputStream ins = new DataInputStream(System.in);
|
||||
return (ins);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the message as specified by the imapURL parameter. This kind of fetch is useful
|
||||
* for applications that obtain the URL from other sources (like from a webpage).
|
||||
* NOTE: For fetch, it is not necessary to connect / login to the message store first.
|
||||
* @param imapURL IMAP URL specifying the fully qualified URL for the message to be fetched.
|
||||
* The URL must conform to the format specified in RFC 2192 and must represent a
|
||||
* unique message.
|
||||
* An example URL is:
|
||||
* imap://foo.com/public.messages;UIDVALIDITY=123456/;UID=789
|
||||
* @exception IOException If an IO error occurs.
|
||||
* @exception IMException If the URL is malformed or does not represent a valid unique message.
|
||||
* @return Returns an inputstream with the Message in MIME format.
|
||||
*/
|
||||
public InputStream fetch (String imapURL) throws IOException, IMException
|
||||
{
|
||||
DataInputStream ins = new DataInputStream(System.in);
|
||||
return (ins);
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches the folder for messages that match the search criteria.
|
||||
* @param folder Name of the folder. A NULL value assumes the folder INBOX.
|
||||
* @param criteria Search criteria as defined by the list of terms.
|
||||
* @exception IOException If an IO error occurs.
|
||||
* @exception IMException If no message matches the criteria.
|
||||
* @return Returns a list of message sequence numbers of matched messages.
|
||||
*/
|
||||
public int [] search (String folder, IMSearchTerm[] criteria) throws IOException, IMException
|
||||
{
|
||||
int [] msn = new int [2];
|
||||
msn [1] = 0;
|
||||
msn [2] = 1;
|
||||
return (msn);
|
||||
}
|
||||
|
||||
/**
|
||||
* Logs out from the message store.
|
||||
* @exception IMException If not logged in earlier
|
||||
* @see IMStore#login
|
||||
*/
|
||||
public void logout () throws IMException
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* disconnects from the message store.
|
||||
* @exception IMException If not connected earlier
|
||||
* @see IMStore#connect
|
||||
*/
|
||||
public void disconnect () throws IMException
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
700
mozilla/msgsdk/java/highlevel/src/IMTransport.java
Normal file
700
mozilla/msgsdk/java/highlevel/src/IMTransport.java
Normal file
@@ -0,0 +1,700 @@
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
* http://www.mozilla.org/NPL/.
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
* for the specific language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Netscape Messaging Access SDK Version 3.5 code,
|
||||
* released on or about June 15, 1998.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998 Netscape
|
||||
* Communications Corporation. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s): ______________________________________.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1997 and 1998 Netscape Communications Corporation
|
||||
* (http://home.netscape.com/misc/trademarks.html)
|
||||
*/
|
||||
|
||||
|
||||
package netscape.messaging.convenience;
|
||||
import java.io.*;
|
||||
import java.lang.*;
|
||||
import java.util.*;
|
||||
|
||||
import netscape.messaging.smtp.*;
|
||||
import netscape.messaging.mime.*;
|
||||
|
||||
/**
|
||||
* The IMTransport class implements Java Convenience APIs.
|
||||
* <p>This class provides a convenient interface for building,
|
||||
* encoding, and sending messages. It combines the functionality
|
||||
* of MIME and SMTP.
|
||||
* @author Prasad Yendluri
|
||||
*/
|
||||
public class IMTransport
|
||||
{
|
||||
/**
|
||||
* Content (primary) type Text.
|
||||
*/
|
||||
public static final int TEXT = 0;
|
||||
/**
|
||||
* Content (primary) type Audio.
|
||||
*/
|
||||
public static final int AUDIO = 1;
|
||||
/**
|
||||
* Content (primary) type Image.
|
||||
*/
|
||||
public static final int IMAGE = 2;
|
||||
/**
|
||||
* Content (primary) type Video.
|
||||
*/
|
||||
public static final int VIDEO = 3;
|
||||
/**
|
||||
* Content (primary) type Application.
|
||||
*/
|
||||
public static final int APPLICATION = 4;
|
||||
|
||||
/**
|
||||
* Base64 Transfer Encoding.
|
||||
*/
|
||||
public static final int BASE64 = 0;
|
||||
/**
|
||||
* Quoted Printable Transfer Encoding.
|
||||
*/
|
||||
public static final int QP = 1;
|
||||
/**
|
||||
* No Transfer Encoding.
|
||||
*/
|
||||
public static final int NONE = 2;
|
||||
|
||||
/**
|
||||
* Content disposition INLINE
|
||||
*/
|
||||
public static final int INLINE = 1;
|
||||
|
||||
/**
|
||||
* Content disposition ATTACHMENT
|
||||
*/
|
||||
public static final int ATTACHMENT = 2;
|
||||
|
||||
/**
|
||||
* Default constructor for the IMTransport class.
|
||||
*/
|
||||
|
||||
//public IMTransport ()
|
||||
//{
|
||||
// // Do any initialization
|
||||
//}
|
||||
|
||||
/**
|
||||
* Connects to the SMTP transport at the specified host and submits the message.
|
||||
* <P>NOTE: The MIME Message itself can be created using the Netscape MIME API or
|
||||
* by any other means.
|
||||
* @param host Name of the host to connect to.
|
||||
* @param sender Sender of the message.
|
||||
* @param recipients Email addresses of the recipients of the message, separated by commas or spaces.
|
||||
* @param MIMEMessageStream Input-Stream to the message in MIME canonical form.
|
||||
* @return List of recipients to whom the message could not be submitted.
|
||||
* @exception IMException If the message could not be sent due to invalid host
|
||||
* or other causes.
|
||||
* @see #sendDocuments
|
||||
*/
|
||||
public static String [] sendMessage (String host,
|
||||
String sender,
|
||||
String recipients,
|
||||
InputStream MIMEMessageStream) throws IMException
|
||||
{
|
||||
Vector l_rejrecips;
|
||||
SMTPClient l_SMTPclnt;
|
||||
IMSMTPSink l_smtpSink;
|
||||
String[] l_addrs=null;
|
||||
|
||||
if (sender == null || sender.length() == 0)
|
||||
{
|
||||
throw new IMException ("Invalid null sender");
|
||||
}
|
||||
|
||||
if (host == null || host.length() == 0)
|
||||
{
|
||||
throw new IMException ("Invalid null host");
|
||||
}
|
||||
|
||||
if (MIMEMessageStream == null)
|
||||
{
|
||||
throw new IMException ("Invalid InputStream");
|
||||
}
|
||||
|
||||
if (recipients != null)
|
||||
l_addrs = parseAddrs (recipients);
|
||||
|
||||
if (l_addrs == null || l_addrs.length <= 0)
|
||||
{
|
||||
throw new IMException ("Invalid recipients");
|
||||
}
|
||||
|
||||
if (recipients != null)
|
||||
l_addrs = parseAddrs (recipients);
|
||||
|
||||
if (l_addrs == null || l_addrs.length <= 0)
|
||||
{
|
||||
throw new IMException ("Invalid recipients");
|
||||
}
|
||||
|
||||
try {
|
||||
l_smtpSink = new IMSMTPSink();
|
||||
l_SMTPclnt = new SMTPClient (l_smtpSink);
|
||||
|
||||
l_SMTPclnt.connect (host);
|
||||
|
||||
if (!l_smtpSink.tryProcessResponses(l_SMTPclnt))
|
||||
{
|
||||
throw new IMException ("Unable to connect to SMTP host " + host);
|
||||
}
|
||||
|
||||
l_SMTPclnt.mailFrom (sender, null);
|
||||
|
||||
if (!l_smtpSink.tryProcessResponses(l_SMTPclnt))
|
||||
{
|
||||
throw new IMException ("sender rejected by server. Resp Code = " +
|
||||
l_smtpSink.m_failCode);
|
||||
}
|
||||
|
||||
boolean someFailed = false;
|
||||
boolean allFailed = true;
|
||||
l_rejrecips = new Vector();
|
||||
|
||||
for (int i = 0, len = l_addrs.length; i < len; i++)
|
||||
{
|
||||
l_SMTPclnt.rcptTo (l_addrs[i], null);
|
||||
if (!l_smtpSink.tryProcessResponses(l_SMTPclnt))
|
||||
{
|
||||
someFailed = true;
|
||||
l_rejrecips.addElement (l_addrs[i]);
|
||||
}
|
||||
else
|
||||
allFailed = false;
|
||||
}
|
||||
|
||||
if (allFailed)
|
||||
{
|
||||
throw new IMException ("Server rejected all recipients");
|
||||
}
|
||||
|
||||
l_SMTPclnt.setChunkSize (8192);
|
||||
l_SMTPclnt.data ();
|
||||
|
||||
if (!l_smtpSink.tryProcessResponses(l_SMTPclnt))
|
||||
{
|
||||
throw new IMException ("Unable to intiate Data transfer with server. Resp Code = " +
|
||||
l_smtpSink.m_failCode);
|
||||
}
|
||||
|
||||
l_SMTPclnt.send (MIMEMessageStream);
|
||||
|
||||
if (!l_smtpSink.tryProcessResponses(l_SMTPclnt))
|
||||
{
|
||||
throw new IMException ("Data transfer failure! Resp Code = " +
|
||||
l_smtpSink.m_failCode);
|
||||
}
|
||||
|
||||
l_SMTPclnt.quit();
|
||||
|
||||
if (!l_smtpSink.tryProcessResponses(l_SMTPclnt))
|
||||
{
|
||||
// Ignore!
|
||||
//showFailPopUp("Error!", "Unbale to quit from server! Server code = "
|
||||
// + l_smtpSink.m_failCode);
|
||||
}
|
||||
|
||||
if (someFailed == true)
|
||||
{
|
||||
if (l_rejrecips == null)
|
||||
return null;
|
||||
|
||||
String [] rejrecips = new String [l_rejrecips.size()];
|
||||
|
||||
for (int i=0; i < l_rejrecips.size(); i++)
|
||||
{
|
||||
rejrecips [i] = (String) l_rejrecips.elementAt (i);
|
||||
}
|
||||
|
||||
return (rejrecips);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new IMException (e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected static String [] sendMessage2 (String host,
|
||||
String sender,
|
||||
String recipients,
|
||||
PipedInputStream MIMEMessageStream) throws IMException
|
||||
{
|
||||
Vector l_rejrecips;
|
||||
SMTPClient l_SMTPclnt;
|
||||
IMSMTPSink l_smtpSink;
|
||||
String[] l_addrs=null;
|
||||
|
||||
if (sender == null || sender.length() == 0)
|
||||
{
|
||||
throw new IMException ("Invalid null sender");
|
||||
}
|
||||
|
||||
if (host == null || host.length() == 0)
|
||||
{
|
||||
throw new IMException ("Invalid null host");
|
||||
}
|
||||
|
||||
if (MIMEMessageStream == null)
|
||||
{
|
||||
throw new IMException ("Invalid InputStream");
|
||||
}
|
||||
|
||||
if (recipients != null)
|
||||
l_addrs = parseAddrs (recipients);
|
||||
|
||||
if (l_addrs == null || l_addrs.length <= 0)
|
||||
{
|
||||
throw new IMException ("Invalid recipients");
|
||||
}
|
||||
|
||||
if (recipients != null)
|
||||
l_addrs = parseAddrs (recipients);
|
||||
|
||||
if (l_addrs == null || l_addrs.length <= 0)
|
||||
{
|
||||
throw new IMException ("Invalid recipients");
|
||||
}
|
||||
|
||||
try {
|
||||
l_smtpSink = new IMSMTPSink();
|
||||
l_SMTPclnt = new SMTPClient (l_smtpSink);
|
||||
|
||||
l_SMTPclnt.connect (host);
|
||||
|
||||
if (!l_smtpSink.tryProcessResponses(l_SMTPclnt))
|
||||
{
|
||||
throw new IMException ("Unable to connect to SMTP host " + host);
|
||||
}
|
||||
|
||||
l_SMTPclnt.mailFrom (sender, null);
|
||||
|
||||
if (!l_smtpSink.tryProcessResponses(l_SMTPclnt))
|
||||
{
|
||||
throw new IMException ("sender rejected by server. Resp Code = " +
|
||||
l_smtpSink.m_failCode);
|
||||
}
|
||||
|
||||
boolean someFailed = false;
|
||||
boolean allFailed = true;
|
||||
l_rejrecips = new Vector();
|
||||
|
||||
for (int i = 0, len = l_addrs.length; i < len; i++)
|
||||
{
|
||||
l_SMTPclnt.rcptTo (l_addrs[i], null);
|
||||
if (!l_smtpSink.tryProcessResponses(l_SMTPclnt))
|
||||
{
|
||||
someFailed = true;
|
||||
l_rejrecips.addElement (l_addrs[i]);
|
||||
}
|
||||
else
|
||||
allFailed = false;
|
||||
}
|
||||
|
||||
if (allFailed)
|
||||
{
|
||||
throw new IMException ("Server rejected all recipients");
|
||||
}
|
||||
|
||||
|
||||
l_SMTPclnt.data ();
|
||||
|
||||
if (!l_smtpSink.tryProcessResponses(l_SMTPclnt))
|
||||
{
|
||||
throw new IMException ("Unable to intiate Data transfer with server. Resp Code = " +
|
||||
l_smtpSink.m_failCode);
|
||||
}
|
||||
|
||||
l_SMTPclnt.send (MIMEMessageStream);
|
||||
|
||||
if (!l_smtpSink.tryProcessResponses(l_SMTPclnt))
|
||||
{
|
||||
throw new IMException ("Data transfer failure! Resp Code = " +
|
||||
l_smtpSink.m_failCode);
|
||||
}
|
||||
|
||||
l_SMTPclnt.quit();
|
||||
|
||||
if (!l_smtpSink.tryProcessResponses(l_SMTPclnt))
|
||||
{
|
||||
// Ignore!
|
||||
//showFailPopUp("Error!", "Unbale to quit from server! Server code = "
|
||||
// + l_smtpSink.m_failCode);
|
||||
}
|
||||
|
||||
if (someFailed == true)
|
||||
{
|
||||
if (l_rejrecips == null)
|
||||
return null;
|
||||
|
||||
String [] rejrecips = new String [l_rejrecips.size()];
|
||||
|
||||
for (int i=0; i < l_rejrecips.size(); i++)
|
||||
{
|
||||
rejrecips [i] = (String) l_rejrecips.elementAt (i);
|
||||
}
|
||||
|
||||
return (rejrecips);
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new IMException (e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds a MIME message with the specified parameters. Connects to the SMTP transport
|
||||
* at the specified host and submits the message. If the message has more than one
|
||||
* attachment, it is sent as MIME multipart/mixed type message.
|
||||
* <P>NOTE: This method facilitates mailing documents by mail-enabling an otherwise
|
||||
* mail-ignorant application. For any other uses or more sophisticated needs,
|
||||
* use the sendMessage() method in association with the Netscape MIME API
|
||||
* or the other Messaging APIs provided by Netscape.
|
||||
* <P>NOTE: If the fUseTempFiles parameter is set to true, sendDocuments uses
|
||||
* temporary intermediate files for some internal processing. This mode provides better
|
||||
* performance. If temporary files should not be created, set this flag to false.
|
||||
* @param host Name of the host to connect to.
|
||||
* @param sender Sender of the message.
|
||||
* @param recipients Email addresses of the recipients of the message, separated by commas or spaces.
|
||||
* @param subject Subject of the Message. Can be null.
|
||||
* @param msgHeaderNames Additional RFC-822 header names.
|
||||
* @param msgHeaderValues Values corresponding to the headers in the msgHeaderNames parameter.
|
||||
* @param fUseTempFiles Whether to use temporary intermediate files for some
|
||||
* internal processing. Values:
|
||||
* <ul><li>true: use temp files (better performance).
|
||||
* <li>false: do not use temp files. </ul>
|
||||
* @param fUseTempFiles If true, uses temporary intermediate files (for better performance).
|
||||
* @return List of recipients to whom the message could not be submitted.
|
||||
* @exception IMException If the message could not be sent due to invalid host or other
|
||||
* causes, or if there are inconsistencies in the parameter specifications.
|
||||
*/
|
||||
public static String [] sendDocuments (String host,
|
||||
String sender,
|
||||
String recipients,
|
||||
String subject,
|
||||
String[] msgHeaderNames,
|
||||
String[] msgHeaderValues,
|
||||
IMAttachment [] attachments,
|
||||
boolean fUseTempFiles) throws IMException
|
||||
{
|
||||
MIMEMultiPart l_mmp;
|
||||
MIMEBasicPart l_mbp;
|
||||
MIMEMessage l_mmsg;
|
||||
boolean fMultiPart = false;
|
||||
//boolean fUseTempFiles = true;
|
||||
int attach_count = 0, hdrs_count = 0;
|
||||
//FileInputStream l_fis;
|
||||
String [] rejrecips;
|
||||
String m_mimefile;
|
||||
Vector l_rejects;
|
||||
|
||||
if (sender == null || sender.length() == 0)
|
||||
{
|
||||
throw new IMException ("Invalid null sender");
|
||||
}
|
||||
|
||||
if (host == null || host.length() == 0)
|
||||
{
|
||||
throw new IMException ("Invalid null host");
|
||||
}
|
||||
|
||||
if (recipients == null)
|
||||
{
|
||||
throw new IMException ("Invalid null recipients");
|
||||
}
|
||||
|
||||
if (msgHeaderNames != null)
|
||||
{
|
||||
hdrs_count = msgHeaderNames.length;
|
||||
|
||||
if (msgHeaderValues == null || hdrs_count != msgHeaderValues.length)
|
||||
{
|
||||
throw new IMException ("msgHeaderNames and msgHeaderValues not equal in number");
|
||||
}
|
||||
}
|
||||
else
|
||||
hdrs_count = 0;
|
||||
|
||||
if (attachments == null || attachments.length == 0)
|
||||
{
|
||||
throw new IMException ("Invalid null attachments");
|
||||
}
|
||||
|
||||
attach_count = attachments.length;
|
||||
|
||||
if (attach_count > 1)
|
||||
fMultiPart = true;
|
||||
try
|
||||
{
|
||||
l_mmp = new MIMEMultiPart ();
|
||||
l_mmp.setContentSubType ("mixed");
|
||||
|
||||
for (int i = 0; i < attach_count; i++)
|
||||
{
|
||||
// build and add each attach to the message
|
||||
|
||||
if (attachments [i] != null)
|
||||
{
|
||||
//System.out.println("sendDocuments()> doing buildBasicPart. i= " + i);
|
||||
l_mbp = buildBasicPart (attachments[i]);
|
||||
l_mmp.addBodyPart (l_mbp, false);
|
||||
}
|
||||
}
|
||||
|
||||
l_mmsg = new MIMEMessage ();
|
||||
|
||||
l_mmsg.setBody (l_mmp, false);
|
||||
|
||||
if (hdrs_count > 0)
|
||||
for (int i = 0; i < hdrs_count; i++)
|
||||
{
|
||||
l_mmsg.setHeader (msgHeaderNames[i], msgHeaderValues [i]);
|
||||
}
|
||||
|
||||
if (subject != null)
|
||||
l_mmsg.setHeader ("Subject", subject);
|
||||
|
||||
if (fUseTempFiles == true)
|
||||
{
|
||||
// set up default tmpdir
|
||||
String sep, tmpdir;
|
||||
sep = System.getProperty ("path.separator");
|
||||
if (sep.equals (";"))
|
||||
tmpdir = "C:\\temp\\"; // its windoz
|
||||
else
|
||||
tmpdir = "/tmp/";
|
||||
|
||||
Random l_rand = new Random (System.currentTimeMillis());
|
||||
long l_decrand = l_rand.nextLong();
|
||||
|
||||
m_mimefile = new String (tmpdir + Long.toHexString(l_decrand));
|
||||
|
||||
removeFile (m_mimefile);
|
||||
FileOutputStream fos = new FileOutputStream (m_mimefile);
|
||||
l_mmsg.putByteStream (fos);
|
||||
|
||||
FileInputStream l_fis = new FileInputStream (m_mimefile);
|
||||
|
||||
rejrecips = sendMessage (host, sender, recipients, l_fis);
|
||||
removeFile (m_mimefile);
|
||||
|
||||
return rejrecips;
|
||||
}
|
||||
else
|
||||
{
|
||||
PipedOutputStream pos = new PipedOutputStream();
|
||||
PipedInputStream pins = new PipedInputStream(pos);
|
||||
|
||||
l_rejects = new Vector();
|
||||
|
||||
IMSendThr sendThr = new IMSendThr (pins, host, sender,
|
||||
recipients, l_rejects);
|
||||
sendThr.start();
|
||||
|
||||
//System.out.println("SendDocs> l_mmsg.putByteStream()");
|
||||
|
||||
l_mmsg.putByteStream (pos);
|
||||
|
||||
|
||||
//System.out.println("SendDocs> pos.close()");
|
||||
pos.close();
|
||||
|
||||
//System.out.println("SendDocs> doinigIMSendThr.join()!");
|
||||
sendThr.join();
|
||||
|
||||
if (l_rejects == null)
|
||||
return null;
|
||||
|
||||
rejrecips = new String [l_rejects.size()];
|
||||
|
||||
for (int i=0; i < l_rejects.size(); i++)
|
||||
{
|
||||
rejrecips [i] = (String) l_rejects.elementAt (i);
|
||||
}
|
||||
|
||||
return rejrecips;
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
throw new IMException (e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected static void removeFile(String in_file)
|
||||
{
|
||||
if (in_file != null)
|
||||
{
|
||||
File file = new File(in_file);
|
||||
if (file.exists())
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected static MIMEBasicPart buildBasicPart (IMAttachment attachment) throws MIMEException, IMException, IOException
|
||||
{
|
||||
fileMIMEType l_fmt;
|
||||
MIMEBasicPart l_basicPart;
|
||||
int content_type;
|
||||
String content_subtype;
|
||||
String content_params;
|
||||
int content_disposition;
|
||||
int mime_encoding = NONE;
|
||||
InputStream dataIS;
|
||||
|
||||
if (attachment.attach_file != null)
|
||||
{
|
||||
if (attachment.attach_stream != null)
|
||||
{
|
||||
throw new IMException ("Invalid attachment");
|
||||
}
|
||||
|
||||
l_fmt = MIMEHelper.getFileMIMEType (attachment.attach_file);
|
||||
|
||||
if (l_fmt == null)
|
||||
throw new IMException ("Invalid attachment");
|
||||
|
||||
if (attachment.content_type >= TEXT && attachment.content_type <= APPLICATION)
|
||||
{
|
||||
//System.out.println("buildBasicPart()> setting content-type from passed in");
|
||||
content_type = attachment.content_type;
|
||||
content_subtype = attachment.content_subtype;
|
||||
content_params = attachment.content_params;
|
||||
}
|
||||
else
|
||||
{
|
||||
//System.out.println("buildBasicPart()> setting content-type from getFileMIMEType() = " + l_fmt.content_type + " sub-type" + l_fmt.content_subtype + " params=" + l_fmt.content_params);
|
||||
|
||||
content_type = l_fmt.content_type;
|
||||
content_subtype = l_fmt.content_subtype;
|
||||
content_params = l_fmt.content_params;
|
||||
}
|
||||
|
||||
if (l_fmt.mime_encoding != BASE64)
|
||||
{
|
||||
if (attachment.mime_encoding >= BASE64 && attachment.mime_encoding < NONE)
|
||||
mime_encoding = attachment.mime_encoding;
|
||||
else
|
||||
mime_encoding = l_fmt.mime_encoding;
|
||||
}
|
||||
else
|
||||
mime_encoding = l_fmt.mime_encoding;
|
||||
|
||||
FileInputStream fis = new FileInputStream (attachment.attach_file);
|
||||
dataIS = fis;
|
||||
}
|
||||
else
|
||||
{
|
||||
dataIS = attachment.attach_stream;
|
||||
|
||||
if (attachment.content_type >= TEXT && attachment.content_type <= APPLICATION)
|
||||
{
|
||||
content_type = attachment.content_type;
|
||||
content_subtype = attachment.content_subtype;
|
||||
content_params = attachment.content_params;
|
||||
|
||||
if (attachment.mime_encoding >= BASE64 && attachment.mime_encoding < NONE)
|
||||
mime_encoding = attachment.mime_encoding;
|
||||
else
|
||||
mime_encoding = BASE64;
|
||||
}
|
||||
else
|
||||
{
|
||||
content_type = APPLICATION;
|
||||
content_subtype = new String ("octet-stream");
|
||||
content_params = null;
|
||||
mime_encoding = BASE64;
|
||||
}
|
||||
}
|
||||
|
||||
if (attachment.content_disposition == INLINE ||
|
||||
attachment.content_disposition == ATTACHMENT)
|
||||
{
|
||||
content_disposition = attachment.content_disposition;
|
||||
}
|
||||
else
|
||||
content_disposition = INLINE;
|
||||
|
||||
l_basicPart = new MIMEBasicPart(content_type);
|
||||
|
||||
if (content_subtype != null)
|
||||
l_basicPart.setContentSubType (content_subtype);
|
||||
|
||||
if (content_params != null)
|
||||
l_basicPart.setContentTypeParams (content_params);
|
||||
|
||||
if (attachment.content_disposition > -1)
|
||||
l_basicPart.setContentDisposition (attachment.content_disposition);
|
||||
|
||||
l_basicPart.setBodyData (dataIS);
|
||||
|
||||
//new
|
||||
if (mime_encoding == BASE64)
|
||||
l_basicPart.setContentEncoding (MIMEBodyPart.BASE64);
|
||||
else if (mime_encoding == QP)
|
||||
l_basicPart.setContentEncoding (MIMEBodyPart.QP);
|
||||
|
||||
return l_basicPart;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
// Parse space or comma separated addresses
|
||||
///////////////////////////////////////////////////////////////
|
||||
protected static String [] parseAddrs (String mailAddrs)
|
||||
{
|
||||
String [] retAddrs;
|
||||
int count;
|
||||
|
||||
String inAddrs = mailAddrs.trim();
|
||||
|
||||
StringTokenizer stz = new StringTokenizer (inAddrs, " ,");
|
||||
|
||||
count = stz.countTokens();
|
||||
|
||||
if (count <= 0)
|
||||
return null;
|
||||
|
||||
retAddrs = new String [count];
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
retAddrs [i] = stz.nextToken();
|
||||
}
|
||||
|
||||
|
||||
return retAddrs;
|
||||
}
|
||||
}
|
||||
84
mozilla/msgsdk/java/highlevel/src/Makefile
Normal file
84
mozilla/msgsdk/java/highlevel/src/Makefile
Normal file
@@ -0,0 +1,84 @@
|
||||
##########################################################################
|
||||
# HighLevel API makefile.
|
||||
# created 12/15/97 -- Prasad
|
||||
#
|
||||
############################################################################
|
||||
# environment
|
||||
#SHELL = /usr/bin/ksh
|
||||
|
||||
# commands
|
||||
JAVAC = javac
|
||||
ARCH = $(shell uname -s)
|
||||
|
||||
ifeq ($(ARCH), SunOS)
|
||||
ARCH = SOLARIS
|
||||
endif
|
||||
|
||||
ifeq ($(ARCH), HP-UX)
|
||||
ARCH = HPUX
|
||||
endif
|
||||
|
||||
ifndef MMDD
|
||||
MMDD = $(shell date +%m.%d)
|
||||
endif
|
||||
|
||||
JAVABUILDDIR=release/$(MMDD)/java/$(ARCH)
|
||||
JAVAHIFILES=IMException.java IMTransport.java IMAttachment.java
|
||||
|
||||
# java flags
|
||||
DEBUGJAVAFLAG =
|
||||
OPTJAVAFLAG = -d $(CLASSDIR)
|
||||
JAVAFLAGS = $(OTHERJAVAFLAGS) $(OPTJAVAFLAG) $(DEBUGJAVAFLAG)
|
||||
RM = rm -f
|
||||
|
||||
# files and directories
|
||||
#CLASSDIR = ./built
|
||||
CLASSDIR = ../../built/$(ARCH)/highlevel
|
||||
PROCLASSDIR = ../../built/$(ARCH)/protocol
|
||||
|
||||
#CLASSPATH = .:$(CLASSDIR):$(JDKCLASSPATH)
|
||||
CLASSPATH = .:$(PROCLASSDIR):$(CLASSDIR)
|
||||
|
||||
SRCS = \
|
||||
IMException.java \
|
||||
IMSMTPSink.java \
|
||||
IMAttachment.java \
|
||||
IMTransport.java \
|
||||
IMSearchTerm.java \
|
||||
MMessageSummary.java \
|
||||
IMStore.java
|
||||
|
||||
|
||||
OBJS = ${SRCS:.java=.class}
|
||||
|
||||
TARGET = package
|
||||
|
||||
.SUFFIXES: .java .class
|
||||
|
||||
all: $(CLASSDIR) $(TARGET)
|
||||
|
||||
install: $(TARGET)
|
||||
foreach f ( $(OBJS) ) \
|
||||
mv -f $$f $(CLASSDIR)/$$f \
|
||||
end
|
||||
|
||||
#$(TARGET): $(OBJS)
|
||||
$(TARGET):
|
||||
echo $(CLASSPATH)
|
||||
echo $(CLASSDIR)
|
||||
$(JAVAC) $(JAVAFLAGS) *.java
|
||||
$(CLASSDIR):
|
||||
echo mkdir $(CLASSDIR)
|
||||
- mkdir -p $(CLASSDIR)
|
||||
|
||||
GEN_JAVADOCS:
|
||||
echo $(CLASSPATH)
|
||||
javadoc -public -d ../../../$(JAVABUILDDIR)/doc/JavaDocs/ConvenienceAPI $(JAVAHIFILES)
|
||||
|
||||
#$(OBJS):
|
||||
# $(JAVAC) $(JAVAFLAGS) *.java
|
||||
#.java.class: $(SRCS)
|
||||
# $(JAVAC) $(JAVAFLAGS) $<
|
||||
|
||||
clean:
|
||||
rm -f $(CLASSDIR)/netscape/messaging/highlevel/*.class
|
||||
Reference in New Issue
Block a user