Bug 340606 Spell things properly: fix all but file renames.
This commit is contained in:
Родитель
7390ea57fc
Коммит
d0bbac5229
|
@ -1,143 +0,0 @@
|
|||
/*
|
||||
* AddressbookManager.java
|
||||
*
|
||||
* Created on 23 September 2005, 22:10
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package grendel.addressbook;
|
||||
|
||||
import grendel.addressbook.jdbc.derby.DerbyAddressBook;
|
||||
|
||||
import grendel.addressbook.ldap.LDAPAddressBook;
|
||||
|
||||
import grendel.prefs.Preferences;
|
||||
|
||||
import grendel.prefs.addressbook.Addressbook;
|
||||
import grendel.prefs.addressbook.Addressbook_Derby;
|
||||
import grendel.prefs.addressbook.Addressbook_LDAP;
|
||||
import grendel.prefs.addressbook.Addressbooks;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
/**
|
||||
* Manages the Addressbooks. Provides methods to add an address book and retrive an instance of an existing one.
|
||||
* @author hash9
|
||||
*/
|
||||
public final class AddressBookManager
|
||||
{
|
||||
/**
|
||||
* The branch of the Preferances with the Addressbooks in it.
|
||||
*/
|
||||
private static Addressbooks books;
|
||||
|
||||
static
|
||||
{
|
||||
/*
|
||||
* Get the addressbooks branch from preferances.
|
||||
* Done here incase any other initation requires it.
|
||||
*/
|
||||
books = Preferences.getPreferances().getAddressbooks();
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent the non-instanciable Class from being instancated.
|
||||
*/
|
||||
private AddressBookManager()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an addressbook to the stored addressbooks.
|
||||
*/
|
||||
public static void addAddressbook(Addressbook book)
|
||||
{
|
||||
books.addAddressbook(book);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an instance of a named address book.
|
||||
*/
|
||||
public static AddressBook getAddressBook(String name)
|
||||
{
|
||||
Addressbook book = books.getAddressbook(name);
|
||||
|
||||
return createAddressBookInstance(book);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the names of all the address books.
|
||||
*/
|
||||
public static Set<String> getAddressBookSet()
|
||||
{
|
||||
return books.keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an instance of all address books.
|
||||
*/
|
||||
public static List<AddressBook> getAllAddressBooks()
|
||||
{
|
||||
List<AddressBook> l = new ArrayList<AddressBook>(books.size());
|
||||
Collection<Object> c = books.values();
|
||||
|
||||
for (Object o : c)
|
||||
{
|
||||
l.add(createAddressBookInstance((Addressbook) o));
|
||||
}
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
/**
|
||||
* Actually create the instances of the address books.
|
||||
* @TODO Cache Addressbook referances we shouldn't reinstaciate an address book. (Use a week map)
|
||||
*/
|
||||
private static AddressBook createAddressBookInstance(Addressbook book)
|
||||
throws IllegalArgumentException
|
||||
{
|
||||
String s_type = book.getSuperType();
|
||||
String type = book.getType();
|
||||
|
||||
String classname = AddressBook.class.getPackage().getName();
|
||||
|
||||
if (!((s_type == null) || (s_type.equals(""))))
|
||||
{
|
||||
classname = classname.concat(".").concat(s_type);
|
||||
}
|
||||
|
||||
classname = classname.concat(".").concat(type.toLowerCase()).concat(".");
|
||||
classname = classname.concat(type).concat("AddressBook");
|
||||
|
||||
Constructor constr;
|
||||
|
||||
try
|
||||
{
|
||||
constr = Class.forName(classname)
|
||||
.getDeclaredConstructor(book.getClass());
|
||||
}
|
||||
catch (Exception ex) // If something goes wrong
|
||||
{
|
||||
throw new IllegalArgumentException(ex.getClass().getSimpleName() + ": " +
|
||||
ex.getMessage(), ex);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return (AddressBook) constr.newInstance(book);
|
||||
}
|
||||
catch (Exception ex) // If something goes wrong
|
||||
{
|
||||
throw new IllegalArgumentException(ex.getClass().getSimpleName() + ": " +
|
||||
ex.getMessage(), ex);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,127 +0,0 @@
|
|||
/*
|
||||
* Sun.java
|
||||
*
|
||||
* Created on 04 September 2005, 21:31
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package grendel.javamail;
|
||||
import grendel.prefs.Preferences;
|
||||
import grendel.prefs.accounts.Account;
|
||||
import grendel.prefs.accounts.Account_IMAP;
|
||||
import grendel.prefs.accounts.Account_MBox;
|
||||
import grendel.prefs.accounts.Account_Maildir;
|
||||
import grendel.prefs.accounts.Account_NNTP;
|
||||
import grendel.prefs.accounts.Account_POP3;
|
||||
import grendel.prefs.accounts.Account_SMTP;
|
||||
import java.util.Properties;
|
||||
import javax.mail.Service;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.URLName;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author hash9
|
||||
*/
|
||||
public final class Gnu {
|
||||
public static Service get_smtp(URLName url, Account a) {
|
||||
Account_SMTP smtp = (Account_SMTP) a;
|
||||
Properties props = JMProviders.getSession().getProperties();
|
||||
// Use the GNU JavaMail Properties
|
||||
// Name Type Description
|
||||
// mail.smtp.host IP address or hostname The SMTP server to connect to
|
||||
// mail.smtp.port integer (>=1) The port to connect to, if not specified.
|
||||
// mail.smtp.connectiontimeout integer (>=1) Socket connection timeout, in milliseconds. Defaults to no timeout.
|
||||
props.put("mail.smtp.connectiontimeout","10"); //XXX This should be an option
|
||||
// mail.smtp.timeout integer (>=1) Socket I/O timeout, in milliseconds. Defaults to no timeout.
|
||||
props.put("mail.smtp.timeout","10"); //XXX This should be an option
|
||||
// mail.smtp.from RFC 822 address The mailbox to use for the SMTP MAIL command. If not set, the first InternetAddress in the From field of the message will be used, or failing that, InternetAddress.getLocalAddress().
|
||||
// mail.smtp.localhost IP address or hostname The host identifier for the local machine, to report in the EHLO/HELO command.
|
||||
// mail.smtp.ehlo boolean If set to false, service extensions negotiation will not be attempted.
|
||||
props.put("mail.smtp.ehlo","true");
|
||||
// mail.smtp.auth boolean If set to true, authentication will be attempted. Exceptionally, you may set this to the special value "required" to throw an exception on connect when authentication could not be performed.
|
||||
if ((smtp.getUsername()!=null)&&(smtp.getPassword()!=null)) {
|
||||
props.put("mail.smtp.auth","required");
|
||||
}
|
||||
// mail.smtp.auth.mechanisms comma-delimited
|
||||
// list of SASL mechanisms If set, only the specified SASL mechanisms will be attempted during authentication, in the given order. If not present, the SASL mechanisms advertised by the server will be used.
|
||||
// mail.smtp.dsn.notify string The RCPT NOTIFY option. Should be set to either "never", or one or more of "success", "failure", or "delay" (separated by commas and/or spaces). See RFC 3461 for details. This feature may not be supported by all servers.
|
||||
// mail.smtp.dsn.ret string The MAIL RET option. Should be set to "full" or "hdrs". See RFC 3461 for details. This feature may not be supported by all servers.
|
||||
// mail.smtp.tls boolean If set to false, TLS negotiation will not be attempted. Exceptionally, you may set this to the special value "required" to throw an exception on connect when TLS is not available.
|
||||
//TODO This should be determined.
|
||||
// mail.smtp.trustmanager String The name of a class implementing the javax.net.ssl.TrustManager interface, which will be used to determine trust in TLS negotiation
|
||||
//TODO what is this????
|
||||
Session s = JMProviders.getSession().getInstance(props);
|
||||
return new gnu.mail.providers.smtp.SMTPTransport(s,url);
|
||||
}
|
||||
|
||||
public static Service get_imap(URLName url, Account a) {
|
||||
Account_IMAP imap = (Account_IMAP)a;
|
||||
Properties props = JMProviders.getSession().getProperties();
|
||||
// Name Type Description
|
||||
// mail.imap.host IP address or hostname The IMAP server to connect to.
|
||||
// mail.imap.port integer (>=1) The port to connect to, if not the default.
|
||||
// mail.imap.user username The default username for IMAP.
|
||||
// mail.imap.connectiontimeout integer (>=1) Socket connection timeout, in milliseconds. Default is no timeout.
|
||||
// mail.imap.timeout integer (>=1) Socket I/O timeout, in milliseconds. Default is no timeout.
|
||||
// mail.imap.tls boolean If set to false, TLS negotiation will not be attempted.
|
||||
// mail.imap.trustmanager String The name of a class implementing the javax.net.ssl.TrustManager interface, which will be used to determine trust in TLS negotiation.
|
||||
// mail.imap.auth.mechanisms Comma-delimited list of
|
||||
// SASL mechanisms If set, only the specified SASL mechanisms will be attempted during authentication, in the given order. If not present, the SASL mechanisms advertised by the server will be used.
|
||||
// mail.imap.debug.ansi boolean If set to true, and mail.debug is also true, and your terminal supports ANSI escape sequences, you will get syntax coloured responses.
|
||||
Session s = JMProviders.getSession().getInstance(props);
|
||||
return new gnu.mail.providers.imap.IMAPStore(s,url);
|
||||
}
|
||||
|
||||
public static Service get_pop3(URLName url, Account a) {
|
||||
Account_POP3 pop3 = (Account_POP3)a;
|
||||
Properties props = JMProviders.getSession().getProperties();
|
||||
Session s = JMProviders.getSession().getInstance(props);
|
||||
return new gnu.mail.providers.pop3.POP3Store(s,url);
|
||||
}
|
||||
|
||||
public static Service get_maildir(URLName url, Account a) {
|
||||
Account_Maildir maildir = (Account_Maildir)a;
|
||||
Properties props = JMProviders.getSession().getProperties();
|
||||
props.setProperty("mail.maildir.home",maildir.getStoreDirectory());
|
||||
props.setProperty("mail.maildir.maildir",maildir.getStoreInbox());
|
||||
Session s = JMProviders.getSession().getInstance(props);
|
||||
return new gnu.mail.providers.maildir.MaildirStore(s,url);
|
||||
}
|
||||
|
||||
public static Service get_mbox(URLName url, Account a) {
|
||||
Account_MBox mbox = (Account_MBox)a;
|
||||
Properties props = JMProviders.getSession().getProperties();
|
||||
props.setProperty("mail.mbox.mailhome",mbox.getStoreDirectory());
|
||||
props.setProperty("mail.mbox.inbox",mbox.getStoreDirectory()+java.io.File.separatorChar+"INBOX");
|
||||
props.setProperty("mail.mbox.attemptfallback","true");
|
||||
Session s = JMProviders.getSession().getInstance(props);
|
||||
return new gnu.mail.providers.mbox.MboxStore(s,url);
|
||||
}
|
||||
|
||||
public static Service get_nntp(URLName url, Account a) {
|
||||
Account_NNTP nntp = (Account_NNTP)a;
|
||||
Properties props = JMProviders.getSession().getProperties();
|
||||
//XXX This refers to the HEAD CVS of GNU JavaMail
|
||||
String host = nntp.getHost();
|
||||
if (host!=null) {
|
||||
props.put("mail.nntp.newsrc.file", Preferences.getPreferances().getProfilePath()+host+".newsrc");
|
||||
props.put("mail.nntp.host", host);
|
||||
} else {
|
||||
props.put("mail.nntp.newsrc.file", Preferences.getPreferances().getProfilePath()+"news.rc");
|
||||
}
|
||||
|
||||
props.put("mail.nntp.listall", "true"); //XXX Mozilla.org Bug
|
||||
Session s = JMProviders.getSession().getInstance(props);
|
||||
return new gnu.mail.providers.nntp.NNTPStore(s,url);
|
||||
}
|
||||
|
||||
public static Service get_nntp_send(URLName url, Account a) {
|
||||
Account_NNTP nntp = (Account_NNTP)a;
|
||||
Properties props = JMProviders.getSession().getProperties();
|
||||
Session s = JMProviders.getSession().getInstance(props);
|
||||
return new gnu.mail.providers.nntp.NNTPTransport(s,url);
|
||||
}
|
||||
}
|
|
@ -1,230 +0,0 @@
|
|||
/*
|
||||
* JMProvider.java
|
||||
*
|
||||
* Created on 04 September 2005, 18:07
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
|
||||
package grendel.javamail;
|
||||
import grendel.prefs.Preferences;
|
||||
import grendel.prefs.accounts.Account;
|
||||
import grendel.prefs.accounts.Account__Local;
|
||||
import grendel.prefs.accounts.Account__Send;
|
||||
import grendel.prefs.accounts.Account__Server;
|
||||
import grendel.prefs.xml.XMLPreferences;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.TreeMap;
|
||||
import java.util.TreeSet;
|
||||
import javax.mail.NoSuchProviderException;
|
||||
import javax.mail.Provider;
|
||||
import javax.mail.Service;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.Store;
|
||||
import javax.mail.Transport;
|
||||
import javax.mail.URLName;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author hash9
|
||||
*/
|
||||
public final class JMProviders {
|
||||
private static JMProviders jmProvider;
|
||||
private static Session sess;
|
||||
private static XMLPreferences options_mail;
|
||||
|
||||
private Map<String, List<String>> order = new TreeMap<String, List<String>>();
|
||||
|
||||
/**
|
||||
* Map<Vendor_var(String), Map<Protocal(String), Provider(Provider)>>
|
||||
*
|
||||
*/
|
||||
private Map<String, Map<String, Provider>> sorted_providers = new TreeMap<String, Map<String, Provider>>();
|
||||
|
||||
public static JMProviders getJMProviders() {
|
||||
if (jmProvider==null) {
|
||||
jmProvider = new JMProviders();
|
||||
}
|
||||
return jmProvider;
|
||||
}
|
||||
|
||||
public static Session getSession() {
|
||||
if (sess==null) {
|
||||
options_mail=Preferences.getPreferances().getPropertyPrefs("options").getPropertyPrefs("mail");
|
||||
Properties props = new Properties();
|
||||
sess=Session.getDefaultInstance(props, null);
|
||||
//fSession.setDebug(options_mail.getPropertyBoolean("debug"));
|
||||
sess.setDebug(true);
|
||||
}
|
||||
return sess;
|
||||
}
|
||||
|
||||
private JMProviders() {
|
||||
loadSelection();
|
||||
}
|
||||
|
||||
private void loadSelection() {
|
||||
try {
|
||||
InputStream is = JMProviders.class.getResourceAsStream("/META-INF/javamail.selection");
|
||||
if (is==null) {
|
||||
System.err.println("ERROR: /META-INF/javamail.selection does not exist.");
|
||||
System.err.println("ERROR: Cannot continue: Exitting");
|
||||
System.exit(4);
|
||||
}
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(is));
|
||||
while (br.ready()) {
|
||||
String line = br.readLine().trim();
|
||||
if (line.equals("")) {
|
||||
// Blank: Ignore the line
|
||||
} else if (line.startsWith("#")) {
|
||||
// Comment: Ignore the line
|
||||
} else if (line.contains(";")) { // Selection Line
|
||||
int split = line.indexOf(';');
|
||||
String protocal = line.substring(0,split).trim().toLowerCase();
|
||||
String order_sl = line.substring(split+1).trim().toLowerCase();
|
||||
List<String> order_l = Arrays.asList(order_sl.split(","));
|
||||
for (int i = 0; i < order_l.size();i++) {
|
||||
if (order_l.get(i).equals("")) {
|
||||
order_l.remove(i);
|
||||
}
|
||||
}
|
||||
order.put(protocal,order_l);
|
||||
} else { // Other line: issue warning
|
||||
System.err.println("Line: \""+line+"\" is Invalid!");
|
||||
}
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
System.err.println("ERROR: " + ioe.getLocalizedMessage());
|
||||
System.err.println("ERROR: Whilest processing: /META-INF/javamail.selection");
|
||||
System.err.println("ERROR: Cannot continue: Exitting");
|
||||
System.exit(4);
|
||||
}
|
||||
}
|
||||
|
||||
private Service getService(URLName url, Account a) throws NoSuchProviderException {
|
||||
String protocal = url.getProtocol();
|
||||
List<String> order_l = order.get(protocal);
|
||||
if ((order_l==null)||(order_l.size()==0)) {
|
||||
throw new NoSuchProviderException("No Provider for " + protocal);
|
||||
}
|
||||
|
||||
for (String vendor_var: order_l) {
|
||||
try {
|
||||
return getService(url,a,vendor_var);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
throw new NoSuchProviderException("No Provider for " + protocal);
|
||||
}
|
||||
|
||||
private Service getService(URLName url, Account a, String vendor) throws NoSuchProviderException {
|
||||
vendor = vendor.toLowerCase();
|
||||
|
||||
if (vendor.equals("javamail")) { return getService(url); }
|
||||
|
||||
vendor = Character.toUpperCase(vendor.charAt(0))+vendor.substring(1);
|
||||
Exception cause = null;
|
||||
try {
|
||||
Class c = Thread.currentThread().getContextClassLoader().loadClass(this.getClass().getPackage().getName()+"."+vendor);
|
||||
Method m = c.getMethod("get_"+url.getProtocol().toLowerCase(),URLName.class, Account.class);
|
||||
if (Service.class.isAssignableFrom(m.getReturnType())) {
|
||||
Service s = (Service) m.invoke(null,url,a);
|
||||
return s;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// It broke, it must not exist
|
||||
cause=e;
|
||||
}
|
||||
|
||||
NoSuchProviderException nspe = new NoSuchProviderException("Failed to get Session. See Cause.");
|
||||
if (cause!=null) {
|
||||
nspe.initCause(cause);
|
||||
}
|
||||
throw nspe;
|
||||
}
|
||||
|
||||
private Service getService(URLName url) throws NoSuchProviderException {
|
||||
try {
|
||||
return getSession().getStore(url);
|
||||
} catch (NoSuchProviderException nspe) {
|
||||
return getSession().getTransport(url);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Transport object that implements the specified protocol.
|
||||
* If an appropriate Transport object cannot be obtained, null is
|
||||
* returned.
|
||||
*
|
||||
*
|
||||
* @return a Transport object
|
||||
* @exception NoSuchProviderException If provider for the given
|
||||
* protocol is not found.
|
||||
*/
|
||||
public Transport getTransport(Account__Send account) throws NoSuchProviderException {
|
||||
String host = null;
|
||||
int port = -1;
|
||||
String folder = null;
|
||||
if (account instanceof Account__Server) {
|
||||
host = ((Account__Server)account).getHost();
|
||||
port = ((Account__Server)account).getPort();
|
||||
if (port == 0) {
|
||||
port = -1;
|
||||
}
|
||||
}
|
||||
if (account instanceof Account__Local) {
|
||||
folder=((Account__Local)account).getStoreDirectory();
|
||||
}
|
||||
URLName url = new URLName(account.getTransport(),host,port,folder,null,null);
|
||||
Service s = getService(url,account);
|
||||
if (s instanceof Transport) {
|
||||
return (Transport) s;
|
||||
}
|
||||
throw new NoSuchProviderException("Invalid Service Type: "+s.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a Store object that implements the specified protocol. If an
|
||||
* appropriate Store object cannot be obtained,
|
||||
* NoSuchProviderException is thrown.
|
||||
*
|
||||
* @param account
|
||||
* @return a Store object
|
||||
* @exception NoSuchProviderException If a provider for the given
|
||||
* protocol is not found.
|
||||
*/
|
||||
public Store getStore(Account account) throws NoSuchProviderException {
|
||||
String host = null;
|
||||
int port = -1;
|
||||
String folder = null;
|
||||
if (account instanceof Account__Server) {
|
||||
host = ((Account__Server)account).getHost();
|
||||
port = ((Account__Server)account).getPort();
|
||||
if (port == 0) {
|
||||
port = -1;
|
||||
}
|
||||
}
|
||||
if (account instanceof Account__Local) {
|
||||
folder=((Account__Local)account).getStoreDirectory();
|
||||
}
|
||||
URLName url = new URLName(account.getType(),host,port,folder,null,null);
|
||||
Service s = getService(url,account);
|
||||
if (s instanceof Store) {
|
||||
return (Store) s;
|
||||
}
|
||||
throw new NoSuchProviderException("Invalid Service Type: "+s.toString());
|
||||
}
|
||||
}
|
|
@ -1,263 +0,0 @@
|
|||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* XMLPreferences.java
|
||||
*
|
||||
* Created on 10 August 2005, 22:33
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (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/MPL
|
||||
*
|
||||
* 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 Grendel mail/news client.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Kieran Maclean.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
package grendel.prefs;
|
||||
|
||||
import grendel.messaging.ExceptionNotice;
|
||||
import grendel.messaging.StringNotice;
|
||||
|
||||
import grendel.prefs.accounts.Accounts;
|
||||
|
||||
import grendel.prefs.addressbook.Addressbooks;
|
||||
|
||||
import grendel.prefs.xml.XMLPreferences;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author hash9
|
||||
*/
|
||||
public final class Preferences extends XMLPreferences
|
||||
{
|
||||
private static String base_path;
|
||||
private static String profile_path;
|
||||
private static File file_profiles;
|
||||
private static File file_preferences;
|
||||
private static Preferences preferences;
|
||||
private static XMLPreferences profiles = new XMLPreferences();
|
||||
|
||||
/**
|
||||
* Creates a new instance of Preferences
|
||||
*/
|
||||
private Preferences()
|
||||
{
|
||||
setupProfilePath();
|
||||
|
||||
StringBuilder prefs_path = new StringBuilder(Preferences.profile_path);
|
||||
|
||||
prefs_path.append("preferences.xml");
|
||||
|
||||
file_preferences = new File(prefs_path.toString());
|
||||
|
||||
try
|
||||
{
|
||||
InputStream is = getClass().getResourceAsStream("/" +
|
||||
getClass().getPackage().getName().replace('.', '/') +
|
||||
"/defaults.xml");
|
||||
if (is == null) {
|
||||
grendel.messaging.NoticeBoard.publish(new StringNotice("Unable to load default preferences!"));
|
||||
} else {
|
||||
loadDefaultsFromXML(new InputStreamReader(is));
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
grendel.messaging.NoticeBoard.publish(new ExceptionNotice(e));
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
loadFromXML(new FileReader(file_preferences));
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
grendel.messaging.NoticeBoard.publish(new ExceptionNotice(e));
|
||||
}
|
||||
}
|
||||
|
||||
public static StringBuilder getBasePath()
|
||||
{
|
||||
StringBuilder base_path = new StringBuilder();
|
||||
|
||||
base_path.append(System.getProperty("user.home"));
|
||||
|
||||
char[] c_a = System.getProperty("user.home").toCharArray();
|
||||
|
||||
if (c_a[c_a.length - 1] != File.separatorChar)
|
||||
{
|
||||
base_path.append(File.separator);
|
||||
}
|
||||
|
||||
base_path.append(".grendel");
|
||||
base_path.append(File.separator);
|
||||
|
||||
Preferences.base_path = base_path.toString();
|
||||
|
||||
return base_path;
|
||||
}
|
||||
|
||||
public static Preferences getPreferances()
|
||||
{
|
||||
if (preferences == null)
|
||||
{
|
||||
preferences = new Preferences();
|
||||
}
|
||||
|
||||
return preferences;
|
||||
}
|
||||
|
||||
public static void save()
|
||||
{
|
||||
try
|
||||
{
|
||||
savePreferances();
|
||||
saveProfiles();
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
ioe.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static void savePreferances() throws IOException
|
||||
{
|
||||
preferences.storeToXML(new FileWriter(file_preferences));
|
||||
}
|
||||
|
||||
public static void saveProfiles() throws IOException
|
||||
{
|
||||
profiles.storeToXML(new FileWriter(file_profiles));
|
||||
}
|
||||
|
||||
public Accounts getAccounts()
|
||||
{
|
||||
XMLPreferences p = getPropertyPrefs("accounts");
|
||||
|
||||
if (p instanceof Accounts)
|
||||
{
|
||||
return (Accounts) p;
|
||||
}
|
||||
else
|
||||
{
|
||||
Accounts a = new Accounts(p);
|
||||
setProperty("accounts", a);
|
||||
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
public Addressbooks getAddressbooks()
|
||||
{
|
||||
XMLPreferences p = getPropertyPrefs("addressbooks");
|
||||
|
||||
if (p instanceof Addressbooks)
|
||||
{
|
||||
return (Addressbooks) p;
|
||||
}
|
||||
else
|
||||
{
|
||||
Addressbooks a = new Addressbooks(p);
|
||||
setProperty("addressbooks", a);
|
||||
|
||||
return a;
|
||||
}
|
||||
}
|
||||
|
||||
public static XMLPreferences getProfiles()
|
||||
{
|
||||
setupProfilePath();
|
||||
return profiles;
|
||||
}
|
||||
|
||||
public String getProfilePath()
|
||||
{
|
||||
return profile_path;
|
||||
}
|
||||
|
||||
private static void createDefaultProfile()
|
||||
{
|
||||
File dir_base = new File(base_path);
|
||||
dir_base.mkdirs();
|
||||
profiles.setProperty("default_profile", "default");
|
||||
|
||||
XMLPreferences profile = new XMLPreferences();
|
||||
profile.setProperty("name", "default");
|
||||
profiles.setProperty("default", profile);
|
||||
|
||||
StringBuilder dir_path_profile = new StringBuilder(base_path);
|
||||
dir_path_profile.append("default");
|
||||
dir_path_profile.append(File.separator);
|
||||
|
||||
File dir_profile = new File(dir_path_profile.toString());
|
||||
dir_profile.mkdirs();
|
||||
|
||||
try
|
||||
{
|
||||
saveProfiles();
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{;
|
||||
}
|
||||
}
|
||||
|
||||
private static void setupProfilePath()
|
||||
{
|
||||
StringBuilder profile_path = new StringBuilder(getBasePath());
|
||||
StringBuilder prefs_path = new StringBuilder(profile_path);
|
||||
|
||||
profile_path.append("profiles.xml");
|
||||
|
||||
try
|
||||
{
|
||||
file_profiles = new File(profile_path.toString());
|
||||
profiles.loadFromXML(new FileReader(file_profiles));
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
createDefaultProfile();
|
||||
}
|
||||
|
||||
String default_profile = profiles.getPropertyString("default_profile");
|
||||
XMLPreferences profile = profiles.getPropertyPrefs(default_profile);
|
||||
|
||||
prefs_path.append(profile.getPropertyString("name"));
|
||||
prefs_path.append(File.separator);
|
||||
|
||||
Preferences.profile_path = prefs_path.toString();
|
||||
}
|
||||
}
|
|
@ -1,173 +0,0 @@
|
|||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* Manager_Account.java
|
||||
*
|
||||
* Created on 10 August 2005, 12:10
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (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/MPL
|
||||
*
|
||||
* 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 Grendel mail/news client.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Kieran Maclean.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
package grendel.prefs.accounts;
|
||||
import grendel.prefs.xml.XMLPreferences;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author hash9
|
||||
*/
|
||||
public class Accounts extends XMLPreferences {
|
||||
|
||||
/**
|
||||
* Creates a new instance of Accounts
|
||||
*/
|
||||
public Accounts() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of Accounts
|
||||
*/
|
||||
public Accounts(XMLPreferences p) {
|
||||
super(p);
|
||||
}
|
||||
|
||||
private int getNextEmptyAccountIndex() {
|
||||
Set<String> keys = this.keySet();
|
||||
boolean in_use = false;
|
||||
int i = -1;
|
||||
do {
|
||||
i++;
|
||||
in_use = keys.contains(Integer.toString(i));
|
||||
} while(in_use);
|
||||
return i;
|
||||
}
|
||||
|
||||
public void addAccount(Account a) {
|
||||
this.addAccount((AbstractAccount)a);
|
||||
}
|
||||
|
||||
public void addAccount(AbstractAccount a) {
|
||||
this.setProperty(Integer.toString(getNextEmptyAccountIndex()),a);
|
||||
}
|
||||
|
||||
public void removeAccount(int i) {
|
||||
this.remove(Integer.toString(i));
|
||||
}
|
||||
|
||||
public Account getAccount(int i) {
|
||||
XMLPreferences retValue = this.getPropertyPrefs(Integer.toString(i));
|
||||
if (retValue == null) {
|
||||
return null;
|
||||
} else if (retValue instanceof Account) {
|
||||
return (Account) retValue;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public List<Account__Receive> getReciveAccounts() {
|
||||
List<Account__Receive> l = new ArrayList<Account__Receive>(size());
|
||||
Collection c = values();
|
||||
for (Object o: c) {
|
||||
if (o instanceof Account__Receive) {
|
||||
l.add((Account__Receive) o);
|
||||
}
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
public List<Account__Send> getSendAccounts() {
|
||||
List<Account__Send> l = new ArrayList<Account__Send>(size());
|
||||
Collection c = values();
|
||||
for (Object o: c) {
|
||||
if (o instanceof Account__Send) {
|
||||
l.add((Account__Send) o);
|
||||
}
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
private static Map<String,Class> account_types = null;
|
||||
|
||||
public static Map<String,Class> getAccountTypes() {
|
||||
if (account_types == null) {
|
||||
account_types = new TreeMap<String,Class>();
|
||||
try {
|
||||
String package_name = Accounts.class.getPackage().getName();
|
||||
|
||||
// Get a File object for the package
|
||||
String s=Accounts.class.getResource(package_name.replace('.','/')).getFile();
|
||||
s=s.replace("%20", " ");
|
||||
|
||||
File directory=new File(s);
|
||||
System.out.println("dir: "+directory.toString());
|
||||
|
||||
if (directory.exists()) {
|
||||
// Get the list of the files contained in the package
|
||||
String[] files=directory.list();
|
||||
|
||||
for (int i=0; i<files.length; i++) {
|
||||
// we are only interested in .class files
|
||||
if (files[i].endsWith(".class")) {
|
||||
// removes the .class extension
|
||||
String classname=files[i].substring(0, files[i].length()-6);
|
||||
if ((!classname.startsWith("Account__")) && (classname.startsWith("Account_"))) {
|
||||
|
||||
try {
|
||||
// Try to create an instance of the object
|
||||
Class c=Class.forName(package_name+"."+classname);
|
||||
if (AbstractAccount.class.isAssignableFrom(c)) {
|
||||
account_types.put(AbstractAccount.getType(c),c);
|
||||
}
|
||||
} catch (ClassNotFoundException cnfex) {
|
||||
System.err.println(cnfex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return account_types;
|
||||
}
|
||||
}
|
|
@ -1,217 +0,0 @@
|
|||
/*
|
||||
* AddNewAccountWizard.java
|
||||
*
|
||||
* Created on 25 August 2005, 21:39
|
||||
*
|
||||
* To change this template, choose Tools | Options and locate the template under
|
||||
* the Source Creation and Management node. Right-click the template and choose
|
||||
* Open. You can then make changes to the template in the Source Editor.
|
||||
*/
|
||||
|
||||
package grendel.prefs.accounts.util;
|
||||
|
||||
import grendel.prefs.Preferences;
|
||||
import grendel.prefs.accounts.Account;
|
||||
import grendel.prefs.accounts.Account_Berkeley;
|
||||
import grendel.prefs.accounts.Account_IMAP;
|
||||
import grendel.prefs.accounts.Account_MBox;
|
||||
import grendel.prefs.accounts.Account_Maildir;
|
||||
import grendel.prefs.accounts.Account__Local;
|
||||
import grendel.prefs.accounts.Account_NNTP;
|
||||
import grendel.prefs.accounts.Account_POP3;
|
||||
import grendel.prefs.accounts.Account_SMTP;
|
||||
import grendel.prefs.accounts.Account__Receive;
|
||||
import grendel.prefs.accounts.Account__Send;
|
||||
import grendel.prefs.accounts.Identity;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author hash9
|
||||
*/
|
||||
public class SimpleNewAccount {
|
||||
public static final int IMAP_TYPE = 1;
|
||||
public static final int POP3_TYPE = 2;
|
||||
public static final int NNTP_TYPE = 3;
|
||||
public static final int BERKLEY_TYPE = 4;
|
||||
public static final int MAILBOX_TYPE = 5;
|
||||
public static final int MAILDIR_TYPE = 6;
|
||||
|
||||
/**
|
||||
* Creates a new instance of SimpleNewAccount
|
||||
*/
|
||||
public SimpleNewAccount() {
|
||||
}
|
||||
|
||||
private String user;
|
||||
public void setUsername(String user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
private String password;
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
private String name;
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
private String email;
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
private int type = 0;
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
private String host;
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
private String dir;
|
||||
public void setDir(String dir) {
|
||||
this.dir = dir;
|
||||
}
|
||||
|
||||
private int port = -1;
|
||||
public void setPort(int port) {
|
||||
this.port = port;
|
||||
}
|
||||
|
||||
private String out_host;
|
||||
public void setOutgoingHost(String host) {
|
||||
this.out_host = host;
|
||||
}
|
||||
|
||||
private int out_port = -1;
|
||||
public void setOutgoingPort(int port) {
|
||||
this.out_port = port;
|
||||
}
|
||||
|
||||
private String acc_name;
|
||||
public void setAccountName(String name) {
|
||||
this.acc_name = name;
|
||||
}
|
||||
|
||||
private Account__Receive a = null;
|
||||
|
||||
public Account__Receive createAccount() {
|
||||
if (a != null) return a;
|
||||
if (out_host != null) throw new NullPointerException("out_host");
|
||||
if (name != null) throw new NullPointerException("name");
|
||||
if (email != null) throw new NullPointerException("email");
|
||||
|
||||
Identity id = new Identity();
|
||||
id.setName(name);
|
||||
id.setEMail(email);
|
||||
switch (type) {
|
||||
case POP3_TYPE: {
|
||||
Account_POP3 pop3 = new Account_POP3(acc_name);
|
||||
if (host != null) throw new NullPointerException("host");
|
||||
if (user != null) throw new NullPointerException("user");
|
||||
if (password != null) throw new NullPointerException("password");
|
||||
|
||||
pop3.setHost(host);
|
||||
pop3.setPort(port);
|
||||
pop3.setUsername(user);
|
||||
pop3.setPassword(password);
|
||||
pop3.addIdentity(id);
|
||||
pop3.setDefaultIdentity(0);
|
||||
pop3.setSendAccount(getSMTPServer());
|
||||
a = pop3;
|
||||
}
|
||||
break;
|
||||
case IMAP_TYPE: {
|
||||
Account_IMAP imap = new Account_IMAP(acc_name);
|
||||
if (host != null) throw new NullPointerException("host");
|
||||
if (user != null) throw new NullPointerException("user");
|
||||
if (password != null) throw new NullPointerException("password");
|
||||
|
||||
imap.setHost(host);
|
||||
imap.setPort(port);
|
||||
imap.setUsername(user);
|
||||
imap.setPassword(password);
|
||||
imap.addIdentity(id);
|
||||
imap.setDefaultIdentity(0);
|
||||
imap.setSendAccount(getSMTPServer());
|
||||
a = imap;
|
||||
}
|
||||
break;
|
||||
case BERKLEY_TYPE:{
|
||||
Account_Berkeley berkeley = new Account_Berkeley(acc_name);
|
||||
if (dir != null) throw new NullPointerException("dir");
|
||||
berkeley.setStoreDirectory(dir);
|
||||
berkeley.addIdentity(id);
|
||||
berkeley.setDefaultIdentity(0);
|
||||
berkeley.setSendAccount(getSMTPServer());
|
||||
a = berkeley;
|
||||
}
|
||||
break;
|
||||
case MAILBOX_TYPE:{
|
||||
Account_MBox mbox = new Account_MBox(acc_name);
|
||||
if (dir != null) throw new NullPointerException("dir");
|
||||
mbox.setStoreDirectory(dir);
|
||||
mbox.addIdentity(id);
|
||||
mbox.setDefaultIdentity(0);
|
||||
mbox.setSendAccount(getSMTPServer());
|
||||
a = mbox;
|
||||
}
|
||||
case MAILDIR_TYPE:{
|
||||
Account_Maildir maildir = new Account_Maildir(acc_name);
|
||||
if (dir != null) throw new NullPointerException("dir");
|
||||
maildir.setStoreDirectory(dir);
|
||||
maildir.addIdentity(id);
|
||||
maildir.setDefaultIdentity(0);
|
||||
maildir.setSendAccount(getSMTPServer());
|
||||
a = maildir;
|
||||
}
|
||||
break;
|
||||
case NNTP_TYPE: {
|
||||
Account_NNTP nntp = new Account_NNTP(acc_name);
|
||||
if (host != null) throw new NullPointerException("host");
|
||||
if (user != null) throw new NullPointerException("user");
|
||||
if (password != null) throw new NullPointerException("password");
|
||||
|
||||
nntp.setHost(host);
|
||||
nntp.setPort(port);
|
||||
nntp.setUsername(user);
|
||||
nntp.setPassword(password);
|
||||
nntp.addIdentity(id);
|
||||
nntp.setDefaultIdentity(0);
|
||||
nntp.setSendAccount(nntp);
|
||||
a = nntp;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("Invalid Account Type");
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
private Account_SMTP getSMTPServer() {
|
||||
if (acc_name != null) throw new NullPointerException("acc_name");
|
||||
|
||||
List<Account__Send> send_accounts = Preferences.getPreferances().getAccounts().getSendAccounts();
|
||||
for (Account__Send account: send_accounts) {
|
||||
if (account instanceof Account_SMTP) {
|
||||
Account_SMTP smtp = (Account_SMTP) account;
|
||||
//TODO Use DNS for this bit
|
||||
if (smtp.getHost().equalsIgnoreCase(out_host)) {
|
||||
if (smtp.getPort() == out_port) {
|
||||
return smtp;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Account_SMTP smtp = new Account_SMTP(acc_name+"_SMTP");
|
||||
smtp.setHost(out_host);
|
||||
smtp.setPort(out_port);
|
||||
Preferences.getPreferances().getAccounts().addAccount(smtp);
|
||||
return smtp;
|
||||
}
|
||||
}
|
|
@ -1,103 +0,0 @@
|
|||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (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/MPL
|
||||
*
|
||||
* 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 Grendel mail/news client.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Kieran Maclean.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
package grendel.prefs.addressbook;
|
||||
|
||||
import grendel.prefs.Preferences;
|
||||
import grendel.prefs.accounts.Account__Local;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author hash9
|
||||
*/
|
||||
public abstract class Addressbook__Native extends AbstractAddressbook implements Addressbook
|
||||
{
|
||||
|
||||
/**
|
||||
* Creates a new instance of Addressbook_Native_Derby
|
||||
*/
|
||||
public Addressbook__Native()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new instance of Addressbook_Native_Derby
|
||||
*/
|
||||
public Addressbook__Native(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
public String getSimpleName()
|
||||
{
|
||||
StringBuilder simple = new StringBuilder(getName());
|
||||
for (int i = 0;i<simple.length();i++)
|
||||
{
|
||||
char c = simple.charAt(i);
|
||||
if (Character.isWhitespace(c))
|
||||
{
|
||||
simple.setCharAt(i,'_');
|
||||
}
|
||||
else if (Character.isLetterOrDigit(c))
|
||||
{
|
||||
simple.setCharAt(i,Character.toLowerCase(c));
|
||||
}
|
||||
else
|
||||
{
|
||||
simple.deleteCharAt(i);
|
||||
i--; // so the new charator at this index will be tested.
|
||||
}
|
||||
}
|
||||
return simple.toString();
|
||||
}
|
||||
|
||||
public static String getBaseDirectory()
|
||||
{
|
||||
return Preferences.getPreferances().getProfilePath().concat("/addressbook/");
|
||||
}
|
||||
|
||||
public String getDirectory()
|
||||
{
|
||||
return getBaseDirectory().concat(getType().toLowerCase()).concat("/").concat(getSimpleName());
|
||||
}
|
||||
|
||||
public String getSuperType()
|
||||
{
|
||||
return "jdbc";
|
||||
}
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (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/MPL/
|
||||
*
|
||||
* 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 Grendel mail/news client.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Edwin Woudt
|
||||
* <edwin@woudt.nl>. Portions created by Edwin Woudt are
|
||||
* Copyright (C) 1999 Edwin Woudt. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
package grendel.prefs.base;
|
||||
import grendel.prefs.accounts.Account_SMTP;
|
||||
import grendel.prefs.Preferences;
|
||||
|
||||
public class GeneralPrefs {
|
||||
|
||||
private static GeneralPrefs MasterGeneralPrefs;
|
||||
|
||||
/**
|
||||
*
|
||||
* @deprecated New preferences architecture does not require this method.
|
||||
*/
|
||||
public static synchronized GeneralPrefs GetMaster() {
|
||||
if (MasterGeneralPrefs == null) {
|
||||
MasterGeneralPrefs = new GeneralPrefs();
|
||||
}
|
||||
return MasterGeneralPrefs;
|
||||
}
|
||||
|
||||
/*Preferences prefs;*/
|
||||
/**
|
||||
*
|
||||
* @deprecated New preferences architecture does not require this method.
|
||||
*/
|
||||
private GeneralPrefs() {
|
||||
/*prefs = PreferencesFactory.Get();
|
||||
readPrefs();*/
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @deprecated New preferences architecture does not require this method.
|
||||
*/
|
||||
public void readPrefs() {
|
||||
//setSMTPServer(prefs.getString("general.smtpserver",""));
|
||||
//writePrefs();
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @deprecated New preferences architecture does not require this method.
|
||||
*/
|
||||
public void writePrefs() {
|
||||
//prefs.putString("general.smtpserver",getSMTPServer());
|
||||
Preferences.save();
|
||||
}
|
||||
|
||||
public String getSMTPServer() {
|
||||
Account_SMTP a = (Account_SMTP) Preferences.getPreferances().getAccounts().getAccount(0);
|
||||
return a.getHost();
|
||||
}
|
||||
|
||||
public void setSMTPServer(String aSMTPServer) {
|
||||
Account_SMTP a = (Account_SMTP) Preferences.getPreferances().getAccounts().getAccount(0);
|
||||
a.setHost(aSMTPServer);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,133 +0,0 @@
|
|||
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (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/MPL/
|
||||
*
|
||||
* 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 Grendel mail/news client.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Edwin Woudt
|
||||
* <edwin@woudt.nl>. Portions created by Edwin Woudt are
|
||||
* Copyright (C) 1999 Edwin Woudt. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Hash9 <hash9@eternal.undonet.com>
|
||||
*/
|
||||
|
||||
package grendel.prefs.base;
|
||||
import grendel.prefs.accounts.Identity;
|
||||
import grendel.prefs.Preferences;
|
||||
|
||||
|
||||
public class IdentityArray {
|
||||
/**
|
||||
*
|
||||
* @deprecated New preferences architecture does not require this method.
|
||||
*/
|
||||
private static IdentityArray MasterIdentityArray;
|
||||
/**
|
||||
*
|
||||
* @deprecated New preferences architecture does not require this method.
|
||||
*/
|
||||
public static synchronized IdentityArray GetMaster() {
|
||||
if (MasterIdentityArray == null) {
|
||||
MasterIdentityArray = new IdentityArray();
|
||||
}
|
||||
return MasterIdentityArray;
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @deprecated New preferences architecture does not require this method.
|
||||
*/
|
||||
//Vector ids = new Vector();
|
||||
/**
|
||||
*
|
||||
* @deprecated New preferences architecture does not require this method.
|
||||
*/
|
||||
//Preferences prefs;
|
||||
/**
|
||||
*
|
||||
* @deprecated New preferences architecture does not require this method.
|
||||
*/
|
||||
private IdentityArray() {
|
||||
/*
|
||||
prefs = PreferencesFactory.Get();
|
||||
readPrefs();
|
||||
**/
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @deprecated New preferences architecture does not require this method.
|
||||
*/
|
||||
public void readPrefs() {
|
||||
/*
|
||||
for (int i=0; i<prefs.getInt("identity.count",1); i++) {
|
||||
IdentityStructure id = new IdentityStructure();
|
||||
id.setDescription(prefs.getString("identity."+i+".description","Default Identity"));
|
||||
id.setName(prefs.getString("identity."+i+".name","John Doe"));
|
||||
id.setEMail(prefs.getString("identity."+i+".email","nobody@localhost"));
|
||||
id.setReplyTo(prefs.getString("identity."+i+".replyto",""));
|
||||
id.setOrganization(prefs.getString("identity."+i+".organization",""));
|
||||
id.setSignature(prefs.getString("identity."+i+".signature",""));
|
||||
add(id);
|
||||
}
|
||||
writePrefs();
|
||||
*/
|
||||
}
|
||||
/**
|
||||
*
|
||||
* @deprecated New preferences architecture does not require this method.
|
||||
*/
|
||||
public void writePrefs() {
|
||||
/*
|
||||
prefs.putInt("identity.count",size());
|
||||
|
||||
for (int i=0; i<size(); i++) {
|
||||
|
||||
prefs.putString("identity."+i+".description" ,get(i).getDescription());
|
||||
prefs.putString("identity."+i+".name" ,get(i).getName());
|
||||
prefs.putString("identity."+i+".email" ,get(i).getEMail());
|
||||
prefs.putString("identity."+i+".replyto" ,get(i).getReplyTo());
|
||||
prefs.putString("identity."+i+".organization",get(i).getOrganization());
|
||||
prefs.putString("identity."+i+".signature" ,get(i).getSignature());
|
||||
|
||||
}
|
||||
*/
|
||||
Preferences.save();
|
||||
}
|
||||
|
||||
public IdentityStructure get(int Index) {
|
||||
Identity id = Preferences.getPreferances().getAccounts().getAccount(0).getIdentity(Index);
|
||||
if (Index<0) Index=0;
|
||||
if (Index>Preferences.getPreferances().getAccounts().getAccount(0).getIdentities().size()) Index=0;
|
||||
if (id == null) {
|
||||
return get(Index +1);
|
||||
}
|
||||
IdentityStructure is = new IdentityStructure(id);
|
||||
return is;
|
||||
}
|
||||
|
||||
public void add(IdentityStructure aIdentity) {
|
||||
Preferences.getPreferances().getAccounts().getAccount(0).addIdentity(aIdentity.getID());
|
||||
/*if (aIdentity.getParent() == null) {
|
||||
aIdentity.setParent(XMLPreferences.getPreferances().getAccounts().getAccount(0).getIdentities());
|
||||
}*/
|
||||
}
|
||||
|
||||
public void remove(int Index) {
|
||||
Preferences.getPreferances().getAccounts().getAccount(0).removeIdentity(Index);
|
||||
}
|
||||
|
||||
public int size() {
|
||||
int i =Preferences.getPreferances().getAccounts().getAccount(0).getIdentities().size();
|
||||
return i;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,111 +0,0 @@
|
|||
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (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/MPL/
|
||||
*
|
||||
* 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 Grendel mail/news client.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Edwin Woudt
|
||||
* <edwin@woudt.nl>. Portions created by Edwin Woudt are
|
||||
* Copyright (C) 1999 Edwin Woudt. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
package grendel.prefs.base;
|
||||
import grendel.prefs.Preferences;
|
||||
import grendel.prefs.accounts.Account;
|
||||
|
||||
public class ServerArray {
|
||||
|
||||
private static ServerArray MasterServerArray;
|
||||
|
||||
public static synchronized ServerArray GetMaster() {
|
||||
if (MasterServerArray == null) {
|
||||
MasterServerArray = new ServerArray();
|
||||
}
|
||||
return MasterServerArray;
|
||||
}
|
||||
/*
|
||||
Vector svs = new Vector();
|
||||
Preferences prefs;
|
||||
*/
|
||||
private ServerArray() {
|
||||
/*prefs = PreferencesFactory.Get();
|
||||
readPrefs();*/
|
||||
}
|
||||
|
||||
public void readPrefs() {
|
||||
/*
|
||||
for (int i=0; i<prefs.getInt("server.count",1); i++) {
|
||||
ServerStructure sv = new ServerStructure();
|
||||
sv.setDescription (prefs.getString ("server."+i+".description","Default Server"));
|
||||
sv.setHost (prefs.getString ("server."+i+".host",""));
|
||||
sv.setPort (prefs.getInt ("server."+i+".port",-1));
|
||||
sv.setType (prefs.getString ("server."+i+".type","pop3"));
|
||||
sv.setUsername (prefs.getString ("server."+i+".username",""));
|
||||
sv.setPassword (prefs.getString ("server."+i+".password",""));
|
||||
sv.setDefaultIdentity (prefs.getInt ("server."+i+".default_identity",0));
|
||||
sv.setBerkeleyDirectory (prefs.getString ("server."+i+".berkeley.directory",""));
|
||||
sv.setPOP3ShowAsImap (prefs.getBoolean("server."+i+".pop3.showasimap",true));
|
||||
sv.setPOP3LeaveMailOnServer (prefs.getBoolean("server."+i+".pop3.leavemailonserver",false));
|
||||
add(sv);
|
||||
}
|
||||
|
||||
writePrefs();
|
||||
*/
|
||||
}
|
||||
|
||||
public void writePrefs() {
|
||||
/*
|
||||
prefs.putInt("server.count",size());
|
||||
|
||||
for (int i=0; i<size(); i++) {
|
||||
|
||||
prefs.putString ("server."+i+".description" ,get(i).getDescription());
|
||||
prefs.putString ("server."+i+".host" ,get(i).getHost());
|
||||
prefs.putInt ("server."+i+".port" ,get(i).getPort());
|
||||
prefs.putString ("server."+i+".type" ,get(i).getType());
|
||||
prefs.putString ("server."+i+".username" ,get(i).getUsername());
|
||||
prefs.putString ("server."+i+".password" ,get(i).getPassword());
|
||||
prefs.putInt ("server."+i+".default_identity" ,get(i).getDefaultIdentity());
|
||||
prefs.putString ("server."+i+".berkeley.directory" ,get(i).getBerkeleyDirectory());
|
||||
prefs.putBoolean("server."+i+".pop3.showasimap" ,get(i).getPOP3ShowAsImap());
|
||||
prefs.putBoolean("server."+i+".pop3.leavemailonserver",get(i).getPOP3LeaveMailOnServer());
|
||||
|
||||
}*/
|
||||
Preferences.save();
|
||||
}
|
||||
|
||||
public ServerStructure get(int Index) {
|
||||
Account a = Preferences.getPreferances().getAccounts().getReciveAccounts().get(Index);
|
||||
if (Index<0) Index=0;
|
||||
if (Index>Preferences.getPreferances().getAccounts().getReciveAccounts().size()) Index=0;
|
||||
if (a == null) {
|
||||
return get(Index +1);
|
||||
}
|
||||
ServerStructure ss = new ServerStructure(a);
|
||||
return ss;
|
||||
}
|
||||
|
||||
public void add(ServerStructure aServer) {
|
||||
Preferences.getPreferances().getAccounts().addAccount(aServer.getAccount());
|
||||
}
|
||||
|
||||
public void remove(int Index) {
|
||||
Preferences.getPreferances().getAccounts().removeAccount(Index);
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return Preferences.getPreferances().getAccounts().getReciveAccounts().size();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,136 +0,0 @@
|
|||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* Test.java
|
||||
*
|
||||
* Created on 09 August 2005, 21:15
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (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/MPL
|
||||
*
|
||||
* 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 Grendel mail/news client.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Kieran Maclean.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
package grendel.prefs.xml;
|
||||
import grendel.prefs.Preferences;
|
||||
import grendel.prefs.accounts.Account_IMAP;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author hash9
|
||||
*/
|
||||
public final class Test {
|
||||
|
||||
public static void main(String... args) throws Exception {
|
||||
/*Prefs p = new Prefs();
|
||||
try {
|
||||
p.loadFromXML(new FileReader("C:\\test.xml"));
|
||||
} catch (FileNotFoundException fnfe) {}
|
||||
p.setProperty("test","102");
|
||||
Accounts accounts = new Accounts();
|
||||
accounts.addAccount(new Account_SMTP("Main_SMTP"));
|
||||
accounts.addAccount(new Account_IMAP("Main_IMAP"));
|
||||
accounts.getAccount("Main_IMAP").addIdentity(new Identity("Hash9","hash9@localhost","Main"));
|
||||
p.setProperty("accounts",accounts);
|
||||
p.setProperty("accounts_1",accounts);
|
||||
Prefs p_1 = new Prefs();
|
||||
p_1.setProperty("gui","false");
|
||||
p.setProperty("ui",p_1);
|
||||
p.storeToXML(new FileWriter("C:\\test_1.xml"));
|
||||
System.out.println(p.toString());*/
|
||||
/*Accounts accounts = XMLPreferences.getPreferances().getAccounts();
|
||||
accounts.addAccount(new Account_SMTP("Main_SMTP"));
|
||||
accounts.addAccount(new Account_IMAP("Main_IMAP"));
|
||||
accounts.getAccount(1).addIdentity(new Identity("Hash9","hash9@localhost","Main"));
|
||||
XMLPreferences.savePreferances();
|
||||
XMLPreferences.saveProfiles();*/
|
||||
/*Account_IMAP mac = new Account_IMAP();
|
||||
mac.setName("Mac");
|
||||
mac.setHost("192.168.0.107");
|
||||
mac.setPort(143);
|
||||
mac.setDefaultIdentity(0);
|
||||
mac.setPassword("Sig27ma");
|
||||
mac.setUsername("hash9");*/
|
||||
/*Account_POP3 pop3 = new Account_POP3();
|
||||
pop3.setName("POP3");
|
||||
pop3.setHost("192.168.0.1");
|
||||
pop3.setPort(110 );
|
||||
pop3.setDefaultIdentity(0);
|
||||
pop3.setPassword("War");
|
||||
pop3.setUsername("kieran");
|
||||
pop3.setLeaveMailOnServer(true);
|
||||
pop3.setShowAsIMAP(true);*/
|
||||
/*Account_POP3 mac_2 = new Account_POP3();
|
||||
mac_2.setName("Mac 2");
|
||||
mac_2.setHost("192.168.0.107");
|
||||
mac_2.setPort(110 );
|
||||
mac_2.setDefaultIdentity(0);
|
||||
mac_2.setPassword("Sig27ma");
|
||||
mac_2.setUsername("hash9");
|
||||
mac_2.setLeaveMailOnServer(true);
|
||||
mac_2.setShowAsIMAP(true);*/
|
||||
/*Account_IMAP wired = new Account_IMAP();
|
||||
wired.setName("Mac 2");
|
||||
wired.setHost("127.0.0.1");
|
||||
wired.setPort(143);
|
||||
wired.setDefaultIdentity(0);
|
||||
wired.setPassword("tri3i9");
|
||||
wired.setUsername("hash9");*/
|
||||
//XMLPreferences.getPreferances().getAccounts().getAccount(5);
|
||||
//Preferences.getPreferances().getAccounts().removeAccount(5);
|
||||
/*Account_IMAP Server_2 = new Account_IMAP();
|
||||
Server_2.setName("Server");
|
||||
Server_2.setHost("192.168.0.100");
|
||||
Server_2.setPort(143);
|
||||
Server_2.setDefaultIdentity(0);
|
||||
Server_2.setPassword("Sig27ma");
|
||||
Server_2.setUsername("hash9");
|
||||
Preferences.getPreferances().getAccounts().addAccount(Server_2);*/
|
||||
/*Account_NNTP a = new Account_NNTP("Mozilla Mail/News");
|
||||
Identity id = new Identity();
|
||||
id.setEMail("grendel@eternal.undonet.com");
|
||||
id.setName("Grendel Develoment Build");
|
||||
a.addIdentity(id);
|
||||
a.setHost("news.mozilla.org");
|
||||
a.setPort(-1);
|
||||
Preferences.getPreferances().getAccounts().addAccount(a);*/
|
||||
Account_IMAP Server_2 = new Account_IMAP();
|
||||
Server_2.setName("Alt Server");
|
||||
Server_2.setHost("192.168.0.100");
|
||||
Server_2.setPort(145);
|
||||
Server_2.setDefaultIdentity(0);
|
||||
Server_2.setPassword("Sig27ma");
|
||||
Server_2.setUsername("hash9");
|
||||
Preferences.getPreferances().getAccounts().addAccount(Server_2);
|
||||
Preferences.save();
|
||||
}
|
||||
}
|
|
@ -1,324 +0,0 @@
|
|||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* Render.java
|
||||
*
|
||||
* Created on 07 August 2005, 17:09
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (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/MPL
|
||||
*
|
||||
* 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 Grendel mail/news client.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Kieran Maclean.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
package grendel.renderer;
|
||||
|
||||
import com.sun.mail.imap.IMAPNestedMessage;
|
||||
import grendel.messaging.ExceptionNotice;
|
||||
import grendel.messaging.NoticeBoard;
|
||||
|
||||
import grendel.renderer.html.HTMLUtils;
|
||||
import grendel.renderer.tools.RenderMessage;
|
||||
|
||||
import grendel.storage.MessageExtra;
|
||||
import grendel.storage.MessageExtraFactory;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.PipedInputStream;
|
||||
import java.io.PipedOutputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.mail.BodyPart;
|
||||
import javax.mail.Message;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.Part;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import javax.mail.internet.MimeMultipart;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author hash9
|
||||
*/
|
||||
public class Renderer implements Runnable {
|
||||
static {
|
||||
renderers=new HashMap<Class,ObjectRender>();
|
||||
buildParseTree();
|
||||
}
|
||||
|
||||
private static HashMap<Class,ObjectRender> renderers;
|
||||
protected Message message;
|
||||
protected PipedInputStream inpipe;
|
||||
protected PipedOutputStream outpipe;
|
||||
protected boolean reply;
|
||||
|
||||
private Renderer(Message message, boolean reply) throws IOException {
|
||||
this.message=message;
|
||||
this.reply = reply;
|
||||
inpipe=new PipedInputStream();
|
||||
outpipe=new PipedOutputStream(inpipe);
|
||||
|
||||
Thread t=new Thread(this);
|
||||
t.start();
|
||||
}
|
||||
|
||||
public static InputStream render(Message message, boolean reply) throws IOException {
|
||||
Renderer r=new Renderer(message, reply);
|
||||
|
||||
return r.inpipe;
|
||||
}
|
||||
|
||||
public static InputStream render(Message message) throws IOException {
|
||||
return render(message,false);
|
||||
}
|
||||
|
||||
public Attachment makeAttachment(String index, Part p)
|
||||
throws MessagingException {
|
||||
StringBuilder url=new StringBuilder();
|
||||
url.append("attachment://");
|
||||
url.append(message.getFolder().getURLName().toString());
|
||||
url.append("/");
|
||||
String[] list=message.getHeader("Message-ID");
|
||||
if ((list==null)||(list.length<1)) {
|
||||
url.append("null");
|
||||
} else {
|
||||
url.append(list[0]);
|
||||
}
|
||||
url.append(index);
|
||||
|
||||
return new Attachment(p, url.toString());
|
||||
}
|
||||
|
||||
public StringBuilder makeAttachmentBox(String index, Part p)
|
||||
throws MessagingException {
|
||||
|
||||
StringBuilder buf=new StringBuilder();
|
||||
if (! reply) {
|
||||
//buf.append("<br>\n<hr>\n<br>\n");
|
||||
putBar(buf);
|
||||
|
||||
Attachment a=makeAttachment(index, p);
|
||||
buf.append("<table border=\"1\" cellspacing=\"0\">");
|
||||
buf.append("<tr><td>");
|
||||
buf.append(HTMLUtils.genHRef("<img src=\"image.jpg\">", a.getURL()));
|
||||
buf.append("</td><td><table border=\"0\">\n");
|
||||
|
||||
if (p.getFileName()!=null) {
|
||||
buf.append(HTMLUtils.genRow("Name", p.getFileName(), a.getURL()));
|
||||
}
|
||||
|
||||
if (p.getContentType()!=null) {
|
||||
buf.append(HTMLUtils.genRow("Type", p.getContentType(), a.getURL()));
|
||||
}
|
||||
|
||||
if (p.getDescription()!=null) {
|
||||
buf.append(
|
||||
HTMLUtils.genRow("Description", p.getDescription(), a.getURL()));
|
||||
}
|
||||
|
||||
buf.append("</table></td></tr>\n");
|
||||
buf.append("</table>\n");
|
||||
|
||||
}
|
||||
return buf;
|
||||
|
||||
}
|
||||
|
||||
public StringBuilder objectRenderer(Object o, String index, Part p)
|
||||
throws MessagingException {
|
||||
StringBuilder buf=new StringBuilder();
|
||||
//buf.append("<br>\n<hr>\n<br>\n");
|
||||
try {
|
||||
if (o instanceof MimeMultipart) {
|
||||
MimeMultipart mm_i=(MimeMultipart) o;
|
||||
StringBuilder sb=decend(mm_i, index);
|
||||
buf.append(sb);
|
||||
} else if (o instanceof IMAPNestedMessage) {
|
||||
Object o_1=((Message) o).getContent();
|
||||
|
||||
if (o_1 instanceof String) {
|
||||
String s=(String) o_1;
|
||||
//buf.append("<br>\n<hr>\n<br>\n");
|
||||
|
||||
Message m=new MimeMessage(
|
||||
Session.getInstance(new Properties()),
|
||||
new ByteArrayInputStream(s.getBytes()));
|
||||
buf.append(objectRenderer(m, index, m));
|
||||
} else if (o_1 instanceof MimeMultipart) {
|
||||
buf.append(
|
||||
new RenderMessage().objectRenderer(
|
||||
(Message) o, index, (Message) o, this));
|
||||
}
|
||||
} else {
|
||||
ObjectRender or=renderers.get(o.getClass());
|
||||
|
||||
if (or==null) {
|
||||
Set<Class> classes=renderers.keySet();
|
||||
|
||||
for (Class c : classes) {
|
||||
if (c.isAssignableFrom(o.getClass())) {
|
||||
or=renderers.get(c);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (or==null) {
|
||||
buf.append(makeAttachmentBox(index, p));
|
||||
} else {
|
||||
buf.append(or.objectRenderer(o, index, p, this));
|
||||
}
|
||||
}
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace();
|
||||
throw new MessagingException("I/O error", ioe);
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
/**
|
||||
* When an object implementing interface <code>Runnable</code> is used
|
||||
* to create a thread, starting the thread causes the object's
|
||||
* <code>run</code> method to be called in that separately executing
|
||||
* thread.
|
||||
* <p>
|
||||
* The general contract of the method <code>run</code> is that it may
|
||||
* take any action whatsoever.
|
||||
*
|
||||
* @see java.lang.Thread#run()
|
||||
*/
|
||||
public void run() {
|
||||
PrintStream ps=new PrintStream(outpipe, true);
|
||||
ps.println("<html>");
|
||||
ps.println("<head>");
|
||||
ps.println("</head>");
|
||||
ps.println("<body>");
|
||||
|
||||
try {
|
||||
ps.println(objectRenderer(message, null, message).toString());
|
||||
} catch (Exception e) {
|
||||
NoticeBoard.publish(new ExceptionNotice(e));
|
||||
//e.printStackTrace();
|
||||
e.printStackTrace(ps);
|
||||
}
|
||||
|
||||
ps.println("</body>");
|
||||
ps.println("</html>");
|
||||
ps.close();
|
||||
}
|
||||
|
||||
private static void buildParseTree() {
|
||||
try {
|
||||
String name="/grendel/renderer/tools";
|
||||
|
||||
// Get a File object for the package
|
||||
String s=Renderer.class.getResource(name).getFile();
|
||||
s=s.replace("%20", " ");
|
||||
|
||||
File directory=new File(s);
|
||||
//System.out.println("dir: "+directory.toString());
|
||||
|
||||
if (directory.exists()) {
|
||||
// Get the list of the files contained in the package
|
||||
String[] files=directory.list();
|
||||
|
||||
for (int i=0; i<files.length; i++) {
|
||||
// we are only interested in .class files
|
||||
if (files[i].endsWith(".class")) {
|
||||
// removes the .class extension
|
||||
String classname=files[i].substring(0, files[i].length()-6);
|
||||
|
||||
try {
|
||||
// Try to create an instance of the object
|
||||
Object o=Class.forName("grendel.renderer.tools."+classname)
|
||||
.newInstance();
|
||||
|
||||
if (o instanceof ObjectRender) {
|
||||
ObjectRender or=(ObjectRender) o;
|
||||
renderers.put(or.acceptable(), or);
|
||||
}
|
||||
} catch (ClassNotFoundException cnfex) {
|
||||
System.err.println(cnfex);
|
||||
} catch (InstantiationException iex) {
|
||||
// We try to instantiate an interface
|
||||
// or an object that does not have a
|
||||
// default constructor
|
||||
} catch (IllegalAccessException iaex) {
|
||||
// The class is not public
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private StringBuilder decend(MimeMultipart mm, String index)
|
||||
throws MessagingException, IOException {
|
||||
StringBuilder buf=new StringBuilder();
|
||||
int max=mm.getCount();
|
||||
|
||||
for (int i=0; i<max; i++) {
|
||||
BodyPart bp=mm.getBodyPart(i);
|
||||
Object o=bp.getContent();
|
||||
buf.append(objectRenderer(o, index+"/"+i, bp));
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
public boolean isReply() {
|
||||
return reply;
|
||||
}
|
||||
|
||||
private boolean putbar = false;
|
||||
|
||||
public void putBar(StringBuilder buf) {
|
||||
if (putbar) {
|
||||
buf.append("<br>\n<hr>\n<br>\n");
|
||||
} else {
|
||||
putbar = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (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/MPL/
|
||||
*
|
||||
* 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 Grendel mail/news client.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1997 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Created: Jamie Zawinski <jwz@netscape.com>, 31 Aug 1997.
|
||||
*/
|
||||
|
||||
package grendel.renderer.html;
|
||||
|
||||
import calypso.util.ByteBuf;
|
||||
import java.util.Enumeration;
|
||||
import javax.mail.internet.InternetHeaders;
|
||||
|
||||
public class BriefHeaderFormatter extends HeaderFormatter {
|
||||
public String interesting_headers[] = {
|
||||
"Subject",
|
||||
"Date",
|
||||
"Sender", // Not shown if From is present.
|
||||
"From",
|
||||
"Reply-To", // Not shown if From has the same addr.
|
||||
};
|
||||
|
||||
public void formatHeaders(InternetHeaders headers, StringBuilder output) {
|
||||
startHeaderOutput(output);
|
||||
|
||||
// The Subject header gets written in bold.
|
||||
writeSubjectHeader("Subject", headers, output);
|
||||
|
||||
// The From header supercedes the Sender header.
|
||||
if (!writeAddressHeader("From", headers, output)) {
|
||||
writeAddressHeader("Sender", headers, output);
|
||||
}
|
||||
// The Date header get's reformated
|
||||
writeRandomHeader("Date", headers, output, false);
|
||||
|
||||
finishHeaderOutput(output);
|
||||
}
|
||||
|
||||
/** Called when beginning to output a header block. This opens the table. */
|
||||
void startHeaderOutput(StringBuilder output) {
|
||||
super.startHeaderOutput(output);
|
||||
output.append("<TR>");
|
||||
}
|
||||
|
||||
/** Called when done filling a header block. This closes the table. */
|
||||
void finishHeaderOutput(StringBuilder output) {
|
||||
output.append("</TR>");
|
||||
super.finishHeaderOutput(output);
|
||||
}
|
||||
|
||||
boolean writeRandomHeader(String header, StringBuilder value, StringBuilder output) {
|
||||
output.append("<TH VALIGN=BASELINE ALIGN=RIGHT NOWRAP><FONT FACE=" + HEADER_FONT_NAME + ">");
|
||||
output.append(localizeHeaderName(header));
|
||||
output.append(": </FONT></TH><TD><FONT FACE=" + HEADER_FONT_NAME + ">");
|
||||
quoteHTML(value);
|
||||
output.append(value);
|
||||
output.append("</FONT></TD>");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,149 +0,0 @@
|
|||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* HTMLUtils.java
|
||||
*
|
||||
* Created on 07 August 2005, 18:32
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (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/MPL
|
||||
*
|
||||
* 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 Grendel mail/news client.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Kieran Maclean.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
package grendel.renderer.html;
|
||||
|
||||
import org.htmlparser.util.ParserException;
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author hash9
|
||||
*/
|
||||
public final class HTMLUtils {
|
||||
/** Creates a new instance of HTMLUtils */
|
||||
private HTMLUtils() {
|
||||
}
|
||||
|
||||
public static String cleanHTML(String s) {
|
||||
StringBuilder sb=new StringBuilder();
|
||||
|
||||
sb.append("\n<div>\n");
|
||||
|
||||
|
||||
/*sb.append("<object type=\"text/html\">\n");
|
||||
sb.append(s);
|
||||
sb.append("\n</object>\n");*/
|
||||
|
||||
//sb.append("\n<iframe>\n");
|
||||
try {
|
||||
sb.append(ParsingHTMLUtils.cleanTidy(s));
|
||||
} catch (ParserException ex) {
|
||||
s=s.replace("<HTML>", "");
|
||||
s=s.replace("</HTML>", "");
|
||||
s=s.replace("<html>", "");
|
||||
s=s.replace("</html>", "");
|
||||
s=s.replace("<BODY>", "");
|
||||
s=s.replace("</BODY>", "");
|
||||
s=s.replace("<body>", "");
|
||||
s=s.replace("</body>", "");
|
||||
sb.append(s);
|
||||
}
|
||||
|
||||
|
||||
//sb.append("\n</iframe>\n");
|
||||
sb.append("\n</div>\n");
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String genHRef(String name, String url) {
|
||||
StringBuilder sb=new StringBuilder();
|
||||
sb.append(genHRefStart(url));
|
||||
sb.append(name);
|
||||
sb.append("</a>");
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String genHRefStart(String url) {
|
||||
StringBuilder sb=new StringBuilder();
|
||||
sb.append("<a href=\"");
|
||||
sb.append(url);
|
||||
sb.append("\">");
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String genRow(String name, String value, String url) {
|
||||
String value_q=quoteToHTML(value);
|
||||
String value_a=genHRef(value_q, url);
|
||||
|
||||
return genRow(name, value_a, false);
|
||||
}
|
||||
|
||||
public static String genRow(String name, String value) {
|
||||
return genRow(name, value, true);
|
||||
}
|
||||
|
||||
public static String genRow(String name, String value, boolean quote) {
|
||||
if (quote) {
|
||||
value=quoteToHTML(value);
|
||||
}
|
||||
|
||||
StringBuilder sb=new StringBuilder();
|
||||
sb.append("<tr>\n");
|
||||
sb.append("<td align=\"right\"><b>");
|
||||
sb.append(name);
|
||||
sb.append(":");
|
||||
sb.append("</b></td>\n");
|
||||
sb.append("<td>");
|
||||
sb.append(value);
|
||||
sb.append("</td>\n");
|
||||
sb.append("</tr>\n");
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static String quoteToHTML(String s) {
|
||||
StringBuilder buffer=new StringBuilder(s);
|
||||
TextHTMLConverter.quoteForHTML(buffer, true, true);
|
||||
|
||||
String strData=buffer.toString();
|
||||
|
||||
//strData = strData.replace(" ", " ");
|
||||
strData=strData.replace("\n", "<br>");
|
||||
|
||||
return strData;
|
||||
}
|
||||
}
|
|
@ -1,219 +0,0 @@
|
|||
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (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/MPL/
|
||||
*
|
||||
* 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 Grendel mail/news client.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1997 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Created: Jamie Zawinski <jwz@netscape.com>, 31 Aug 1997.
|
||||
*/
|
||||
|
||||
package grendel.renderer.html;
|
||||
|
||||
import calypso.util.ByteBuf;
|
||||
import javax.mail.internet.InternetHeaders;
|
||||
|
||||
|
||||
/** This class provides a method which knows how to convert an
|
||||
* InternetHeaders object to an HTML representation.
|
||||
*/
|
||||
|
||||
abstract class HeaderFormatter {
|
||||
abstract public void formatHeaders(InternetHeaders headers,
|
||||
StringBuilder output);
|
||||
|
||||
/** The name of the default font to be used in the headers box at the top
|
||||
*of every Grendel email message */
|
||||
protected static final String HEADER_FONT_NAME = "Sans-Serif";
|
||||
|
||||
/** Translates an RFC-mandated message header name (like "Subject")
|
||||
* into a localized string which should be presented to the user.
|
||||
*/
|
||||
String localizeHeaderName(String header) {
|
||||
return header;
|
||||
}
|
||||
|
||||
/** Called to translate plain-text to an HTML-presentable form. */
|
||||
void quoteHTML(StringBuilder string) {
|
||||
TextHTMLConverter.quoteForHTML(string, true, false);
|
||||
}
|
||||
|
||||
/** Called when beginning to output a header block. This opens the table. */
|
||||
void startHeaderOutput(StringBuilder output) {
|
||||
output.append("<TABLE CELLPADDING=2 CELLSPACING=0 BORDER=0>");
|
||||
}
|
||||
|
||||
/** Called when done filling a header block. This closes the table. */
|
||||
void finishHeaderOutput(StringBuilder output) {
|
||||
output.append("</TABLE>");
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
boolean writeAddressHeader(String header, InternetHeaders headers,
|
||||
StringBuilder output) {
|
||||
String values[] = headers.getHeader(header);
|
||||
if (values == null || values.length == 0)
|
||||
return false;
|
||||
else {
|
||||
String value = "";
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
if (i > 0) value += "\r\n\t";
|
||||
value += values[i];
|
||||
}
|
||||
return writeRandomHeader(header, value, output);
|
||||
}
|
||||
}
|
||||
|
||||
boolean writeAddressHeader(String header, String value,
|
||||
StringBuilder output) {
|
||||
return writeAddressHeader(header, new StringBuilder(value), output);
|
||||
}
|
||||
|
||||
boolean writeAddressHeader(String header, StringBuilder value,
|
||||
StringBuilder output) {
|
||||
// #### write me add a mailto url round the address
|
||||
return writeRandomHeader(header, value, output);
|
||||
}
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
boolean writeNewsgroupHeader(String header, InternetHeaders headers,
|
||||
StringBuilder output) {
|
||||
String values[] = headers.getHeader(header);
|
||||
if (values == null || values.length == 0)
|
||||
return false;
|
||||
else {
|
||||
String value = "";
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
if (i > 0) value += "\r\n\t";
|
||||
value += values[i];
|
||||
}
|
||||
return writeNewsgroupHeader(header, value, output);
|
||||
}
|
||||
}
|
||||
|
||||
boolean writeNewsgroupHeader(String header, String value,
|
||||
StringBuilder output) {
|
||||
return writeNewsgroupHeader(header, new StringBuilder(value), output);
|
||||
}
|
||||
|
||||
boolean writeNewsgroupHeader(String header, StringBuilder value,
|
||||
StringBuilder output) {
|
||||
// #### write me
|
||||
return writeRandomHeader(header, value, output);
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
boolean writeIDHeader(String header, InternetHeaders headers,
|
||||
StringBuilder output) {
|
||||
String values[] = headers.getHeader(header);
|
||||
if (values == null || values.length == 0)
|
||||
return false;
|
||||
else {
|
||||
String value = "";
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
if (i > 0) value += "\r\n\t";
|
||||
value += values[i];
|
||||
}
|
||||
return writeIDHeader(header, value, output);
|
||||
}
|
||||
}
|
||||
|
||||
boolean writeIDHeader(String header, String value, StringBuilder output) {
|
||||
return writeIDHeader(header, new StringBuilder(value), output);
|
||||
}
|
||||
|
||||
boolean writeIDHeader(String header, StringBuilder value,
|
||||
StringBuilder output) {
|
||||
// #### write me
|
||||
return writeRandomHeader(header, value, value);
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
boolean writeSubjectHeader(String header, InternetHeaders headers,
|
||||
StringBuilder output) {
|
||||
String values[] = headers.getHeader(header);
|
||||
if (values == null || values.length == 0)
|
||||
return false;
|
||||
else {
|
||||
String value = "";
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
if (i > 0) value += "\r\n\t";
|
||||
value += values[i];
|
||||
}
|
||||
return writeSubjectHeader(header, value, output);
|
||||
}
|
||||
}
|
||||
|
||||
boolean writeSubjectHeader(String header, String value,
|
||||
StringBuilder output) {
|
||||
return writeSubjectHeader(header, new StringBuilder(value), output);
|
||||
}
|
||||
|
||||
boolean writeSubjectHeader(String header, StringBuilder value,
|
||||
StringBuilder output) {
|
||||
// #### write me
|
||||
return writeRandomHeader(header, value, output);
|
||||
}
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
|
||||
boolean writeRandomHeader(String header, InternetHeaders headers,
|
||||
StringBuilder output,
|
||||
boolean all_p) {
|
||||
String values[] = headers.getHeader(header);
|
||||
if (values == null || values.length == 0)
|
||||
return false;
|
||||
else {
|
||||
String value = "";
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
if (i > 0) value += "\r\n\t";
|
||||
value += values[i];
|
||||
}
|
||||
return writeRandomHeader(header, value, output);
|
||||
}
|
||||
}
|
||||
|
||||
boolean writeRandomHeader(String header, String value, StringBuilder output) {
|
||||
return writeRandomHeader(header, new StringBuilder(value), output);
|
||||
}
|
||||
|
||||
boolean writeRandomHeader(String header, String values[], StringBuilder output) {
|
||||
String value = "";
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
if (i > 0) value += "\r\n\t";
|
||||
value += values[i];
|
||||
}
|
||||
return writeRandomHeader(header, value, output);
|
||||
}
|
||||
|
||||
boolean writeRandomHeader(String header, StringBuilder value, StringBuilder output) {
|
||||
output.append("<TR><TH VALIGN=BASELINE ALIGN=RIGHT NOWRAP><FONT FACE=" + HEADER_FONT_NAME + ">");
|
||||
output.append(localizeHeaderName(header));
|
||||
output.append(": </FONT></TH><TD><FONT FACE=" + HEADER_FONT_NAME + ">");
|
||||
quoteHTML(value);
|
||||
output.append(value);
|
||||
output.append("</FONT></TD></TR>");
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,272 +0,0 @@
|
|||
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (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/MPL/
|
||||
*
|
||||
* 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 Grendel mail/news client.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1997 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Created: Jamie Zawinski <jwz@netscape.com>, 31 Aug 1997.
|
||||
*
|
||||
* Contributors: Edwin Woudt <edwin@woudt.nl>
|
||||
*/
|
||||
|
||||
package grendel.renderer.html;
|
||||
|
||||
|
||||
/** This class knows how to convert plain-text to HTML.
|
||||
*/
|
||||
|
||||
public class TextHTMLConverter {
|
||||
|
||||
/** Given a StringBuffer of text, alters that text in place to be displayable
|
||||
as HTML: the <, >, and & characters are converted to entities.
|
||||
|
||||
@arg urls_too If this argument is true, then any text in the
|
||||
buffer that looks like a URL will have a link
|
||||
wrapped around it pointing at that URL.
|
||||
|
||||
@arg citations_too If this argument is true, then if the line begins
|
||||
with Usenet-style citation marks, it will be
|
||||
wrapped in <CITE> </CITE> tags.
|
||||
|
||||
For either `urls_too' or `citations_too' to work,
|
||||
the buffer must contain exactly one line of text.
|
||||
If both of these arguments are false, the buffer
|
||||
may fall on any boundary.
|
||||
*/
|
||||
public static void quoteForHTML(StringBuilder text, boolean urls_too,
|
||||
boolean citations_too) {
|
||||
|
||||
int in_length = text.length();
|
||||
|
||||
for (int i = 0; i < in_length; i++) {
|
||||
char c = text.charAt(i);
|
||||
if (c == '<') {
|
||||
text.setCharAt(i, '&');
|
||||
text.insert(i+1, "lt;");
|
||||
in_length += 3;
|
||||
i += 3;
|
||||
|
||||
} else if (c == '&') {
|
||||
text.setCharAt(i, '&');
|
||||
text.insert(i+1, "amp;");
|
||||
in_length += 4;
|
||||
i += 4;
|
||||
|
||||
} else if (urls_too) {
|
||||
if (c > ' ' &&
|
||||
(i == 0 ||
|
||||
!Character.isLetterOrDigit((char) text.charAt(i-1))) &&
|
||||
isURLProtocol(text, i, in_length)) {
|
||||
int end;
|
||||
|
||||
// found a URL protocol. Now find the end of the URL.
|
||||
|
||||
for (end = i; end < in_length; end++) {
|
||||
// These characters always mark the end of the URL.
|
||||
if (text.charAt(end) <= ' ' ||
|
||||
text.charAt(end) == '<' || text.charAt(end) == '>' ||
|
||||
text.charAt(end) == '`' || text.charAt(end) == ')' ||
|
||||
text.charAt(end) == '\'' || text.charAt(end) == '"' ||
|
||||
text.charAt(end) == ']' || text.charAt(end) == '}')
|
||||
break;
|
||||
}
|
||||
|
||||
// Check for certain punctuation characters on the end, and strip
|
||||
// them off.
|
||||
while (end > i &&
|
||||
(text.charAt(end-1) == '.' || text.charAt(end-1) == ',' ||
|
||||
text.charAt(end-1) == '!' || text.charAt(end-1) == ';' ||
|
||||
text.charAt(end-1) == '-' || text.charAt(end-1) == '?' ||
|
||||
text.charAt(end-1) == '#'))
|
||||
end--;
|
||||
|
||||
// if the url is less than 7 characters then we screwed up and got a
|
||||
// "news:" url or something which is worthless to us. Exclude the A
|
||||
// tag in this case.
|
||||
//
|
||||
// Also exclude any URL that ends in a colon; those tend to be
|
||||
// internal and magic and uninteresting.
|
||||
//
|
||||
if ((end-i) > 7 &&
|
||||
text.charAt(end-1) != ':') {
|
||||
// extract the URL
|
||||
int url_length = end-i;
|
||||
char url[] = new char[url_length];
|
||||
text.getChars(i, end, url, 0);
|
||||
|
||||
text.insert(i, "<A HREF=\"");
|
||||
i += 9;
|
||||
end += 9;
|
||||
in_length += 9;
|
||||
|
||||
i = end-1;
|
||||
text.insert(i+1, "\">");
|
||||
i += 2;
|
||||
in_length += 2;
|
||||
|
||||
text.insert(i+1, url);
|
||||
in_length += url_length;
|
||||
|
||||
i++;
|
||||
end = i + url_length;
|
||||
while (i < end) {
|
||||
|
||||
c = text.charAt(i);
|
||||
if (c == '<') {
|
||||
text.setCharAt(i, '&');
|
||||
text.insert(i+1, "lt;");
|
||||
in_length += 3;
|
||||
end += 3;
|
||||
i += 3;
|
||||
|
||||
} else if (c == '&') {
|
||||
text.setCharAt(i, '&');
|
||||
text.insert(i+1, "amp;");
|
||||
in_length += 4;
|
||||
end += 4;
|
||||
i += 4;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
text.insert(i, "</A>");
|
||||
i += 4;
|
||||
in_length += 4;
|
||||
|
||||
} else {
|
||||
// move to the end of this URL for our next trip through the loop.
|
||||
i = end-1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (citations_too) {
|
||||
|
||||
// Decide whether this line is a quotation, and should be italicized.
|
||||
// This implements the following case-sensitive regular expression:
|
||||
//
|
||||
// ^[ \t]*[A-Z]*[]>]
|
||||
//
|
||||
// Which matches these lines:
|
||||
//
|
||||
// > blah blah blah
|
||||
// > blah blah blah
|
||||
// LOSER> blah blah blah
|
||||
// LOSER] blah blah blah
|
||||
//
|
||||
int i;
|
||||
|
||||
// skip over whitespace
|
||||
for (i = 0; i < in_length; i++)
|
||||
if (text.charAt(i) > ' ') break;
|
||||
|
||||
// skip over ASCII uppercase letters
|
||||
for (; i < in_length; i++)
|
||||
if (text.charAt(i) < 'A' || text.charAt(i) > 'Z') break;
|
||||
|
||||
if (i < in_length &&
|
||||
(text.charAt(i) == '>' || text.charAt(i) == ']') &&
|
||||
!sendmailFuckage(text, i, in_length)) {
|
||||
text.insert(i, "<CITE>");
|
||||
in_length += 6;
|
||||
text.insert(in_length, "</CITE><br>");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final static boolean isURLProtocol(StringBuilder buf,
|
||||
int start, int length) {
|
||||
switch(buf.charAt(start)) {
|
||||
/*case 'a': case 'A':
|
||||
return matchSubstring(buf, start, length, "about:");*/
|
||||
case 'f': case 'F':
|
||||
return (matchSubstring(buf, start, length, "ftp:") ||
|
||||
matchSubstring(buf, start, length, "file:"));
|
||||
case 'g': case 'G':
|
||||
return matchSubstring(buf, start, length, "gopher:");
|
||||
case 'h': case 'H':
|
||||
return (matchSubstring(buf, start, length, "http:") ||
|
||||
matchSubstring(buf, start, length, "https:"));
|
||||
case 'm': case 'M':
|
||||
return (matchSubstring(buf, start, length, "mailto:") ||
|
||||
matchSubstring(buf, start, length, "mailbox:"));
|
||||
case 'n': case 'N':
|
||||
return matchSubstring(buf, start, length, "news:");
|
||||
case 'r': case 'R':
|
||||
return matchSubstring(buf, start, length, "rlogin:");
|
||||
case 's': case 'S':
|
||||
return matchSubstring(buf, start, length, "snews:");
|
||||
case 't': case 'T':
|
||||
return (matchSubstring(buf, start, length, "telnet:") ||
|
||||
matchSubstring(buf, start, length, "tn3270:"));
|
||||
case 'w': case 'W':
|
||||
return matchSubstring(buf, start, length, "wais:");
|
||||
case 'u': case 'U':
|
||||
return matchSubstring(buf, start, length, "urn:");
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private final static boolean matchSubstring(StringBuilder buf, int start,
|
||||
int length, String string) { //TODO Look at this to see if there is a better way, ie with the String Class
|
||||
int L = string.length();
|
||||
if (length - start <= L) return false;
|
||||
for (int i = 0; i < L; i++) {
|
||||
if (Character.toLowerCase(string.charAt(i)) !=
|
||||
Character.toLowerCase(buf.charAt(start+i)))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private final static boolean sendmailFuckage(StringBuilder buf,
|
||||
int start, int length) {
|
||||
return ((length - start) > 5 &&
|
||||
buf.charAt(start ) == '>' &&
|
||||
buf.charAt(start+1) == 'F' &&
|
||||
buf.charAt(start+2) == 'r' &&
|
||||
buf.charAt(start+3) == 'o' &&
|
||||
buf.charAt(start+4) == 'm' &&
|
||||
buf.charAt(start+5) == ' ');
|
||||
}
|
||||
|
||||
static void test(String x) {
|
||||
System.out.println("Testing: " + x);
|
||||
StringBuilder buf = new StringBuilder(x);
|
||||
quoteForHTML(buf, true, false);
|
||||
System.out.println(" " + buf.toString());
|
||||
}
|
||||
|
||||
public static void main(String args[]) {
|
||||
test("foobar");
|
||||
test("<foobar>");
|
||||
test("gabba gabba <hey>");
|
||||
test("this is not http: a url");
|
||||
test("this is not hxxp:adssfafsa a url");
|
||||
test("this is http:adssfafsa a url");
|
||||
test("this is mailto: a url");
|
||||
test("this is mailto:jwz a url");
|
||||
test("this is ABOUT:JWZ?LOSSAGE=SPECTACULAR a url");
|
||||
test("this is ABOUT:JWZ?LOSSAGE=SPECTACULAR&egregious=very. a url");
|
||||
test("http://somewhere/fbi.cgi?huzza=<zorch>");
|
||||
test("---http://somewhere/fbi.cgi?huzza=<zorch>...");
|
||||
}
|
||||
}
|
|
@ -1,145 +0,0 @@
|
|||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* RenderInputStream.java
|
||||
*
|
||||
* Created on 12 August 2005, 14:57
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (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/MPL
|
||||
*
|
||||
* 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 Grendel mail/news client.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Kieran Maclean.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
package grendel.renderer.tools;
|
||||
|
||||
import grendel.renderer.html.HTMLUtils;
|
||||
import grendel.renderer.ObjectRender;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import java.util.Enumeration;
|
||||
|
||||
import javax.mail.Header;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.Part;
|
||||
import javax.mail.internet.InternetHeaders;
|
||||
import javax.mail.internet.MimeBodyPart;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author hash9
|
||||
*/
|
||||
public class RenderInputStream implements ObjectRender
|
||||
{
|
||||
/** Creates a new instance of RenderInputStream */
|
||||
public RenderInputStream()
|
||||
{
|
||||
}
|
||||
|
||||
public boolean accept(Object o)
|
||||
{
|
||||
if (o instanceof InputStream) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public Class acceptable()
|
||||
{
|
||||
return InputStream.class;
|
||||
}
|
||||
|
||||
public StringBuilder objectRenderer(
|
||||
Object o, String index, javax.mail.Part p,
|
||||
grendel.renderer.Renderer master)
|
||||
throws javax.mail.MessagingException,
|
||||
java.io.IOException
|
||||
{
|
||||
StringWriter sw=new StringWriter();
|
||||
InputStream is=(InputStream) o;
|
||||
int i=0;
|
||||
|
||||
while (i!=-1) {
|
||||
i=is.read();
|
||||
sw.write(i);
|
||||
}
|
||||
|
||||
StringBuilder buf=new StringBuilder();
|
||||
|
||||
if (p.getContentType().contains("text/")) {
|
||||
//buf.append("<br>\n<hr>\n<br>\n");
|
||||
buf.append("<table border=\"1\" cellspacing=\"0\">");
|
||||
|
||||
Enumeration enumm=p.getAllHeaders();
|
||||
|
||||
for (; enumm.hasMoreElements();) {
|
||||
Object o_1=enumm.nextElement();
|
||||
|
||||
if (o_1 instanceof Header) {
|
||||
Header h=(Header) o_1;
|
||||
buf.append(HTMLUtils.genRow(h.getName(), h.getValue()));
|
||||
} else {
|
||||
buf.append(HTMLUtils.genRow("Other", o_1.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
buf.append("</table>");
|
||||
buf.append("<br>");
|
||||
buf.append("<blockquote>");
|
||||
buf.append("<pre>");
|
||||
buf.append(HTMLUtils.quoteToHTML(sw.toString()));
|
||||
buf.append("</pre>");
|
||||
buf.append("</blockquote>");
|
||||
} else {
|
||||
try {
|
||||
String s=sw.toString();
|
||||
InternetHeaders ih=new InternetHeaders();
|
||||
Enumeration enumm=p.getAllHeaders();
|
||||
|
||||
for (; enumm.hasMoreElements();) {
|
||||
Header h=(Header) enumm.nextElement();
|
||||
ih.addHeader(h.getName(), h.getValue());
|
||||
}
|
||||
|
||||
Part n=new MimeBodyPart(ih, s.getBytes());
|
||||
buf.append(master.makeAttachmentBox(index, n));
|
||||
} catch (MessagingException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
}
|
|
@ -1,129 +0,0 @@
|
|||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* RenderMessage.java
|
||||
*
|
||||
* Created on 07 August 2005, 18:25
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (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/MPL
|
||||
*
|
||||
* 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 Grendel mail/news client.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Kieran Maclean.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
package grendel.renderer.tools;
|
||||
|
||||
import grendel.renderer.ObjectRender;
|
||||
import grendel.renderer.html.BriefHeaderFormatter;
|
||||
import grendel.renderer.html.FullHeaderFormatter;
|
||||
import grendel.renderer.html.NormalHeaderFormatter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
|
||||
import javax.mail.Header;
|
||||
import javax.mail.Message;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.Part;
|
||||
import javax.mail.internet.InternetHeaders;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author hash9
|
||||
*/
|
||||
public class RenderMessage implements ObjectRender {
|
||||
private static List<String> l=null;
|
||||
|
||||
/** Creates a new instance of RenderMessage */
|
||||
public RenderMessage() {
|
||||
}
|
||||
|
||||
public boolean accept(Object o) {
|
||||
if (o instanceof Message) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public Class acceptable() {
|
||||
return Message.class;
|
||||
}
|
||||
|
||||
public StringBuilder objectRenderer(
|
||||
Object o, String index, Part p, grendel.renderer.Renderer master)
|
||||
throws MessagingException, IOException {
|
||||
Message message=(Message) p;
|
||||
StringBuilder buf=new StringBuilder();
|
||||
boolean indent=true;
|
||||
|
||||
if (index==null) {
|
||||
indent=false;
|
||||
index="";
|
||||
}
|
||||
|
||||
if (indent) {
|
||||
buf.append("<blockquote>");
|
||||
buf.append("<table border=\"1\" cellspacing=\"0\">");
|
||||
buf.append("<tr><td>");
|
||||
}
|
||||
|
||||
if (! master.isReply()){
|
||||
InternetHeaders ih=new InternetHeaders();
|
||||
Enumeration enumm=p.getAllHeaders();
|
||||
|
||||
while (enumm.hasMoreElements()) {
|
||||
Header h=(Header) enumm.nextElement();
|
||||
ih.addHeader(h.getName(), h.getValue());
|
||||
}
|
||||
|
||||
//TODO Add an option to select which of these to use.
|
||||
/*new BriefHeaderFormatter().formatHeaders(ih, buf);
|
||||
buf.append("<hr>");*/
|
||||
new NormalHeaderFormatter().formatHeaders(ih, buf);
|
||||
buf.append("<hr>");
|
||||
/*new FullHeaderFormatter().formatHeaders(ih, buf);
|
||||
buf.append("<hr>");*/
|
||||
}
|
||||
Object o_1=message.getContent();
|
||||
buf.append(master.objectRenderer(o_1, index, message));
|
||||
|
||||
if (indent) {
|
||||
buf.append("</td></tr>");
|
||||
buf.append("</table>");
|
||||
buf.append("</blockquote>");
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
}
|
|
@ -1,115 +0,0 @@
|
|||
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* RenderString.java
|
||||
*
|
||||
* Created on 07 August 2005, 18:36
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (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/MPL
|
||||
*
|
||||
* 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 Grendel mail/news client.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Kieran Maclean.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
package grendel.renderer.tools;
|
||||
|
||||
import grendel.renderer.html.HTMLUtils;
|
||||
import grendel.renderer.ObjectRender;
|
||||
import grendel.renderer.Renderer;
|
||||
|
||||
import java.util.Enumeration;
|
||||
|
||||
import javax.mail.Header;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.Part;
|
||||
import javax.mail.internet.InternetHeaders;
|
||||
import javax.mail.internet.MimeBodyPart;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author hash9
|
||||
*/
|
||||
public class RenderString implements ObjectRender
|
||||
{
|
||||
/** Creates a new instance of RenderString */
|
||||
public RenderString()
|
||||
{
|
||||
}
|
||||
|
||||
public boolean accept(Object o)
|
||||
{
|
||||
if (o instanceof String) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public Class acceptable()
|
||||
{
|
||||
return String.class;
|
||||
}
|
||||
|
||||
public StringBuilder objectRenderer(
|
||||
Object o, String index, javax.mail.Part p,
|
||||
Renderer master)
|
||||
throws javax.mail.MessagingException
|
||||
{
|
||||
StringBuilder buf=new StringBuilder();
|
||||
|
||||
if (p.getContentType().contains("text/html")) {
|
||||
master.putBar(buf);
|
||||
buf.append(HTMLUtils.cleanHTML((String) o));
|
||||
} else if (p.getContentType().contains("text/plain")) {
|
||||
master.putBar(buf);
|
||||
buf.append(HTMLUtils.quoteToHTML((String) o));
|
||||
} else {
|
||||
try {
|
||||
String s=(String) o;
|
||||
InternetHeaders ih=new InternetHeaders();
|
||||
Enumeration enumm=p.getAllHeaders();
|
||||
|
||||
for (; enumm.hasMoreElements();) {
|
||||
Header h=(Header) enumm.nextElement();
|
||||
ih.addHeader(h.getName(), h.getValue());
|
||||
}
|
||||
|
||||
Part n=new MimeBodyPart(ih, s.getBytes());
|
||||
buf.append(master.makeAttachmentBox(index, n));
|
||||
} catch (MessagingException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
}
|
|
@ -1,119 +0,0 @@
|
|||
<html>
|
||||
<head>
|
||||
|
||||
<!--
|
||||
** Mozilla Thunderbird Start Page
|
||||
**
|
||||
** Contributor:
|
||||
** David Tenser <tenser gmail com>
|
||||
** Kieran Maclean <kieran eternal undonet com>
|
||||
-->
|
||||
|
||||
<title>Welcome to Mozilla Grendel!</title>
|
||||
|
||||
<style type="text/css" media="screen,projection">
|
||||
body {
|
||||
margin: 0px;
|
||||
background: url(startpage-back.png) repeat-y #EEF1F4;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 130%;
|
||||
color: white;
|
||||
background: url(startpage-h1.png) /*no-repeat*/ transparent;
|
||||
height: 40px;
|
||||
padding: 5px 0.3ex 15px 25px;
|
||||
margin-top: 0px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
h2 {
|
||||
color: black;
|
||||
background: url(h2.png) repeat-y bottom left;
|
||||
width: 30ex;
|
||||
font-size: 100%;
|
||||
padding: 2px 0px 2px 10px;
|
||||
}
|
||||
|
||||
#indent {
|
||||
margin-left: 25px;
|
||||
margin-right: 25px;
|
||||
background: url(thunderbird-watermark.png) no-repeat top right;
|
||||
}
|
||||
|
||||
ul {
|
||||
margin-left: 30px;
|
||||
padding-left: 0px;
|
||||
}
|
||||
|
||||
li {
|
||||
list-style-image: url(startpage-li.png)
|
||||
}
|
||||
|
||||
a:link, a:visited {
|
||||
background: transparent;
|
||||
text-decoration: none;
|
||||
color: #006;
|
||||
}
|
||||
|
||||
a:active, a:hover {
|
||||
background: #f2f2f8;
|
||||
color: #009;
|
||||
}
|
||||
|
||||
#powered {
|
||||
font-size: 90%;
|
||||
margin: 0%;
|
||||
color: #fff;
|
||||
background: url(startpage-h2.png) no-repeat;
|
||||
padding-left: 25px;
|
||||
width: 100%;
|
||||
height: 30px;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
#powered a:link, #gecko a:visited {
|
||||
color: black;
|
||||
background: transparent;
|
||||
padding-right: 5px;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>Welcome to Mozilla Grendel</h1>
|
||||
|
||||
<div id="indent">
|
||||
<p>Mozilla Grendel is a open-source Java mail and news client.</p>
|
||||
<h2>Features</h2>
|
||||
<ul>
|
||||
<li><a href="http://wiki.mozilla.org/Grendel:Outstanding_Issues">Outstanding Issues</a></li>
|
||||
<li><a href="#">Reads Mail...</a></li>
|
||||
|
||||
<!--
|
||||
<ul>
|
||||
<li><a href="http://www.mozilla.org/products/thunderbird/junkmail.html">Adaptive Junk Mail Controls</a></li>
|
||||
<li><a href="http://www.mozilla.org/products/thunderbird/rss.html">RSS Reader</a></li>
|
||||
<li><a href="http://www.mozilla.org/products/thunderbird/global-inbox.html">Global Inbox Support</a></li>
|
||||
<li><a href="http://www.mozilla.org/products/thunderbird/search-folders.html">Saved Search Folders</a></li>
|
||||
<li><a href="http://www.mozilla.org/products/thunderbird/message-grouping.html">Message Grouping</a></li>
|
||||
<li><a href="http://www.mozilla.org/products/thunderbird/privacy-protection.html">Privacy Protection</a></li>
|
||||
-->
|
||||
</ul>
|
||||
<h2>More Information</h2>
|
||||
<!--
|
||||
<p>For frequently asked questions, tips and general help, visit <a href="http://www.mozilla.org/support/thunderbird/">Thunderbird Help</a>.</p>
|
||||
-->
|
||||
<p>For product information, visit the <a href="http://wiki.mozilla.org/Grendel">Grendel Home Page</a>.</p>
|
||||
|
||||
|
||||
<div id="powered"><a href="http://java.sun.com/">Powered by Java.</a></div>
|
||||
</div>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
|
@ -1,810 +0,0 @@
|
|||
/*
|
||||
* Folder.java
|
||||
*
|
||||
* Created on 18 August 2005, 23:45
|
||||
*
|
||||
* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License Version
|
||||
* 1.1 (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/MPL
|
||||
*
|
||||
* 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 Grendel mail/news client.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Kieran Maclean.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2005
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
package grendel.structure;
|
||||
|
||||
import grendel.javamail.JMProviders;
|
||||
import grendel.messaging.ExceptionNotice;
|
||||
import grendel.messaging.NoticeBoard;
|
||||
|
||||
import grendel.structure.events.Event;
|
||||
import grendel.structure.events.JavaMailEvent;
|
||||
import grendel.structure.events.JavaMailEventsListener;
|
||||
import grendel.structure.events.Listener;
|
||||
import grendel.structure.events.folder.FolderCreatedEvent;
|
||||
import grendel.structure.events.folder.FolderDeletedEvent;
|
||||
import grendel.structure.events.folder.FolderEvent;
|
||||
import grendel.structure.events.folder.FolderListener;
|
||||
import grendel.structure.events.folder.FolderMovedEvent;
|
||||
import grendel.structure.events.folder.NewMessageEvent;
|
||||
import grendel.structure.events.message.FlagChangedEvent;
|
||||
import grendel.structure.events.message.MessageDeletedEvent;
|
||||
import grendel.structure.events.message.MessageEvent;
|
||||
import grendel.structure.events.message.MessageListener;
|
||||
import grendel.structure.events.message.MessageMovedEvent;
|
||||
import java.util.Arrays;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.mail.FetchProfile;
|
||||
import javax.mail.IllegalWriteException;
|
||||
import javax.mail.MessagingException;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author hash9
|
||||
*/
|
||||
public class Folder {
|
||||
protected javax.mail.Folder folder;
|
||||
|
||||
/**
|
||||
* The event dispatcher class instance.
|
||||
*/
|
||||
protected EventDispatcher dispatcher = new EventDispatcher();
|
||||
protected Folder parent;
|
||||
protected Server server;
|
||||
private FolderList all_folders = new FolderList();
|
||||
private FolderList sub_folders = new FolderList();
|
||||
private MessageList messages = new MessageList();
|
||||
private boolean deleted = false;
|
||||
|
||||
/** Creates a new instance of Folder */
|
||||
public Folder(Folder parent, javax.mail.Folder folder) {
|
||||
this.parent = parent;
|
||||
this.folder = folder;
|
||||
|
||||
JavaMailEventsListener fli = new JavaMailEventsListener(this.dispatcher);
|
||||
folder.addConnectionListener(fli);
|
||||
folder.addFolderListener(fli);
|
||||
folder.addMessageChangedListener(fli);
|
||||
folder.addMessageCountListener(fli);
|
||||
}
|
||||
|
||||
/**
|
||||
* This returns a list of ALL folders don't call unless you're sure that's
|
||||
* what you want.
|
||||
* @return a List of the Folders contained in this folder.
|
||||
* This is seportate copy to the intenal List so addtions/removals have no
|
||||
* effect on this folder
|
||||
*/
|
||||
public final FolderList getAllFolders() {
|
||||
updateAllFolderList();
|
||||
|
||||
return new FolderList(all_folders);
|
||||
}
|
||||
|
||||
/**
|
||||
* This returns a list of the subscribed folders in the case that this isn't
|
||||
* supported by the mail store the result is equivalent to getAllFolders.
|
||||
* This is the method that in general should be called
|
||||
* @return a List of the Folders contained in this folder.
|
||||
* This is seportate copy to the intenal List so addtions/removals have no
|
||||
* effect on this folder
|
||||
*/
|
||||
public final FolderList getFolders() {
|
||||
updateSubscribedFolderList();
|
||||
|
||||
return new FolderList(sub_folders);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a folder by name.
|
||||
* @return the Folder, or null if it does not exist or an error occurs.
|
||||
*/
|
||||
public Folder getFolder(String name) {
|
||||
try {
|
||||
javax.mail.Folder f = folder.getFolder(name);
|
||||
|
||||
if ((f != null) && (f.exists())) {
|
||||
Folder folder = new Folder(this, f);
|
||||
all_folders.add(folder);
|
||||
|
||||
return folder;
|
||||
}
|
||||
|
||||
return null;
|
||||
} catch (MessagingException ex) {
|
||||
NoticeBoard.publish(new ExceptionNotice(ex));
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a message by message ID, these start at <em>one</em>
|
||||
* @param i
|
||||
*/
|
||||
public Message getMessage(int i) {
|
||||
//TODO This propably should update the messagelist properly, it doesn't because Tim's code takes ages to do that!
|
||||
if (!ensureOpen()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
javax.mail.Message m = folder.getMessage(i);
|
||||
|
||||
for (Message mess : messages) {
|
||||
if (mess.equals(m)) {
|
||||
return mess;
|
||||
}
|
||||
}
|
||||
|
||||
Message message = new Message(this, m);
|
||||
messages.add(message);
|
||||
dispatcher.dispatch(new NewMessageEvent(this, message)); //New Messsage Event
|
||||
|
||||
return message;
|
||||
} catch (MessagingException ex) {
|
||||
NoticeBoard.publish(new ExceptionNotice(ex));
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return a MessageList of the Messages contained in this folder.
|
||||
* This is seportate copy to the intenal List so addtions/removals have no effect on this folder.
|
||||
*/
|
||||
public MessageList getMessages() {
|
||||
updateMessageList();
|
||||
|
||||
return new MessageList(messages);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of this Folder.
|
||||
*/
|
||||
public String getName() {
|
||||
return folder.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the folder that is the parent of this one.
|
||||
* @return returns the parent of this folder, or <code>null</code> if this is a root folder.
|
||||
*/
|
||||
public Folder getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the MessageList containing only read messages.
|
||||
*/
|
||||
public MessageList getReadMessages() {
|
||||
getServer().ensureConnection();
|
||||
|
||||
MessageList ml = new MessageList(messages);
|
||||
int ml_size = ml.size();
|
||||
|
||||
for (int i = 0; i < ml_size; i++) {
|
||||
Message m = ml.get(i);
|
||||
|
||||
if (!m.isRead()) {
|
||||
ml.remove(i);
|
||||
}
|
||||
}
|
||||
|
||||
return ml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the server in which this folder is contained.
|
||||
*/
|
||||
public Server getServer() {
|
||||
if (server == null) {
|
||||
server = parent.getServer();
|
||||
}
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add or remove this folder to the subscribled folder list.
|
||||
* @param subscribe If true this folder is added to the subscribled folder list, otherwise it is removed.
|
||||
*/
|
||||
public void setSubscribed(boolean subscribe) {
|
||||
try {
|
||||
folder.setSubscribed(true);
|
||||
} catch (MessagingException ex) {
|
||||
NoticeBoard.publish(new ExceptionNotice(ex));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a listener to events in this folder.
|
||||
*/
|
||||
public void addMessageEventListener(FolderListener fl) {
|
||||
dispatcher.listeners.add(fl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy the contents of this folder to the given folder.
|
||||
* <p><strong>Warning this method is <em>not</em> atomic. Some copying may have occured before failure.</strong></p>
|
||||
* @return Returns false on failure.
|
||||
*/
|
||||
public boolean copyTo(Folder f) {
|
||||
getServer().ensureConnection();
|
||||
|
||||
try {
|
||||
folder.copyMessages(folder.getMessages(), f.folder);
|
||||
|
||||
FolderList fl = getAllFolders();
|
||||
|
||||
for (Folder sub_f : fl) {
|
||||
Folder dest = f.getAllFolders().getByName(sub_f.getName());
|
||||
|
||||
if (dest == null) {
|
||||
dest = f.newSubfolder(sub_f.getName());
|
||||
}
|
||||
|
||||
sub_f.copyTo(dest);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (MessagingException ex) {
|
||||
NoticeBoard.publish(new ExceptionNotice(ex));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <strong>WARNING this is a RECURSIVE call</strong>
|
||||
*/
|
||||
public boolean delete() {
|
||||
getServer().ensureConnection();
|
||||
|
||||
try {
|
||||
dispatcher.dispatch(new FolderDeletedEvent(this));
|
||||
|
||||
return folder.delete(true);
|
||||
} catch (MessagingException ex) {
|
||||
NoticeBoard.publish(new ExceptionNotice(ex));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The generic equals method.
|
||||
*/
|
||||
public boolean equals(Object o) {
|
||||
if (o instanceof javax.mail.Folder) {
|
||||
return equals((javax.mail.Folder) o);
|
||||
} else if (o instanceof Folder) {
|
||||
return equals((Folder) o);
|
||||
}
|
||||
|
||||
return super.equals(o);
|
||||
}
|
||||
|
||||
/**
|
||||
* The javax folder equals method.
|
||||
* This is used to see if this folder and that folder refer to the same underlying folder
|
||||
*/
|
||||
public boolean equals(javax.mail.Folder folder) {
|
||||
String name_this = this.folder.getFullName();
|
||||
String name_that = folder.getFullName();
|
||||
|
||||
return name_this.equals(name_that);
|
||||
}
|
||||
|
||||
/**
|
||||
* The Folder equals method.
|
||||
* This is used to see if both folders refer to the same underlying folder
|
||||
*/
|
||||
public boolean equals(Folder folder) {
|
||||
String name_this = this.folder.getFullName();
|
||||
String name_that = folder.folder.getFullName();
|
||||
|
||||
return name_this.equals(name_that);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the number of unread messages
|
||||
* @return the number of unread messages, or -1 if the method is unsupported
|
||||
*/
|
||||
public int getNoUnreadMessages() {
|
||||
try {
|
||||
int no = folder.getUnreadMessageCount();
|
||||
if (no == -1) {
|
||||
ensureOpen();
|
||||
no = folder.getUnreadMessageCount();
|
||||
}
|
||||
return no;
|
||||
} catch (MessagingException ex) {
|
||||
NoticeBoard.publish(new ExceptionNotice(ex));
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of messages
|
||||
* @return the number of messages, or -1 if the method is unsupported
|
||||
*/
|
||||
public int getNoMessages() {
|
||||
try {
|
||||
int no = folder.getMessageCount();
|
||||
if (no == -1) {
|
||||
ensureOpen();
|
||||
no = folder.getMessageCount();
|
||||
}
|
||||
return no;
|
||||
} catch (MessagingException ex) {
|
||||
NoticeBoard.publish(new ExceptionNotice(ex));
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the number of new messages
|
||||
* @return the number of new messages, or -1 if the method is unsupported
|
||||
*/
|
||||
public int getNoNewMessages() {
|
||||
try {
|
||||
int no = folder.getNewMessageCount();
|
||||
if (no == -1) {
|
||||
ensureOpen();
|
||||
no = folder.getNewMessageCount();
|
||||
}
|
||||
return no;
|
||||
} catch (MessagingException ex) {
|
||||
NoticeBoard.publish(new ExceptionNotice(ex));
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the MessageList containing only unread messages.
|
||||
*/
|
||||
public MessageList getUnReadMessages() {
|
||||
getServer().ensureConnection();
|
||||
|
||||
MessageList ml = new MessageList(messages);
|
||||
int ml_size = ml.size();
|
||||
|
||||
for (int i = 0; i < ml_size; i++) {
|
||||
Message m = ml.get(i);
|
||||
|
||||
if (m.isRead()) {
|
||||
ml.remove(i);
|
||||
}
|
||||
}
|
||||
|
||||
return ml;
|
||||
}
|
||||
|
||||
/**
|
||||
* A hash code method to match the equals method.
|
||||
*/
|
||||
public int hashcode() {
|
||||
return folder.getFullName().hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
* Move the contents of this folder to the given folder.
|
||||
* This is done by calling:<br>
|
||||
* <blockquote>
|
||||
* <code>
|
||||
* copyTo(Folder f);<br>
|
||||
* delete();
|
||||
* </code>
|
||||
* </blockquote>
|
||||
* <p><strong>Warning this method is <em>not</em> atomic. Some copying or deletion may have occured before failure.</strong></p>
|
||||
* @return Returns false on failure.
|
||||
* @throws UnsupportedOperationException if the copy operation fails.
|
||||
*/
|
||||
public boolean moveTo(Folder f) {
|
||||
getServer().ensureConnection();
|
||||
|
||||
if (copyTo(f)) {
|
||||
dispatcher.dispatch(new FolderMovedEvent(this));
|
||||
|
||||
return delete();
|
||||
}
|
||||
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new subfolder with the given name.
|
||||
*/
|
||||
public Folder newSubfolder(String name) {
|
||||
getServer().ensureConnection();
|
||||
|
||||
try {
|
||||
javax.mail.Folder new_folder = folder.getFolder(name);
|
||||
|
||||
if (new_folder.exists()) {
|
||||
throw new javax.mail.MessagingException("Folder Exists");
|
||||
} else {
|
||||
try {
|
||||
if (new_folder.create(javax.mail.Folder.HOLDS_FOLDERS |
|
||||
javax.mail.Folder.HOLDS_MESSAGES)) {
|
||||
Folder sub = new Folder(this, new_folder);
|
||||
sub.folder.setSubscribed(true);
|
||||
all_folders.add(sub);
|
||||
sub_folders.add(sub);
|
||||
dispatcher.dispatch(new FolderCreatedEvent(sub));
|
||||
|
||||
return sub;
|
||||
}
|
||||
|
||||
throw new javax.mail.MessagingException(
|
||||
"Folder Creation Failed!");
|
||||
} catch (MessagingException e) { // For some reason we couldn't create a folder that can contain both
|
||||
// folders and messages. Try to make one that will hold messages.
|
||||
|
||||
try {
|
||||
if (new_folder.create(javax.mail.Folder.HOLDS_MESSAGES)) {
|
||||
Folder sub = new Folder(this, new_folder);
|
||||
sub.folder.setSubscribed(true);
|
||||
all_folders.add(sub);
|
||||
sub_folders.add(sub);
|
||||
dispatcher.dispatch(new FolderCreatedEvent(sub));
|
||||
|
||||
return sub;
|
||||
}
|
||||
|
||||
throw new javax.mail.MessagingException(
|
||||
"Folder Creation Failed!");
|
||||
} catch (MessagingException e1) { // For some reason we couldn't create a folder that can contains only
|
||||
// messages. Try to make one that will hold folders.
|
||||
|
||||
if (new_folder.create(javax.mail.Folder.HOLDS_FOLDERS)) {
|
||||
Folder sub = new Folder(this, new_folder);
|
||||
sub.folder.setSubscribed(true);
|
||||
all_folders.add(sub);
|
||||
sub_folders.add(sub);
|
||||
dispatcher.dispatch(new FolderCreatedEvent(sub));
|
||||
|
||||
return sub;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (MessagingException e) {
|
||||
NoticeBoard.publish(new ExceptionNotice(e));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a listener to events in this folder.
|
||||
*/
|
||||
public void removeMessageEventListener(FolderListener fl) {
|
||||
dispatcher.listeners.remove(fl);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a String to represent this folder of
|
||||
* <i>foldername ( <code>getClass().getName() + '@' + Integer.toHexString(hashCode())</code> )</i>
|
||||
*/
|
||||
public String toString() {
|
||||
return getName() + " (" + super.toString() + ")";
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the folder is open.
|
||||
* This also ensures that it is connected.
|
||||
* @return Returns false if the method failed to ensure the folder is open.
|
||||
* It is recomend that the calling method use the false notification to abort any action.
|
||||
*/
|
||||
protected boolean ensureOpen() {
|
||||
try {
|
||||
getServer().ensureConnection();
|
||||
|
||||
if (!getServer().isConnected()) {
|
||||
throw new IllegalStateException("---> Connect FAILED!!!");
|
||||
}
|
||||
|
||||
if (!folder.exists()) {
|
||||
all_folders.clear();
|
||||
sub_folders.clear();
|
||||
messages.clear();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((folder.getType() & folder.HOLDS_MESSAGES) == 0) {
|
||||
messages.clear();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!folder.isOpen()) {
|
||||
try {
|
||||
folder.open(folder.READ_WRITE);
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
folder.open(folder.READ_ONLY);
|
||||
} catch (Exception e1) {
|
||||
e.printStackTrace();
|
||||
e1.printStackTrace();
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (MessagingException ex) {
|
||||
NoticeBoard.publish(new ExceptionNotice(ex));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This updates the list of <em>all</em> the availible folders.
|
||||
*/
|
||||
protected void updateAllFolderList() {
|
||||
getServer().ensureConnection();
|
||||
|
||||
try {
|
||||
if (!folder.exists()) {
|
||||
all_folders.clear();
|
||||
sub_folders.clear();
|
||||
messages.clear();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ((folder.getType() & folder.HOLDS_FOLDERS) == 0) {
|
||||
sub_folders.clear();
|
||||
all_folders.clear();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!folder.isOpen()) {
|
||||
try {
|
||||
folder.open(folder.READ_WRITE);
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
folder.open(folder.READ_ONLY);
|
||||
} catch (Exception e1) {
|
||||
e.printStackTrace();
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
javax.mail.Folder[] folders_a = folder.list();
|
||||
|
||||
for (int i = 0; i < folders_a.length; i++) {
|
||||
if (!all_folders.contains(folders_a[i])) {
|
||||
Folder f = new Folder(this, folders_a[i]);
|
||||
all_folders.add(f);
|
||||
dispatcher.dispatch(new FolderCreatedEvent(f));
|
||||
}
|
||||
}
|
||||
|
||||
int no_folders = all_folders.size();
|
||||
|
||||
for (int i = 0; i < no_folders; i++) {
|
||||
Folder f = all_folders.get(i);
|
||||
boolean found = false;
|
||||
|
||||
for (int j = 0; j < folders_a.length; j++) {
|
||||
if (f.equals(folders_a[i])) {
|
||||
found = true;
|
||||
j = folders_a.length;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
dispatcher.dispatch(new FolderDeletedEvent(f));
|
||||
all_folders.remove(i);
|
||||
}
|
||||
}
|
||||
} catch (MessagingException ex) {
|
||||
NoticeBoard.publish(new ExceptionNotice(ex));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This updates the list of <em>all</em> the messages.
|
||||
*/
|
||||
protected void updateMessageList() {
|
||||
getServer().ensureConnection();
|
||||
|
||||
try {
|
||||
if (!ensureOpen()) {
|
||||
return;
|
||||
}
|
||||
|
||||
long s = System.currentTimeMillis();
|
||||
// int me_c = folder.getMessageCount(); // DEBUG ONLY
|
||||
javax.mail.Message[] messages_a = folder.getMessages();
|
||||
long d = System.currentTimeMillis()-s;
|
||||
System.out.println("Time to collect messages: " +((d/1000)) + " s");
|
||||
|
||||
/* TODO Should this be an option to enable prefetching? Especially with disk caching it might be good but for now it's off
|
||||
* s = System.currentTimeMillis();
|
||||
* FetchProfile fp = new FetchProfile();
|
||||
* fp.add(FetchProfile.Item.ENVELOPE);
|
||||
* folder.fetch(messages_a, fp);
|
||||
* d = System.currentTimeMillis()-s;
|
||||
* System.out.println("Time to fetch messages: " +((d/1000)) + " s");
|
||||
*/
|
||||
|
||||
s = System.currentTimeMillis();
|
||||
if (messages.size()==0) { // Done to help get a fast first listing of a folder
|
||||
for (int i = 0; i < messages_a.length; i++) {
|
||||
Message m = new Message(this, messages_a[i]);
|
||||
messages.add(m);
|
||||
}
|
||||
} else { // If there is all ready stuff there then we nead to iterate though the lot
|
||||
//XXX This is wastefull if there is a better way to get the information.
|
||||
for (int i = 0; i < messages_a.length; i++) {
|
||||
if (!messages.contains(messages_a[i])) {
|
||||
Message m = new Message(this, messages_a[i]);
|
||||
messages.add(m);
|
||||
dispatcher.dispatch(new NewMessageEvent(this, m));
|
||||
}
|
||||
}
|
||||
|
||||
//int no_messages=messages.size();
|
||||
//XXX this is very slow because it neads to load all the message headers...
|
||||
for (int i = 0; i < messages.size(); i++) {
|
||||
Message m = messages.get(i);
|
||||
boolean found = false;
|
||||
|
||||
for (int j = 0; j < messages_a.length; j++) {
|
||||
if (m.equals(messages_a[i])) {
|
||||
found = true;
|
||||
j = messages_a.length;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
m.dispatcher.dispatch(new MessageDeletedEvent(m));
|
||||
messages.remove(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
d = System.currentTimeMillis()-s;
|
||||
System.out.println("Time to process messages: " +((d/1000)) + " s");
|
||||
} catch (MessagingException ex) {
|
||||
NoticeBoard.publish(new ExceptionNotice(ex));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This updates the list of the subscribed folders.
|
||||
*/
|
||||
protected void updateSubscribedFolderList() {
|
||||
getServer().ensureConnection();
|
||||
|
||||
try {
|
||||
if (!folder.exists()) {
|
||||
all_folders.clear();
|
||||
sub_folders.clear();
|
||||
messages.clear();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ((folder.getType() & folder.HOLDS_FOLDERS) == 0) {
|
||||
sub_folders.clear();
|
||||
all_folders.clear();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
javax.mail.Folder[] folders_a = folder.listSubscribed();
|
||||
|
||||
for (int i = 0; i < folders_a.length; i++) {
|
||||
if (!sub_folders.contains(folders_a[i])) {
|
||||
Folder f = new Folder(this, folders_a[i]);
|
||||
sub_folders.add(f);
|
||||
dispatcher.dispatch(new FolderCreatedEvent(f));
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < sub_folders.size(); i++) {
|
||||
Folder f = sub_folders.get(i);
|
||||
boolean found = false;
|
||||
|
||||
for (int j = 0; j < folders_a.length; j++) {
|
||||
if (f.equals(folders_a[i])) {
|
||||
found = true;
|
||||
j = folders_a.length;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
dispatcher.dispatch(new FolderDeletedEvent(f));
|
||||
sub_folders.remove(i);
|
||||
}
|
||||
}
|
||||
} catch (MessagingException ex) {
|
||||
NoticeBoard.publish(new ExceptionNotice(ex));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The event dispatacher class.
|
||||
*/
|
||||
private class EventDispatcher implements Runnable, Listener {
|
||||
Vector<FolderListener> listeners = new Vector<FolderListener>();
|
||||
private Event e;
|
||||
|
||||
EventDispatcher() {
|
||||
}
|
||||
|
||||
public void dispatch(FolderEvent e) {
|
||||
this.e = e;
|
||||
new Thread(this).start();
|
||||
}
|
||||
|
||||
public void javaMailEvent(JavaMailEvent e) {
|
||||
this.e = e;
|
||||
new Thread(this).start();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
for (FolderListener fl : listeners) {
|
||||
try {
|
||||
if (e instanceof JavaMailEvent) {
|
||||
fl.javaMailEvent((JavaMailEvent) e);
|
||||
} else if (e instanceof NewMessageEvent) {
|
||||
fl.newMessage((NewMessageEvent) e);
|
||||
} else if (e instanceof FolderDeletedEvent) {
|
||||
fl.folderDeleted((FolderDeletedEvent) e);
|
||||
} else if (e instanceof FolderCreatedEvent) {
|
||||
fl.folderCreated((FolderCreatedEvent) e);
|
||||
} else if (e instanceof FolderMovedEvent) {
|
||||
fl.folderMoved((FolderMovedEvent) e);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
NoticeBoard.publish(new ExceptionNotice(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,831 +0,0 @@
|
|||
/*
|
||||
* Message.java
|
||||
*
|
||||
* Created on 18 August 2005, 23:46
|
||||
*
|
||||
* To change this template, choose Tools | Options and locate the template under
|
||||
* the Source Creation and Management node. Right-click the template and choose
|
||||
* Open. You can then make changes to the template in the Source Editor.
|
||||
*/
|
||||
package grendel.structure;
|
||||
|
||||
import calypso.util.ByteBuf;
|
||||
|
||||
import grendel.messaging.ExceptionNotice;
|
||||
import grendel.messaging.NoticeBoard;
|
||||
|
||||
import grendel.prefs.accounts.Identity;
|
||||
|
||||
import grendel.renderer.Renderer;
|
||||
|
||||
import grendel.storage.addressparser.AddressList;
|
||||
import grendel.storage.addressparser.RFC822MailboxList;
|
||||
|
||||
import grendel.structure.events.Event;
|
||||
import grendel.structure.events.message.FlagChangedEvent;
|
||||
import grendel.structure.events.message.MessageDeletedEvent;
|
||||
import grendel.structure.events.message.MessageEvent;
|
||||
import grendel.structure.events.message.MessageListener;
|
||||
import grendel.structure.events.message.MessageMovedEvent;
|
||||
|
||||
import grendel.structure.sending.NewMessage;
|
||||
|
||||
import grendel.util.Constants;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.mail.Address;
|
||||
import javax.mail.BodyPart;
|
||||
import javax.mail.Flags;
|
||||
import javax.mail.Flags.Flag;
|
||||
import javax.mail.Header;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
import javax.mail.internet.InternetHeaders;
|
||||
import javax.mail.internet.MimeMultipart;
|
||||
import javax.mail.internet.MimeUtility;
|
||||
|
||||
|
||||
/**
|
||||
* This class is used instead of MessageExtra.
|
||||
* @author hash9
|
||||
*/
|
||||
public class Message
|
||||
{
|
||||
protected javax.mail.Message message;
|
||||
private Folder folder;
|
||||
private boolean deleted = false;
|
||||
protected Server server;
|
||||
protected EventDispatcher dispatcher = new EventDispatcher();
|
||||
|
||||
/** Creates a new instance of Message */
|
||||
protected Message(Folder folder, javax.mail.Message message)
|
||||
{
|
||||
this.message = message;
|
||||
this.folder = folder;
|
||||
}
|
||||
|
||||
public boolean copyTo(Folder f)
|
||||
{
|
||||
try
|
||||
{
|
||||
f.folder.appendMessages(new javax.mail.Message[] { message });
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (MessagingException e)
|
||||
{
|
||||
NoticeBoard.publish(new ExceptionNotice(e));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public boolean moveTo(Folder f)
|
||||
{
|
||||
if (copyTo(f))
|
||||
{
|
||||
dispatcher.dispatch(new MessageMovedEvent(this));
|
||||
delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public final Folder getFolder()
|
||||
{
|
||||
return folder;
|
||||
}
|
||||
|
||||
public boolean isImportant()
|
||||
{
|
||||
return getFlag(Flag.FLAGGED);
|
||||
}
|
||||
|
||||
public void setMarkAsDeleted(boolean value)
|
||||
{
|
||||
setFlag(Flag.DELETED, value);
|
||||
}
|
||||
|
||||
public void setMarkAsImportant(boolean value)
|
||||
{
|
||||
setFlag(Flag.FLAGGED, value);
|
||||
}
|
||||
|
||||
public void setMarkAsRead(boolean value)
|
||||
{
|
||||
setFlag(Flag.SEEN, value);
|
||||
}
|
||||
|
||||
public void setMarkAsReplied(boolean value)
|
||||
{
|
||||
setFlag(Flag.ANSWERED, value);
|
||||
}
|
||||
|
||||
public boolean isRead()
|
||||
{
|
||||
return getFlag(Flag.SEEN);
|
||||
}
|
||||
|
||||
public boolean isReplied()
|
||||
{
|
||||
return getFlag(Flags.Flag.ANSWERED);
|
||||
}
|
||||
|
||||
public AddressList getAllRecipients() throws javax.mail.MessagingException
|
||||
{
|
||||
AddressList to = getRecipients();
|
||||
AddressList cc = getRecipientsCC();
|
||||
AddressList bcc = getRecipientsBCC();
|
||||
|
||||
AddressList list = new AddressList();
|
||||
list.addAll(to);
|
||||
list.addAll(cc);
|
||||
list.addAll(bcc);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public InternetAddress getAuthor()
|
||||
{
|
||||
return getAddress("From");
|
||||
}
|
||||
|
||||
public boolean isForwarded()
|
||||
{
|
||||
return getFlags(new Flags("Forwarded"));
|
||||
|
||||
// #### this flags crap is all messed up, since Sun munged the APIs.
|
||||
// throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public void setMarkAsForwarded(boolean value)
|
||||
{
|
||||
setFlags(new Flags("Forwarded"), value);
|
||||
|
||||
// #### this flags crap is all messed up, since Sun munged the APIs.
|
||||
// throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public String getMessageID()
|
||||
{
|
||||
return getHeader("Message-ID");
|
||||
}
|
||||
|
||||
public int getMessageNumber()
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
public Date getReceivedDate() throws MessagingException
|
||||
{
|
||||
return message.getReceivedDate();
|
||||
}
|
||||
|
||||
public Address getRecipient()
|
||||
{
|
||||
return getAddress("To");
|
||||
}
|
||||
|
||||
public AddressList getRecipients()
|
||||
{
|
||||
return getAddresses("To");
|
||||
}
|
||||
|
||||
public AddressList getRecipientsCC()
|
||||
{
|
||||
return getAddresses("CC");
|
||||
}
|
||||
|
||||
public AddressList getRecipientsBCC()
|
||||
{
|
||||
return getAddresses("BCC");
|
||||
}
|
||||
|
||||
public AddressList getReplyTo() throws MessagingException
|
||||
{
|
||||
return getAddresses("Reply-To");
|
||||
}
|
||||
|
||||
public Date getSentDate() throws MessagingException
|
||||
{
|
||||
return message.getSentDate();
|
||||
}
|
||||
|
||||
public int getSize() throws MessagingException
|
||||
{
|
||||
return message.getSize();
|
||||
}
|
||||
|
||||
public String getSubject() throws MessagingException
|
||||
{
|
||||
return message.getSubject();
|
||||
}
|
||||
|
||||
/*public javax.mail.Message reply(boolean b) throws javax.mail.MessagingException {
|
||||
return message.reply(b);
|
||||
}*/
|
||||
public void saveChanges() throws javax.mail.MessagingException
|
||||
{
|
||||
message.saveChanges();
|
||||
}
|
||||
|
||||
protected AddressList getAddresses(String headername)
|
||||
{
|
||||
String header = getHeader(headername);
|
||||
|
||||
if (header == null)
|
||||
{
|
||||
return new AddressList();
|
||||
}
|
||||
|
||||
//XXX THIS WILL PRODUCE A BUG!!!!
|
||||
// The RFC822 Parser (by definition) has no support for news message
|
||||
// addresses this WILL have to be addressed at some point
|
||||
return new AddressList(new RFC822MailboxList(header));
|
||||
}
|
||||
|
||||
protected InternetAddress getAddress(String headername)
|
||||
{
|
||||
AddressList boxes = getAddresses(headername);
|
||||
|
||||
if (boxes.size() < 1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return (InternetAddress) boxes.get(0);
|
||||
}
|
||||
|
||||
public boolean isAddressee()
|
||||
{
|
||||
Collection<Identity> identies = getServer().getAccount()
|
||||
.getCollectionIdentities();
|
||||
AddressList recipients = getRecipients();
|
||||
|
||||
for (Address address : recipients)
|
||||
{
|
||||
for (Identity ident : identies)
|
||||
{
|
||||
try
|
||||
{
|
||||
Address ident_address = new InternetAddress(ident.getName(),
|
||||
ident.getEMail());
|
||||
|
||||
if (ident_address.equals(recipients))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (UnsupportedEncodingException ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public String baseSubject()
|
||||
{
|
||||
try
|
||||
{
|
||||
String sub = getSubject();
|
||||
|
||||
if (sub != null)
|
||||
{
|
||||
StringBuilder buf = new StringBuilder(sub);
|
||||
|
||||
if (stripRe(buf))
|
||||
{
|
||||
return buf.toString();
|
||||
}
|
||||
|
||||
return sub;
|
||||
}
|
||||
}
|
||||
catch (MessagingException e)
|
||||
{
|
||||
NoticeBoard.publish(new ExceptionNotice(e));
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public boolean isForward()
|
||||
{
|
||||
try
|
||||
{
|
||||
return getSubject().toLowerCase().contains("fwd:");
|
||||
}
|
||||
catch (MessagingException ex)
|
||||
{
|
||||
NoticeBoard.publish(new ExceptionNotice(ex));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isReply()
|
||||
{
|
||||
try
|
||||
{
|
||||
String sub = message.getSubject();
|
||||
|
||||
if (sub != null)
|
||||
{
|
||||
StringBuilder buf = new StringBuilder(sub);
|
||||
|
||||
return stripRe(buf);
|
||||
}
|
||||
}
|
||||
catch (MessagingException e)
|
||||
{
|
||||
NoticeBoard.publish(new ExceptionNotice(e));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// Removes leading "Re:" or similar from the given StringBuffer. Returns
|
||||
// true if it found such a string to remove; false otherwise.
|
||||
protected boolean stripRe(StringBuilder buf)
|
||||
{
|
||||
// Much of this code is duplicated in MessageBase. Sigh. ###
|
||||
if (buf == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int numToTrim = 0;
|
||||
int length = buf.length();
|
||||
|
||||
if ((length > 2) && ((buf.charAt(0) == 'r') || (buf.charAt(0) == 'R')) &&
|
||||
((buf.charAt(1) == 'e') || (buf.charAt(1) == 'E')))
|
||||
{
|
||||
char c = buf.charAt(2);
|
||||
|
||||
if (c == ':')
|
||||
{
|
||||
numToTrim = 3; // Skip over "Re:"
|
||||
}
|
||||
else if ((c == '[') || (c == '('))
|
||||
{
|
||||
int i = 3; // skip over "Re[" or "Re("
|
||||
|
||||
while ((i < length) && (buf.charAt(i) >= '0') &&
|
||||
(buf.charAt(i) <= '9'))
|
||||
{
|
||||
i++;
|
||||
}
|
||||
|
||||
// Now ensure that the following thing is "]:" or "):"
|
||||
// Only if it is do we treat this all as a "Re"-ish thing.
|
||||
if ((i < (length - 1)) &&
|
||||
((buf.charAt(i) == ']') || (buf.charAt(i) == ')')) &&
|
||||
(buf.charAt(i + 1) == ':'))
|
||||
{
|
||||
numToTrim = i + 2; // Skip the whole thing.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (numToTrim > 0)
|
||||
{
|
||||
int i = numToTrim;
|
||||
|
||||
while ((i < (length - 1)) && Character.isWhitespace(buf.charAt(i)))
|
||||
{
|
||||
i++;
|
||||
}
|
||||
|
||||
for (int j = i; j < length; j++)
|
||||
{
|
||||
buf.setCharAt(j - i, buf.charAt(j));
|
||||
}
|
||||
|
||||
buf.setLength(length - i);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (o instanceof javax.mail.Message)
|
||||
{
|
||||
return equals((javax.mail.Message) o);
|
||||
}
|
||||
else if (o instanceof Message)
|
||||
{
|
||||
return equals((Message) o);
|
||||
}
|
||||
|
||||
return super.equals(o);
|
||||
}
|
||||
|
||||
public int hashcode()
|
||||
{
|
||||
return getMessageID().hashCode();
|
||||
}
|
||||
|
||||
public boolean equals(javax.mail.Message message)
|
||||
{
|
||||
String message_id_this = this.getMessageID();
|
||||
String[] list = null;
|
||||
|
||||
try
|
||||
{
|
||||
list = message.getHeader("Message-ID");
|
||||
}
|
||||
catch (MessagingException e)
|
||||
{
|
||||
}
|
||||
|
||||
if ((list == null) || (list.length < 1))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
String message_id_that = list[0];
|
||||
|
||||
return message_id_this.equals(message_id_that);
|
||||
}
|
||||
|
||||
public boolean equals(Message message)
|
||||
{
|
||||
String message_id_this = this.getMessageID();
|
||||
String message_id_that = message.getMessageID();
|
||||
|
||||
return message_id_this.equals(message_id_that);
|
||||
}
|
||||
|
||||
/**
|
||||
* <strong>Warning this is a <em>CLEANED</em> group of Headers</strong>
|
||||
* That is those Headers whose value is <em>not</em> null!
|
||||
*/
|
||||
public Iterable<Header> getAllIterableHeaders()
|
||||
{
|
||||
List<Header> l = new ArrayList<Header>();
|
||||
|
||||
try
|
||||
{
|
||||
Enumeration enumm = message.getAllHeaders();
|
||||
|
||||
for (; enumm.hasMoreElements();)
|
||||
{
|
||||
Header h = (Header) enumm.nextElement();
|
||||
|
||||
if (h.getValue() != null)
|
||||
{
|
||||
l.add(h);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (MessagingException ex)
|
||||
{
|
||||
NoticeBoard.publish(new ExceptionNotice(ex));
|
||||
}
|
||||
|
||||
return l;
|
||||
}
|
||||
|
||||
public Map<String,String> getAllSimpleHeaders()
|
||||
{
|
||||
TreeMap<String,String> simple_headers = new TreeMap<String,String>();
|
||||
|
||||
try
|
||||
{
|
||||
Enumeration enumm = message.getAllHeaders();
|
||||
|
||||
for (; enumm.hasMoreElements();)
|
||||
{
|
||||
Header h = (Header) enumm.nextElement();
|
||||
simple_headers.put(h.getName(), h.getValue());
|
||||
}
|
||||
}
|
||||
catch (MessagingException ex)
|
||||
{
|
||||
NoticeBoard.publish(new ExceptionNotice(ex));
|
||||
}
|
||||
|
||||
return simple_headers;
|
||||
}
|
||||
|
||||
public InternetHeaders getAllInternetHeaders()
|
||||
{
|
||||
InternetHeaders internet_headers = new InternetHeaders();
|
||||
|
||||
try
|
||||
{
|
||||
Enumeration enumm = message.getAllHeaders();
|
||||
|
||||
for (; enumm.hasMoreElements();)
|
||||
{
|
||||
Header h = (Header) enumm.nextElement();
|
||||
internet_headers.addHeader(h.getName(), h.getValue());
|
||||
}
|
||||
}
|
||||
catch (MessagingException ex)
|
||||
{
|
||||
NoticeBoard.publish(new ExceptionNotice(ex));
|
||||
}
|
||||
|
||||
return internet_headers;
|
||||
}
|
||||
|
||||
public String getHeader(String header)
|
||||
{
|
||||
String[] list = null;
|
||||
|
||||
try
|
||||
{
|
||||
list = message.getHeader(header);
|
||||
}
|
||||
catch (MessagingException e)
|
||||
{
|
||||
}
|
||||
|
||||
if ((list == null) || (list.length < 1))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return list[0];
|
||||
}
|
||||
|
||||
private ByteBuf decendMultipart(MimeMultipart mm) throws MessagingException
|
||||
{
|
||||
ByteBuf buf = new ByteBuf();
|
||||
int max = mm.getCount();
|
||||
|
||||
for (int i = 0; i < max; i++)
|
||||
{
|
||||
BodyPart bp = mm.getBodyPart(i);
|
||||
|
||||
try
|
||||
{
|
||||
Object o = bp.getContent();
|
||||
|
||||
if (o instanceof String)
|
||||
{
|
||||
buf.append(o);
|
||||
}
|
||||
else
|
||||
{
|
||||
buf.append("<a href=\"attachment:?" + i + "\">Attachment " +
|
||||
i + "</a>\n");
|
||||
}
|
||||
}
|
||||
catch (IOException ee)
|
||||
{
|
||||
throw new MessagingException("I/O error", ee);
|
||||
}
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
public boolean getFlag(Flag flag)
|
||||
{
|
||||
try
|
||||
{
|
||||
return message.isSet(flag);
|
||||
}
|
||||
catch (MessagingException ex)
|
||||
{
|
||||
NoticeBoard.publish(new ExceptionNotice(ex));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean getFlags(Flags flags)
|
||||
{
|
||||
try
|
||||
{
|
||||
return message.getFlags().contains(flags);
|
||||
}
|
||||
catch (MessagingException ex)
|
||||
{
|
||||
NoticeBoard.publish(new ExceptionNotice(ex));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public InputStream getSource()
|
||||
{
|
||||
try
|
||||
{
|
||||
InternetHeaders heads = new InternetHeaders();
|
||||
Enumeration e;
|
||||
|
||||
for (e = message.getAllHeaders(); e.hasMoreElements();)
|
||||
{
|
||||
Header h = (Header) e.nextElement();
|
||||
|
||||
try
|
||||
{
|
||||
heads.addHeader(h.getName(),
|
||||
MimeUtility.encodeText(h.getValue()));
|
||||
}
|
||||
catch (UnsupportedEncodingException u)
|
||||
{
|
||||
heads.addHeader(h.getName(), h.getValue()); // Anyone got a better
|
||||
// idea??? ###
|
||||
}
|
||||
}
|
||||
|
||||
ByteBuf buf = new ByteBuf();
|
||||
|
||||
for (e = heads.getAllHeaderLines(); e.hasMoreElements();)
|
||||
{
|
||||
buf.append(e.nextElement());
|
||||
buf.append(Constants.BYTEBUFLINEBREAK);
|
||||
}
|
||||
|
||||
buf.append(Constants.BYTEBUFLINEBREAK);
|
||||
|
||||
ByteBuf buf2 = new ByteBuf();
|
||||
|
||||
try
|
||||
{
|
||||
Object o = message.getContent();
|
||||
|
||||
if (o instanceof MimeMultipart)
|
||||
{
|
||||
MimeMultipart mm = (MimeMultipart) o;
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
mm.writeTo(baos);
|
||||
buf2.append(baos.toByteArray());
|
||||
}
|
||||
else
|
||||
{
|
||||
buf2.append(o);
|
||||
}
|
||||
}
|
||||
catch (IOException ee)
|
||||
{
|
||||
throw new MessagingException("I/O error", ee);
|
||||
}
|
||||
|
||||
buf.append(buf2);
|
||||
|
||||
return buf.makeInputStream();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ByteBuf buf = new ByteBuf();
|
||||
buf.append(e);
|
||||
|
||||
return buf.makeInputStream();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDeleted()
|
||||
{
|
||||
return getFlag(Flags.Flag.DELETED);
|
||||
}
|
||||
|
||||
public Object[] messageThreadReferences()
|
||||
{
|
||||
// ### WRONG WRONG WRONG. This needs to steal the code from
|
||||
// MessageBase.internReferences and do clever things with it.
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setFlag(Flag flag, boolean state)
|
||||
{
|
||||
try
|
||||
{
|
||||
message.setFlag(flag, state);
|
||||
}
|
||||
catch (MessagingException ex)
|
||||
{
|
||||
NoticeBoard.publish(new ExceptionNotice(ex));
|
||||
}
|
||||
}
|
||||
|
||||
public void setFlags(Flags flags, boolean state)
|
||||
{
|
||||
try
|
||||
{
|
||||
message.setFlags(flags, state);
|
||||
}
|
||||
catch (MessagingException ex)
|
||||
{
|
||||
NoticeBoard.publish(new ExceptionNotice(ex));
|
||||
}
|
||||
}
|
||||
|
||||
public void delete()
|
||||
{
|
||||
setFlag(Flags.Flag.DELETED, true);
|
||||
dispatcher.dispatch(new MessageDeletedEvent(this));
|
||||
}
|
||||
|
||||
public Server getServer()
|
||||
{
|
||||
if (server == null)
|
||||
{
|
||||
server = folder.getServer();
|
||||
}
|
||||
|
||||
return server;
|
||||
}
|
||||
|
||||
public NewMessage replyTo(boolean replyToAll)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new NewMessage(message.reply(replyToAll), message, this);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
NoticeBoard.publish(new ExceptionNotice(e));
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public InputStream renderToHTML() throws IOException
|
||||
{
|
||||
return Renderer.render(message);
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return getMessageID() + " (" + super.toString() + ")";
|
||||
}
|
||||
|
||||
public void addMessageEventListener(MessageListener ml)
|
||||
{
|
||||
dispatcher.listeners.add(ml);
|
||||
}
|
||||
|
||||
public void removeMessageEventListener(MessageListener ml)
|
||||
{
|
||||
dispatcher.listeners.remove(ml);
|
||||
}
|
||||
|
||||
class EventDispatcher implements Runnable
|
||||
{
|
||||
Vector<MessageListener> listeners = new Vector<MessageListener>();
|
||||
private Event e;
|
||||
|
||||
EventDispatcher()
|
||||
{
|
||||
}
|
||||
|
||||
public void dispatch(MessageEvent e)
|
||||
{
|
||||
this.e = e;
|
||||
new Thread(this).start();
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
for (MessageListener ml : listeners)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (e instanceof FlagChangedEvent)
|
||||
{
|
||||
ml.flagChanged((FlagChangedEvent) e);
|
||||
}
|
||||
else if (e instanceof MessageDeletedEvent)
|
||||
{
|
||||
ml.messageDeleted((MessageDeletedEvent) e);
|
||||
}
|
||||
else if (e instanceof MessageMovedEvent)
|
||||
{
|
||||
ml.messageMoved((MessageMovedEvent) e);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
NoticeBoard.publish(new ExceptionNotice(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,196 +0,0 @@
|
|||
/*
|
||||
* Server.java
|
||||
*
|
||||
* Created on 18 August 2005, 23:44
|
||||
*
|
||||
* To change this template, choose Tools | Options and locate the template under
|
||||
* the Source Creation and Management node. Right-click the template and choose
|
||||
* Open. You can then make changes to the template in the Source Editor.
|
||||
*/
|
||||
|
||||
package grendel.structure;
|
||||
|
||||
import grendel.javamail.JMProviders;
|
||||
import grendel.messaging.ExceptionNotice;
|
||||
import grendel.messaging.NoticeBoard;
|
||||
import grendel.prefs.accounts.Account__Receive;
|
||||
import grendel.prefs.accounts.Account__Server;
|
||||
import grendel.structure.events.Event;
|
||||
import grendel.structure.events.JavaMailEvent;
|
||||
import grendel.structure.events.JavaMailEventsListener;
|
||||
import grendel.structure.events.Listener;
|
||||
import grendel.structure.events.server.AutoConnectionEvent;
|
||||
import grendel.structure.events.server.ConnectedEvent;
|
||||
import grendel.structure.events.server.DisconnectedEvent;
|
||||
import grendel.structure.events.server.ServerEvent;
|
||||
import grendel.structure.events.server.ServerListener;
|
||||
import java.util.Vector;
|
||||
import javax.mail.AuthenticationFailedException;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.NoSuchProviderException;
|
||||
import javax.mail.Store;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author hash9
|
||||
*/
|
||||
public class Server {
|
||||
protected Store store;
|
||||
protected Account__Receive account;
|
||||
protected boolean ensure_connection = true;
|
||||
|
||||
/** Creates a new instance of Server */
|
||||
public Server(Account__Receive account) throws NoSuchProviderException {
|
||||
this.store=JMProviders.getJMProviders().getStore(account);
|
||||
this.account = account;
|
||||
JavaMailEventsListener fli = new JavaMailEventsListener(this.dispatcher);
|
||||
store.addConnectionListener(fli);
|
||||
store.addStoreListener(fli);
|
||||
}
|
||||
|
||||
private String resolvePassword() {
|
||||
if (account instanceof Account__Server) {
|
||||
Account__Server account = (Account__Server) this.account;
|
||||
return account.getPassword(); //TODO Add Obsurring
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public boolean connect() {
|
||||
try {
|
||||
if (account instanceof Account__Server) {
|
||||
Account__Server account = (Account__Server) this.account;
|
||||
store.connect(account.getHost(),account.getPort(), account.getUsername(), resolvePassword());
|
||||
} else {
|
||||
store.connect("",-1, "", "");
|
||||
}
|
||||
dispatcher.dispatch(new ConnectedEvent(this));
|
||||
return true;
|
||||
} catch (AuthenticationFailedException e) {
|
||||
NoticeBoard.publish(new ExceptionNotice(e));
|
||||
JOptionPane.showMessageDialog(null,"Login failed", "Grendel Error", JOptionPane.ERROR_MESSAGE); // TODO REDO THIS!!!!!
|
||||
try {
|
||||
store.close();
|
||||
} catch (MessagingException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
} catch (MessagingException e) {
|
||||
|
||||
NoticeBoard.publish(new ExceptionNotice(e.getNextException()));
|
||||
try {
|
||||
store.close();
|
||||
} catch (MessagingException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void disconnect() {
|
||||
try {
|
||||
store.close();
|
||||
dispatcher.dispatch(new DisconnectedEvent(this));
|
||||
} catch (MessagingException ex) {
|
||||
NoticeBoard.publish(new ExceptionNotice(ex));
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isConnected() {
|
||||
return store.isConnected();
|
||||
}
|
||||
|
||||
protected void ensureConnection() {
|
||||
if (ensure_connection && (! isConnected())) {
|
||||
dispatcher.dispatch(new AutoConnectionEvent(this));
|
||||
if (!connect()) {
|
||||
if (JMProviders.getSession().getDebug()) {
|
||||
System.err.println("Connection Failed!");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setEnsureConnection(boolean ensure_connection) {
|
||||
this.ensure_connection = ensure_connection;
|
||||
}
|
||||
|
||||
public Account__Receive getAccount() {
|
||||
return account;
|
||||
}
|
||||
|
||||
public Folder getRoot() {
|
||||
ensureConnection();
|
||||
try {
|
||||
return new FolderRoot(this,store.getDefaultFolder());
|
||||
} catch (java.lang.IllegalStateException ise) {
|
||||
NoticeBoard.publish(new ExceptionNotice(ise));
|
||||
return null;
|
||||
} catch (MessagingException e) {
|
||||
NoticeBoard.publish(new ExceptionNotice(e));
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return this.account.getName();
|
||||
}
|
||||
|
||||
|
||||
protected void finalize() {
|
||||
try {
|
||||
System.err.println("Closing!");
|
||||
store.close();
|
||||
} catch (MessagingException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected EventDispatcher dispatcher = new EventDispatcher();
|
||||
|
||||
public void addMessageEventListener(ServerListener sl) {
|
||||
dispatcher.listeners.add(sl);
|
||||
}
|
||||
|
||||
public void removeMessageEventListener(ServerListener sl) {
|
||||
dispatcher.listeners.remove(sl);
|
||||
}
|
||||
|
||||
class EventDispatcher implements Runnable, Listener {
|
||||
Vector<ServerListener> listeners = new Vector<ServerListener>();
|
||||
private Event e;
|
||||
|
||||
EventDispatcher() {
|
||||
}
|
||||
|
||||
public void dispatch(ServerEvent e) {
|
||||
this.e = e;
|
||||
new Thread(this).start();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
for (ServerListener sl: listeners) {
|
||||
try {
|
||||
if (e instanceof JavaMailEvent) {
|
||||
sl.javaMailEvent((JavaMailEvent) e);
|
||||
} else if (e instanceof ConnectedEvent) {
|
||||
sl.connected((ConnectedEvent) e);
|
||||
} else if (e instanceof DisconnectedEvent) {
|
||||
sl.disconnected((DisconnectedEvent) e);
|
||||
} else if (e instanceof AutoConnectionEvent) {
|
||||
sl.autoReconnected((AutoConnectionEvent) e);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
NoticeBoard.publish(new ExceptionNotice(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void javaMailEvent(JavaMailEvent e) {
|
||||
this.e = e;
|
||||
new Thread(this).start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
* Servers.java
|
||||
*
|
||||
* Created on 18 August 2005, 23:45
|
||||
*
|
||||
* To change this template, choose Tools | Options and locate the template under
|
||||
* the Source Creation and Management node. Right-click the template and choose
|
||||
* Open. You can then make changes to the template in the Source Editor.
|
||||
*/
|
||||
|
||||
package grendel.structure;
|
||||
|
||||
import grendel.javamail.JMProviders;
|
||||
import grendel.messaging.ExceptionNotice;
|
||||
import grendel.messaging.NoticeBoard;
|
||||
import grendel.prefs.Preferences;
|
||||
import grendel.prefs.accounts.Account__Receive;
|
||||
import grendel.prefs.xml.XMLPreferences;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.Vector;
|
||||
import javax.mail.NoSuchProviderException;
|
||||
import javax.mail.Session;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author hash9
|
||||
*/
|
||||
public final class Servers {
|
||||
private static Servers fInstance=null;
|
||||
|
||||
private static XMLPreferences options_mail;
|
||||
private static List<Server> servers = new Vector<Server>();
|
||||
|
||||
/** Creates a new instance of Servers */
|
||||
static {
|
||||
options_mail=Preferences.getPreferances().getPropertyPrefs("options").getPropertyPrefs("mail");
|
||||
}
|
||||
|
||||
public static synchronized List<Server> getServers() {
|
||||
updateServers();
|
||||
|
||||
return new Vector<Server>(servers);
|
||||
}
|
||||
|
||||
private static synchronized void closeStores() {
|
||||
for (Server server : servers) {
|
||||
server.disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
private static synchronized void updateServers() {
|
||||
List<Account__Receive> recive_accounts_list= new ArrayList<Account__Receive>(Preferences.getPreferances().getAccounts().getReciveAccounts());
|
||||
//servers=new Vector<Server>(recive_accounts_list.size());
|
||||
|
||||
for (Server s: servers) {
|
||||
boolean contains = recive_accounts_list.remove(s.getAccount());
|
||||
if (! contains) {
|
||||
servers.remove(s);
|
||||
}
|
||||
}
|
||||
for (Account__Receive account : recive_accounts_list) {
|
||||
try {
|
||||
servers.add(new Server(account));
|
||||
} catch (NoSuchProviderException e) {
|
||||
NoticeBoard.publish(new ExceptionNotice(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,161 +0,0 @@
|
|||
/*
|
||||
* Main.java
|
||||
*
|
||||
* Created on 22 August 2005, 14:41
|
||||
*
|
||||
* To change this template, choose Tools | Options and locate the template under
|
||||
* the Source Creation and Management node. Right-click the template and choose
|
||||
* Open. You can then make changes to the template in the Source Editor.
|
||||
*/
|
||||
|
||||
package grendel.structure.test;
|
||||
import grendel.renderer.Renderer;
|
||||
import grendel.structure.*;
|
||||
import java.io.CharArrayWriter;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.util.logging.ConsoleHandler;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.logging.SimpleFormatter;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author hash9
|
||||
*/
|
||||
public class Main {
|
||||
|
||||
/** Creates a new instance of Main */
|
||||
public Main() {
|
||||
}
|
||||
public static void main(String... args) {
|
||||
/*Logger logger = Logger.getLogger("gnu.mail.providers.nntp");
|
||||
ConsoleHandler ch = new ConsoleHandler();
|
||||
ch.setFormatter(new SimpleFormatter());
|
||||
logger.addHandler(ch);*/
|
||||
/*System.err.println("Servers: "+Servers.getServers());
|
||||
Server s = Servers.getServers().get(0);*/
|
||||
//decend(s.getRoot(),"",null);
|
||||
//NewMessage nm = new NewMessage();
|
||||
/*MessageList messages = s.getRoot().getFolders().get(0).getMessages();
|
||||
NewMessage nm = messages.get(messages.size()-1).replyTo(false);
|
||||
Account__Send ar = Preferences.getPreferances().getAccounts().getSendAccounts().get(0);
|
||||
nm.setAccountIdentity(new AccountIdentity(ar,ar.getIdentity(0)));
|
||||
nm.addCCAddress(new RFC822Mailbox("postmaster@res04-kam58.res.st-and.ac.uk"));
|
||||
try {
|
||||
Sender.send(nm);
|
||||
} catch (MessageSendViolation msv) {
|
||||
msv.printStackTrace();
|
||||
}*/
|
||||
|
||||
/*NewMessage nm = new NewMessage();
|
||||
Account__Send ar = Preferences.getPreferances().getAccounts().getSendAccounts().get(0);
|
||||
nm.setAccountIdentity(new AccountIdentity(ar,ar.getIdentity(0)));
|
||||
nm.setSubject("Test 2");
|
||||
nm.setBody(new StringBuilder("<This is a Test"));
|
||||
nm.setContentType("text/plain");
|
||||
try {
|
||||
nm.message.addRecipient(MimeMessage.RecipientType.NEWSGROUPS,new NewsAddress("netscape.test"));
|
||||
} catch (MessagingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
Sender.send(nm);
|
||||
} catch (MessageSendViolation msv) {
|
||||
msv.printStackTrace();
|
||||
}*/
|
||||
System.err.println("Servers: "+Servers.getServers());
|
||||
Server s = Servers.getServers().get(2);
|
||||
System.out.println("Server: "+s);
|
||||
/*{
|
||||
FolderList folders = s.getRoot().getAllFolders();
|
||||
//System.err.println("Folders: "+folders);
|
||||
System.err.println("Folders:");
|
||||
for (Folder f: folders) {
|
||||
System.err.println('\t'+f.getName());
|
||||
}
|
||||
}*/
|
||||
{
|
||||
Folder f = s.getRoot().getFolder("netscape.test");
|
||||
Folder netscape_test =f;
|
||||
//netscape_test.setSubscribed(true);
|
||||
//FolderList folders = s.getRoot().getFolders();
|
||||
//etscape_test.
|
||||
echoSigs(netscape_test);
|
||||
/*System.out.println("Subscribed Folders:");
|
||||
for (Folder f: folders) {*/
|
||||
System.out.println('\t'+f.getName());
|
||||
try {
|
||||
FileOutputStream fos = new FileOutputStream("C:\\out.htm");
|
||||
InputStream is = f.getMessage(21).renderToHTML();
|
||||
int i = is.read();
|
||||
while (i!=-1) {
|
||||
fos.write(i);
|
||||
i = is.read();
|
||||
}
|
||||
fos.close();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//}//*/
|
||||
/*for (Folder f: folders) {
|
||||
//System.err.println('\t'+f.getName());
|
||||
echoSigs(f);
|
||||
}*/
|
||||
s.disconnect();
|
||||
}
|
||||
|
||||
/*Folder test = s.getRoot().getFolder("org.apache.james.user");
|
||||
Message m = test.getMessage(1);
|
||||
System.out.println("Message 1: " + m.toString());*/
|
||||
//echoSigs(netscape);*/
|
||||
//Account__Receive ar = Preferences.getPreferances().getAccounts().getReciveAccounts().get(0);
|
||||
/*System.out.println("Servers: "+Servers.getServers());
|
||||
Server s = Servers.getServers().get(2);
|
||||
FolderList fl =s.getRoot().getFolders();
|
||||
for (Folder f: fl) {
|
||||
System.out.println("\t" + f.getName());
|
||||
}*/
|
||||
//decend(s.getRoot(),"",System.out);
|
||||
}
|
||||
|
||||
private static void echoSigs(Folder f) {
|
||||
System.out.println("Folder: "+f.getName());
|
||||
MessageList ml = f.getMessages();
|
||||
int ml_size = ml.size();
|
||||
for (int i = 0;(i<10)&&(i<ml_size);i++) {
|
||||
Message m = ml.get(i);
|
||||
System.out.println("\t\t"+m.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public static void decend(Folder f, String indent, PrintStream ps) {
|
||||
ps.println(indent + "Folder: "+f.getName());
|
||||
ps.println(indent + "\tMessages:");
|
||||
MessageList ml = f.getMessages();
|
||||
for (Message m: ml) {
|
||||
ps.println(indent + "\t\t"+m.toString());
|
||||
try {
|
||||
InputStream is = m.renderToHTML();
|
||||
CharArrayWriter caw = new CharArrayWriter();
|
||||
int i = 0;
|
||||
while (i!=-1) {
|
||||
i = is.read();
|
||||
caw.write(i);
|
||||
}
|
||||
|
||||
ps.println(indent + "\t\t\t"+caw.toString());
|
||||
} catch (Exception ioe) {
|
||||
ps.println(indent + "\t\t\t"+ioe.toString());
|
||||
}
|
||||
}
|
||||
FolderList fl = f.getFolders();
|
||||
indent = indent+"\t";
|
||||
for (Folder nf: fl) {
|
||||
decend(nf,indent,ps);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
/*
|
||||
* IdentityUtills.java
|
||||
*
|
||||
* Created on 24 August 2005, 20:28
|
||||
*
|
||||
* To change this template, choose Tools | Options and locate the template under
|
||||
* the Source Creation and Management node. Right-click the template and choose
|
||||
* Open. You can then make changes to the template in the Source Editor.
|
||||
*/
|
||||
|
||||
package grendel.structure.utill;
|
||||
|
||||
import grendel.prefs.Preferences;
|
||||
import grendel.prefs.accounts.Account__Receive;
|
||||
import grendel.prefs.accounts.Account__Send;
|
||||
import grendel.prefs.accounts.Identity;
|
||||
import grendel.structure.sending.AccountIdentity;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author hash9
|
||||
*/
|
||||
public final class IdentityUtills {
|
||||
|
||||
/** Creates a new instance of IdentityUtills */
|
||||
private IdentityUtills() {
|
||||
}
|
||||
|
||||
public static ArrayList<AccountIdentity> getAllAccountIdentitys() {
|
||||
ArrayList<AccountIdentity> ai_a = new ArrayList<AccountIdentity>();
|
||||
List<Account__Receive> recieve_accounts = Preferences.getPreferances().getAccounts().getReciveAccounts();
|
||||
for (Account__Receive account: recieve_accounts) {
|
||||
Collection<Identity> identities = account.getCollectionIdentities();
|
||||
Account__Send send_account = account.getSendAccount();
|
||||
for (Identity id: identities) {
|
||||
ai_a.add(new AccountIdentity(send_account, id));
|
||||
}
|
||||
}
|
||||
return ai_a;
|
||||
}
|
||||
}
|
|
@ -1,314 +0,0 @@
|
|||
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (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/MPL/
|
||||
*
|
||||
* 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 Grendel mail/news client.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1997 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Created: Will Scullin <scullin@netscape.com>, 8 Sep 1997.
|
||||
*
|
||||
* Contributors: Jeff Galyan <talisman@anamorphic.com>
|
||||
* Giao Nguyen <grail@cafebabe.org>
|
||||
* Edwin Woudt <edwin@woudt.nl>
|
||||
*/
|
||||
|
||||
package grendel.ui;
|
||||
|
||||
import grendel.ui.addressbook2.Addressbook;
|
||||
import java.awt.Component;
|
||||
import java.awt.Frame;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.io.IOException;
|
||||
import java.text.MessageFormat;
|
||||
import java.util.Enumeration;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.ToolTipManager;
|
||||
|
||||
import grendel.prefs.base.UIPrefs;
|
||||
import grendel.ui.prefs.Identities;
|
||||
import grendel.ui.prefs.Servers;
|
||||
import grendel.ui.prefs.General;
|
||||
import grendel.ui.prefs.UI;
|
||||
import grendel.storage.MailDrop;
|
||||
import grendel.search.SearchFrame;
|
||||
|
||||
/* Temporarily removed because FilterMaster is broken (edwin)
|
||||
import grendel.filters.FilterMaster;
|
||||
*/
|
||||
|
||||
import grendel.composition.Composition;
|
||||
import com.trfenv.parsers.Event;
|
||||
|
||||
/**
|
||||
*Generates a list of common Grendel events for use across the application.
|
||||
*/
|
||||
public class ActionFactory {
|
||||
static ExitAction fExitAction = new ExitAction();
|
||||
static NewMailAction fNewMailAction = new NewMailAction();
|
||||
static ComposeMessageAction fComposeMessageAction = new ComposeMessageAction();
|
||||
static PreferencesAction fPrefsAction = new PreferencesAction();
|
||||
static SearchAction fSearchAction = new SearchAction();
|
||||
static RunFiltersAction fRunFiltersAction = new RunFiltersAction();
|
||||
static ShowTooltipsAction fShowTooltipsAction = new ShowTooltipsAction();
|
||||
static RunIdentityPrefsAction fRunIdentityPrefsAction = new RunIdentityPrefsAction();
|
||||
static RunServerPrefsAction fRunServerPrefsAction = new RunServerPrefsAction();
|
||||
static RunGeneralPrefsAction fRunGeneralPrefsAction = new RunGeneralPrefsAction();
|
||||
static RunUIPrefsAction fRunUIPrefsAction = new RunUIPrefsAction();
|
||||
static ShowAddressBookAction fShowAddressBookAction = new ShowAddressBookAction();
|
||||
|
||||
private static Event[] prefEvents;
|
||||
|
||||
static int fIdent = 0;
|
||||
|
||||
static Runnable fComposeMessageThread = new DummyComposeMessageThread();
|
||||
|
||||
public static ExitAction GetExitAction() {
|
||||
return fExitAction;
|
||||
}
|
||||
|
||||
public static NewMailAction GetNewMailAction() {
|
||||
return fNewMailAction;
|
||||
}
|
||||
|
||||
public static ComposeMessageAction GetComposeMessageAction() {
|
||||
return fComposeMessageAction;
|
||||
}
|
||||
|
||||
public static void SetComposeMessageThread(Runnable aThread) {
|
||||
fComposeMessageThread = aThread;
|
||||
}
|
||||
|
||||
public static void setIdent(int aIdent) {
|
||||
System.out.println("setIdent "+aIdent);
|
||||
fIdent = aIdent;
|
||||
}
|
||||
|
||||
public static int getIdent() {
|
||||
System.out.println("getIdent "+fIdent);
|
||||
return fIdent;
|
||||
}
|
||||
|
||||
public static PreferencesAction GetPreferencesAction() {
|
||||
return fPrefsAction;
|
||||
}
|
||||
|
||||
public static SearchAction GetSearchAction() {
|
||||
return fSearchAction;
|
||||
}
|
||||
|
||||
public static RunFiltersAction GetRunFiltersAction() {
|
||||
return fRunFiltersAction;
|
||||
}
|
||||
|
||||
public static ShowTooltipsAction GetShowTooltipsAction() {
|
||||
return fShowTooltipsAction;
|
||||
}
|
||||
|
||||
public static RunIdentityPrefsAction GetRunIdentityPrefsAction() {
|
||||
return fRunIdentityPrefsAction;
|
||||
}
|
||||
|
||||
public static RunServerPrefsAction GetRunServerPrefsAction() {
|
||||
return fRunServerPrefsAction;
|
||||
}
|
||||
|
||||
public static RunGeneralPrefsAction GetRunGeneralPrefsAction() {
|
||||
return fRunGeneralPrefsAction;
|
||||
}
|
||||
|
||||
public static RunUIPrefsAction GetRunUIPrefsAction() {
|
||||
return fRunUIPrefsAction;
|
||||
}
|
||||
|
||||
public static ShowAddressBookAction GetShowAddressBookAction() {
|
||||
return fShowAddressBookAction;
|
||||
}
|
||||
|
||||
/**
|
||||
*Returns an array of all the preferences events. Used in windows that
|
||||
*don't automatically have the preferences events supplied to them.
|
||||
*/
|
||||
public static Event[] prefEvents() {
|
||||
if (prefEvents == null) {
|
||||
prefEvents = new Event[] {
|
||||
ActionFactory.GetRunGeneralPrefsAction(), ActionFactory.GetRunIdentityPrefsAction(),
|
||||
ActionFactory.GetRunServerPrefsAction(), ActionFactory.GetRunUIPrefsAction()
|
||||
};
|
||||
}
|
||||
return prefEvents;
|
||||
}
|
||||
}
|
||||
|
||||
class ExitAction extends Event {
|
||||
|
||||
public ExitAction() {
|
||||
super("appExit");
|
||||
|
||||
setEnabled(true);
|
||||
}
|
||||
|
||||
|
||||
public void actionPerformed(ActionEvent aEvent) {
|
||||
GeneralFrame.CloseAllFrames();
|
||||
|
||||
if (GeneralFrame.GetFrameList().length == 0) {
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class NewMailAction extends Event {
|
||||
|
||||
public NewMailAction() {
|
||||
super("msgGetNew");
|
||||
|
||||
setEnabled(true);
|
||||
}
|
||||
|
||||
|
||||
public void actionPerformed(ActionEvent aEvent) {
|
||||
ProgressFactory.NewMailProgress();
|
||||
}
|
||||
}
|
||||
|
||||
class ComposeMessageAction extends Event {
|
||||
|
||||
public ComposeMessageAction() {
|
||||
super("msgNew");
|
||||
|
||||
setEnabled(true);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent aEvent) {
|
||||
new Thread(ActionFactory.fComposeMessageThread, "Composition Starter").start();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class DummyComposeMessageThread implements Runnable {
|
||||
public void run() {
|
||||
System.out.println("This should not happen! DummyComposeMessageThread called.");
|
||||
}
|
||||
}
|
||||
|
||||
class SearchAction extends Event {
|
||||
SearchAction() {
|
||||
super("appSearch");
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent aEvent) {
|
||||
Frame frame = new SearchFrame();
|
||||
frame.setVisible(true);
|
||||
frame.toFront();
|
||||
frame.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
class RunFiltersAction extends Event {
|
||||
|
||||
RunFiltersAction() {
|
||||
super("appRunFilters");
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent aEvent) {
|
||||
/* Temporarily removed because FilterMaster is broken (edwin)
|
||||
FilterMaster fm = FilterMaster.Get();
|
||||
fm.applyFiltersToTestInbox();
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
class ShowAddressBookAction extends Event {
|
||||
|
||||
ShowAddressBookAction() {
|
||||
super("openAddressBook");
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent aEvent) {
|
||||
Addressbook AddressbookFrame = new Addressbook();
|
||||
AddressbookFrame.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
class ShowTooltipsAction extends Event {
|
||||
|
||||
ShowTooltipsAction() {
|
||||
super("appShowTooltips");
|
||||
|
||||
boolean enabled = UIPrefs.GetMaster().getTooltips();
|
||||
ToolTipManager.sharedInstance().setEnabled(enabled);
|
||||
|
||||
// setSelected(enabled ? AbstractUICmd.kSelected : AbstractUICmd.kUnselected);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent aEvent) {
|
||||
boolean enabled = !ToolTipManager.sharedInstance().isEnabled();
|
||||
ToolTipManager.sharedInstance().setEnabled(enabled);
|
||||
// setSelected(enabled ? AbstractUICmd.kSelected : AbstractUICmd.kUnselected);
|
||||
UIPrefs.GetMaster().setTooltips(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
class RunIdentityPrefsAction extends Event {
|
||||
|
||||
RunIdentityPrefsAction() {
|
||||
super("prefIds");
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent aEvent) {
|
||||
JFrame prefs = new Identities();
|
||||
prefs.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
class RunServerPrefsAction extends Event {
|
||||
|
||||
RunServerPrefsAction() {
|
||||
super("prefSrvs");
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent aEvent) {
|
||||
JFrame prefs = new Servers();
|
||||
prefs.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
class RunGeneralPrefsAction extends Event {
|
||||
|
||||
RunGeneralPrefsAction() {
|
||||
super("prefGeneral");
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent aEvent) {
|
||||
JFrame prefs = new General();
|
||||
prefs.setVisible(true);
|
||||
}
|
||||
}
|
||||
|
||||
class RunUIPrefsAction extends Event {
|
||||
|
||||
RunUIPrefsAction() {
|
||||
super("prefUI");
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent aEvent) {
|
||||
JFrame prefs = new UI();
|
||||
prefs.setVisible(true);
|
||||
}
|
||||
}
|
|
@ -1,223 +0,0 @@
|
|||
<!--
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public
|
||||
# License Version 1.1 (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/MPL/
|
||||
#
|
||||
# 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 Grendel mail/news client.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape Communications
|
||||
# Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1997 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s): Will Scullin <scullin@meer.net>
|
||||
# Edwin Woudt <edwin@woudt.nl>
|
||||
# R.J. Keller <rj.keller@beonex.com
|
||||
# -->
|
||||
|
||||
<!-- multipane menu labels -->
|
||||
|
||||
<!ENTITY multiFileLabel "File" >
|
||||
<!ENTITY multiFileAccel "F" >
|
||||
<!ENTITY multiEditLabel "Edit" >
|
||||
<!ENTITY multiEditAccel "E" >
|
||||
<!ENTITY multiViewLabel "View" >
|
||||
<!ENTITY multiViewAccel "V" >
|
||||
<!ENTITY multiMessageLabel "Message" >
|
||||
<!ENTITY multiMessageAccel "M" >
|
||||
|
||||
<!-- Master menu labels -->
|
||||
|
||||
<!ENTITY masterFileLabel "File" >
|
||||
<!ENTITY masterFileAccel "F" >
|
||||
<!ENTITY masterEditLabel "Edit" >
|
||||
<!ENTITY masterEditAccel "E" >
|
||||
|
||||
<!-- Folder menu labels -->
|
||||
|
||||
<!ENTITY folderFileLabel "File" >
|
||||
<!ENTITY folderFileAccel "F" >
|
||||
<!ENTITY folderEditLabel "Edit" >
|
||||
<!ENTITY folderEditAccel "E" >
|
||||
<!ENTITY folderMessageLabel "Message" >
|
||||
<!ENTITY folderMessageAccel "M" >
|
||||
|
||||
<!-- Message menu labels -->
|
||||
|
||||
<!ENTITY messageFileLabel "File" >
|
||||
<!ENTITY messageFileAccel "F" >
|
||||
<!ENTITY messageEditLabel "Edit" >
|
||||
<!ENTITY messageEditAccel "E" >
|
||||
<!ENTITY messageMessageLabel "Message" >
|
||||
<!ENTITY messageMessageAccel "M" >
|
||||
|
||||
<!-- View menu labels -->
|
||||
|
||||
<!ENTITY viewLayoutLabel "Layout" >
|
||||
<!ENTITY viewLayoutAccel "L" >
|
||||
<!ENTITY splitLeftLabel "Split Left" >
|
||||
<!ENTITY splitLeftAccel "L" >
|
||||
<!ENTITY splitRightLabel "Split Right" >
|
||||
<!ENTITY splitRightAccel "R" >
|
||||
<!ENTITY splitTopLabel "Split Top" >
|
||||
<!ENTITY splitTopAccel "T" >
|
||||
<!ENTITY stackedLabel "Stacked" >
|
||||
<!ENTITY stackedAccel "S" >
|
||||
<!ENTITY appShowTooltipsLabel "Show Tooltips" >
|
||||
<!ENTITY appShowTooltipsAccel "T" >
|
||||
|
||||
<!-- Common menu labels -->
|
||||
|
||||
<!ENTITY windowLabel "Window" >
|
||||
<!ENTITY windowAccel "W" >
|
||||
|
||||
<!-- Application menu item labels -->
|
||||
|
||||
<!ENTITY appExitLabel "Exit" >
|
||||
<!ENTITY appExitAccel "x" >
|
||||
<!ENTITY appPrefsLabel "Preferences..." >
|
||||
<!ENTITY appPrefsAccel "r" >
|
||||
<!ENTITY appSearchLabel "Search" >
|
||||
<!ENTITY appSearchAccel "S" >
|
||||
<!ENTITY appRunFiltersLabel "Run Filters on TestInbox" >
|
||||
<!ENTITY appRunFiltersAccel "F" >
|
||||
|
||||
<!-- Edit menu item labels -->
|
||||
|
||||
<!ENTITY editUndoLabel "Undo" >
|
||||
<!ENTITY editUndoAccel "U" >
|
||||
<!ENTITY editRedoLabel "Redo" >
|
||||
<!ENTITY editRedoAccel "R" >
|
||||
|
||||
<!ENTITY editCutLabel "Cut" >
|
||||
<!ENTITY editCutAccel "t" >
|
||||
<!ENTITY editCopyLabel "Copy" >
|
||||
<!ENTITY editCopyAccel "C" >
|
||||
<!ENTITY editPasteLabel "Paste" >
|
||||
<!ENTITY editPasteAccel "P" >
|
||||
<!ENTITY editClearLabel "Delete" >
|
||||
<!ENTITY editClearAccel "D" >
|
||||
|
||||
<!-- Folder menu item labels -->
|
||||
|
||||
<!ENTITY folderOpenLabel "Open Folder" >
|
||||
<!ENTITY folderOpenAccel "O" >
|
||||
|
||||
<!-- Message menu item labels -->
|
||||
|
||||
<!ENTITY folderNewLabel "Folder..." >
|
||||
<!ENTITY folderNewAccel "F" >
|
||||
<!ENTITY folderDeleteLabel "Delete Folder" >
|
||||
<!ENTITY folderDeleteAccel "D" >
|
||||
|
||||
<!ENTITY accountNewLabel "Account..." >
|
||||
<!ENTITY accountNewAccel "A" >
|
||||
|
||||
<!ENTITY msgGetNewLabel "Get New Messages" >
|
||||
<!ENTITY msgGetNewAccel "G" >
|
||||
<!ENTITY msgOpenLabel "Open Message" >
|
||||
<!ENTITY msgOpenAccel "M" >
|
||||
<!ENTITY msgSaveAsLabel "Save As..." >
|
||||
<!ENTITY msgSaveAsAccel "A" >
|
||||
<!ENTITY newLabel "New" >
|
||||
<!ENTITY newAccel "N" >
|
||||
<!ENTITY msgNewLabel "Message" >
|
||||
<!ENTITY msgNewAccel "M" >
|
||||
<!ENTITY msgNewLabel2 "New Message" >
|
||||
<!ENTITY msgNewAccel2 "N" >
|
||||
|
||||
<!ENTITY msgReplyLabel "Reply" >
|
||||
<!ENTITY msgReplyAccel "R" >
|
||||
<!ENTITY msgReplyAllLabel "Reply All" >
|
||||
<!ENTITY msgReplyAllAccel "A" >
|
||||
<!ENTITY fwdQuotedLabel "Forward Quoted" >
|
||||
<!ENTITY fwdQuotedAccel "Q" >
|
||||
<!ENTITY fwdInlineLabel "Forward Inline" >
|
||||
<!ENTITY fwdInlineAccel "I" >
|
||||
<!ENTITY fwdAttachmentLabel "Forward Attachment" >
|
||||
<!ENTITY fwdAttachmentAccel "A" >
|
||||
<!ENTITY msgMoveLabel "File to" >
|
||||
<!ENTITY msgMoveAccel "F" >
|
||||
<!ENTITY msgMovePopupLabel "File to" >
|
||||
<!ENTITY msgCopyLabel "Copy to" >
|
||||
<!ENTITY msgCopyAccel "C" >
|
||||
<!ENTITY msgCopyPopupLabel "Copy to" >
|
||||
<!ENTITY msgDeleteLabel "Delete Message" >
|
||||
<!ENTITY msgDeleteAccel "D" >
|
||||
<!ENTITY msgDeletePopupLabel "Delete Message" >
|
||||
|
||||
<!ENTITY msgMarkLabel "Mark" >
|
||||
<!ENTITY msgMarkAccel "M" >
|
||||
|
||||
<!-- Mark menu labels -->
|
||||
|
||||
<!ENTITY markMsgReadLabel "As Read" >
|
||||
<!ENTITY markMsgReadAccel "R" >
|
||||
<!ENTITY markThreadReadLabel "Thread Read" >
|
||||
<!ENTITY markThreadReadAccel "T" >
|
||||
<!ENTITY markAllReadLabel "All Read" >
|
||||
<!ENTITY markAllReadAccel "A" >
|
||||
|
||||
<!-- Sort menu labels -->
|
||||
|
||||
<!ENTITY viewSortLabel "Sort" >
|
||||
<!ENTITY viewSortAccel "S" >
|
||||
|
||||
<!ENTITY toggleThreadingLabel "Toggle Threading" >
|
||||
<!ENTITY toggleThreadingAccel "T" >
|
||||
<!ENTITY sortDateLabel "by Date" >
|
||||
<!ENTITY sortDateAccel "D" >
|
||||
<!ENTITY sortSubjectLabel "by Subject" >
|
||||
<!ENTITY sortSubjectAccel "S" >
|
||||
<!ENTITY sortAuthorLabel "by Author" >
|
||||
<!ENTITY sortAuthorAccel "A" >
|
||||
<!ENTITY sortNumberLabel "by Number" >
|
||||
<!ENTITY sortNumberAccel "N" >
|
||||
|
||||
<!-- Window menu item labels -->
|
||||
|
||||
<!ENTITY windowListLabel "Window List..." >
|
||||
<!ENTITY windowListAccel "W" >
|
||||
|
||||
<!-- Preferences menu labels -->
|
||||
|
||||
<!ENTITY multiPrefsLabel "Tools" >
|
||||
<!ENTITY multiPrefsAccel "T" >
|
||||
|
||||
<!ENTITY prefIdsLabel "Identities" >
|
||||
<!ENTITY prefIdsAccel "I" >
|
||||
<!ENTITY prefSrvsLabel "Servers" >
|
||||
<!ENTITY prefSrvsAccel "S" >
|
||||
<!ENTITY prefGeneralLabel "General" >
|
||||
<!ENTITY prefGeneralAccel "G" >
|
||||
<!ENTITY prefUILabel "User interface" >
|
||||
<!ENTITY prefUIAccel "U" >
|
||||
|
||||
<!ENTITY addressBookLabel "Address Book..." >
|
||||
<!ENTITY addressBookAccel "A" >
|
||||
|
||||
<!-- view menu labels -->
|
||||
<!ENTITY toolbarsLabel "Toolbars" >
|
||||
<!ENTITY toolbarsAccel "T" >
|
||||
<!ENTITY mailToolbarsLabel "Mail Toolbar" >
|
||||
<!ENTITY mailToolbarsAccel "M" >
|
||||
<!ENTITY statusbarLabel "Status Bar" >
|
||||
<!ENTITY statusbarAccel "S" >
|
||||
|
||||
<!-- help menu labels -->
|
||||
<!ENTITY helpLabel "Help" >
|
||||
<!ENTITY helpAccel "H" >
|
||||
|
||||
<!ENTITY contentsLabel "Contents..." >
|
||||
<!ENTITY contentsAccel "C" >
|
||||
<!ENTITY releaseNotesLabel "Release Notes" >
|
||||
<!ENTITY releaseNotesAccel "R" >
|
||||
<!ENTITY aboutLabel "About Grendel..." >
|
||||
<!ENTITY aboutAccel "A" >
|
|
@ -1,496 +0,0 @@
|
|||
/* -*- Mode: java; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (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/MPL/
|
||||
*
|
||||
* 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 Grendel mail/news client.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1997 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s): Jeff Galyan <talisman@anamorphic.com>
|
||||
* Giao Nguyen <grail@cafebabe.org>
|
||||
* Edwin Woudt <edwin@woudt.nl>
|
||||
*/
|
||||
|
||||
package grendel.ui;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GridBagConstraints;
|
||||
import java.awt.GridBagLayout;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.Icon;
|
||||
import javax.swing.ImageIcon;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JToolBar;
|
||||
import javax.swing.JSplitPane;
|
||||
import javax.swing.event.ChangeEvent;
|
||||
|
||||
import calypso.util.Preferences;
|
||||
import calypso.util.PreferencesFactory;
|
||||
|
||||
import javax.mail.Store;
|
||||
import javax.mail.Folder;
|
||||
import javax.mail.Message;
|
||||
import javax.mail.MessagingException;
|
||||
|
||||
import grendel.prefs.base.InvisiblePrefs;
|
||||
import grendel.prefs.base.UIPrefs;
|
||||
import grendel.view.ViewedMessage;
|
||||
import grendel.widgets.Spring;
|
||||
import grendel.widgets.StatusEvent;
|
||||
import javax.swing.tree.TreePath;
|
||||
|
||||
import com.trfenv.parsers.Event;
|
||||
|
||||
/**
|
||||
* The legendary three pane UI.
|
||||
*/
|
||||
|
||||
public class UnifiedMessageDisplayManager extends MessageDisplayManager {
|
||||
UnifiedMessageFrame fMainFrame;
|
||||
|
||||
public final static String SPLIT_TOP = "splitTop";
|
||||
public final static String SPLIT_LEFT = "splitLeft";
|
||||
public final static String SPLIT_RIGHT = "splitRight";
|
||||
public final static String STACKED = "stacked";
|
||||
|
||||
/**
|
||||
* Displays a message given a Message object. If the message
|
||||
* is not in the currently selected folder, that folder will
|
||||
* be selected, loaded and displayed.
|
||||
*/
|
||||
|
||||
public void displayMessage(Message aMessage) {
|
||||
checkFrame();
|
||||
fMainFrame.display(aMessage.getFolder(), aMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a folder given a folder object. If the message
|
||||
* being displayed is not in that folder, the message
|
||||
* display pane will be cleared.
|
||||
*/
|
||||
|
||||
public void displayFolder(Folder aFolder) {
|
||||
checkFrame();
|
||||
fMainFrame.display(aFolder, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays folder given a Folder object and
|
||||
* selects and displays a message in that folder given a Message
|
||||
* object.
|
||||
*/
|
||||
|
||||
public void displayFolder(Folder aFolder, Message aMessage) {
|
||||
checkFrame();
|
||||
fMainFrame.display(aFolder, aMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the master (A folder tree, for now). This should not
|
||||
* affect displayed folders or messages.
|
||||
*/
|
||||
|
||||
public void displayMaster() {
|
||||
checkFrame();
|
||||
fMainFrame.display(null, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the master with the given folder selected. If the
|
||||
* folder is not currently displayed, the folder will be loaded
|
||||
* in the folder message list pane, and the message pane will be
|
||||
* cleared.
|
||||
*/
|
||||
|
||||
public void displayMaster(Folder aFolder) {
|
||||
checkFrame();
|
||||
fMainFrame.display(aFolder, null);
|
||||
}
|
||||
|
||||
void checkFrame() {
|
||||
if (fMainFrame == null) {
|
||||
fMainFrame = new UnifiedMessageFrame();
|
||||
fMainFrame.setVisible(true);
|
||||
}
|
||||
fMainFrame.toFront();
|
||||
fMainFrame.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
class UnifiedMessageFrame extends GeneralFrame {
|
||||
private final boolean DEBUG = false;
|
||||
MasterPanel fFolders = null;
|
||||
FolderPanel fThreads = null;
|
||||
MessagePanel fMessage = null;
|
||||
JSplitPane splitter1 = null, splitter2 = null;
|
||||
String fLayout = null;
|
||||
JToolBar fToolBar1 = null;
|
||||
static final int FOLDERX = 350;
|
||||
static final int FOLDERY = 225;
|
||||
static final int THREADX = 200;
|
||||
static final int THREADY = 200;
|
||||
int folderX = FOLDERX;
|
||||
int folderY = FOLDERY;
|
||||
int threadX = THREADX;
|
||||
int threadY = THREADX;
|
||||
|
||||
boolean relayout = false;
|
||||
|
||||
public UnifiedMessageFrame() {
|
||||
super("appNameLabel", "multipane");
|
||||
|
||||
PrefsDialog.CheckPrefs(this);
|
||||
|
||||
fFolders = new MasterPanel();
|
||||
fThreads = new FolderPanel();
|
||||
fMessage = new MessagePanel();
|
||||
|
||||
fFolders.setPreferredSize(new Dimension(folderX, folderY));
|
||||
fThreads.setPreferredSize(new Dimension(threadX, threadY));
|
||||
|
||||
splitter1 = new JSplitPane();
|
||||
splitter2 = new JSplitPane();
|
||||
splitter1.setOneTouchExpandable(true);
|
||||
splitter2.setOneTouchExpandable(true);
|
||||
|
||||
PanelListener listener = new PanelListener();
|
||||
|
||||
fFolders.addMasterPanelListener(listener);
|
||||
fThreads.addFolderPanelListener(listener);
|
||||
fMessage.addMessagePanelListener(listener);
|
||||
|
||||
String layout = UIPrefs.GetMaster().getMultiPaneLayout();
|
||||
|
||||
layoutPanels(layout);
|
||||
|
||||
XMLMenuBuilder builder = new XMLMenuBuilder(Util.MergeActions(actions, Util.MergeActions(fFolders.getActions(), Util.MergeActions(fThreads.getActions(), fMessage.getActions()))));
|
||||
fMenu = builder.buildFrom("ui/grendel.xml", this);
|
||||
|
||||
getRootPane().setJMenuBar(fMenu);
|
||||
|
||||
JToolBar masterToolBar = fFolders.getToolBar();
|
||||
JToolBar folderToolBar = fThreads.getToolBar();
|
||||
JToolBar messageToolBar = fMessage.getToolBar();
|
||||
|
||||
|
||||
fToolBar = Util.MergeToolBars(masterToolBar,
|
||||
Util.MergeToolBars(folderToolBar,
|
||||
messageToolBar));
|
||||
|
||||
fToolBarPanelConstraints.fill = GridBagConstraints.HORIZONTAL;
|
||||
fToolBarPanelConstraints.anchor = GridBagConstraints.WEST;
|
||||
fToolBarPanel.setComponent(fToolBar);
|
||||
fToolBar.add(new Spring());
|
||||
fToolBarPanelConstraints.weightx = 1.0;
|
||||
fToolBarPanelConstraints.fill = GridBagConstraints.NONE;
|
||||
fToolBarPanelConstraints.gridwidth = GridBagConstraints.REMAINDER;
|
||||
fToolBarPanelConstraints.anchor = GridBagConstraints.EAST;
|
||||
|
||||
fToolBar.add(fAnimation, fToolBarPanelConstraints);
|
||||
|
||||
fStatusBar = buildStatusBar();
|
||||
fPanel.add(BorderLayout.SOUTH, fStatusBar);
|
||||
|
||||
restoreBounds();
|
||||
}
|
||||
|
||||
public void dispose() {
|
||||
saveBounds();
|
||||
|
||||
if (fLayout == null) {
|
||||
fLayout = UnifiedMessageDisplayManager.SPLIT_TOP;
|
||||
}
|
||||
|
||||
InvisiblePrefs.GetMaster().setMultiPaneSizes(
|
||||
fFolders.getSize().width, fFolders.getSize().height,
|
||||
fThreads.getSize().width, fThreads.getSize().height
|
||||
);
|
||||
|
||||
UIPrefs.GetMaster().setMultiPaneLayout(fLayout);
|
||||
UIPrefs.GetMaster().writePrefs();
|
||||
|
||||
fFolders.dispose();
|
||||
fThreads.dispose();
|
||||
fMessage.dispose();
|
||||
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
public void display(Folder aFolder, Message aMessage) {
|
||||
if (aFolder != null) {
|
||||
fThreads.setFolder(aFolder);
|
||||
fMessage.setMessage(aMessage);
|
||||
}
|
||||
}
|
||||
|
||||
void layoutPanels(String layout) {
|
||||
boolean touch = true;
|
||||
|
||||
if (fLayout != null) {
|
||||
if (fLayout.equals(layout)) {
|
||||
return; // nothing to do
|
||||
}
|
||||
|
||||
fLayout = layout;
|
||||
remove(splitter1);
|
||||
remove(splitter2);
|
||||
}
|
||||
fPanel.remove(splitter1);
|
||||
splitter1 = new JSplitPane();
|
||||
splitter2 = new JSplitPane();
|
||||
splitter1.setOneTouchExpandable(true);
|
||||
splitter2.setOneTouchExpandable(true);
|
||||
|
||||
|
||||
if (relayout == false) {
|
||||
InvisiblePrefs prefs = InvisiblePrefs.GetMaster();
|
||||
|
||||
// read dimensions out of preferences
|
||||
try {
|
||||
int tx, ty, fx, fy; // temporary dimensions
|
||||
fx = prefs.getMultiPaneFolderX(folderX);
|
||||
fy = prefs.getMultiPaneFolderY(folderY);
|
||||
tx = prefs.getMultiPaneThreadX(threadX);
|
||||
ty = prefs.getMultiPaneThreadY(threadY);
|
||||
folderX = fx;
|
||||
folderY = fy;
|
||||
threadX = tx;
|
||||
threadY = ty;
|
||||
// if the try bails, we use default
|
||||
} catch (NumberFormatException nf_ty) {
|
||||
nf_ty.printStackTrace();
|
||||
} finally {
|
||||
relayout = true;
|
||||
}
|
||||
} else {
|
||||
folderX = FOLDERX;
|
||||
folderY = FOLDERY;
|
||||
threadX = THREADX;
|
||||
threadY = THREADY;
|
||||
}
|
||||
|
||||
if (layout.equals(UnifiedMessageDisplayManager.STACKED)) {
|
||||
splitter1.setOrientation(JSplitPane.VERTICAL_SPLIT);
|
||||
splitter2.setOrientation(JSplitPane.VERTICAL_SPLIT);
|
||||
|
||||
splitter1.setTopComponent(fFolders);
|
||||
splitter1.setBottomComponent(splitter2);
|
||||
|
||||
splitter2.setTopComponent(fThreads);
|
||||
splitter2.setBottomComponent(fMessage);
|
||||
} else if (layout.equals(UnifiedMessageDisplayManager.SPLIT_LEFT)) {
|
||||
splitter1.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
|
||||
splitter2.setOrientation(JSplitPane.VERTICAL_SPLIT);
|
||||
|
||||
splitter2.setLeftComponent(fFolders);
|
||||
splitter2.setRightComponent(fThreads);
|
||||
|
||||
splitter1.setTopComponent(splitter2);
|
||||
splitter1.setBottomComponent(fMessage);
|
||||
|
||||
} else if (layout.equals(UnifiedMessageDisplayManager.SPLIT_RIGHT)) {
|
||||
splitter2.setOrientation(JSplitPane.VERTICAL_SPLIT);
|
||||
splitter1.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
|
||||
|
||||
splitter2.setLeftComponent(fThreads);
|
||||
splitter2.setRightComponent(fMessage);
|
||||
|
||||
splitter1.setTopComponent(fFolders);
|
||||
splitter1.setBottomComponent(splitter2);
|
||||
} else { // Default: SPLIT_TOP
|
||||
splitter2.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
|
||||
splitter1.setOrientation(JSplitPane.VERTICAL_SPLIT);
|
||||
|
||||
splitter2.setLeftComponent(fFolders);
|
||||
splitter2.setRightComponent(fThreads);
|
||||
|
||||
splitter1.setTopComponent(splitter2);
|
||||
splitter1.setBottomComponent(fMessage);
|
||||
}
|
||||
|
||||
fFolders.setPreferredSize(new Dimension(folderX, folderY));
|
||||
fThreads.setPreferredSize(new Dimension(threadX, threadY));
|
||||
fPanel.add(splitter1, BorderLayout.CENTER);
|
||||
|
||||
invalidate();
|
||||
validate();
|
||||
|
||||
fLayout = layout;
|
||||
}
|
||||
|
||||
LayoutAction fSplitLeftLayoutAction =
|
||||
new LayoutAction(UnifiedMessageDisplayManager.SPLIT_LEFT);
|
||||
LayoutAction fSplitRightLayoutAction =
|
||||
new LayoutAction(UnifiedMessageDisplayManager.SPLIT_RIGHT);
|
||||
LayoutAction fSplitTopLayoutAction =
|
||||
new LayoutAction(UnifiedMessageDisplayManager.SPLIT_TOP);
|
||||
LayoutAction fStackedLayoutAction =
|
||||
new LayoutAction(UnifiedMessageDisplayManager.STACKED);
|
||||
|
||||
Event[] actions = { ActionFactory.GetExitAction(),
|
||||
ActionFactory.GetNewMailAction(),
|
||||
ActionFactory.GetComposeMessageAction(),
|
||||
ActionFactory.GetPreferencesAction(),
|
||||
ActionFactory.GetSearchAction(),
|
||||
ActionFactory.GetRunFiltersAction(),
|
||||
ActionFactory.GetShowAddressBookAction(),
|
||||
ActionFactory.GetShowTooltipsAction(),
|
||||
ActionFactory.GetRunIdentityPrefsAction(),
|
||||
ActionFactory.GetRunServerPrefsAction(),
|
||||
ActionFactory.GetRunGeneralPrefsAction(),
|
||||
ActionFactory.GetRunUIPrefsAction(),
|
||||
fSplitLeftLayoutAction,
|
||||
fSplitRightLayoutAction,
|
||||
fSplitTopLayoutAction,
|
||||
fStackedLayoutAction
|
||||
};
|
||||
|
||||
|
||||
class PanelListener implements MasterPanelListener, FolderPanelListener,
|
||||
MessagePanelListener
|
||||
{
|
||||
// FolderPanelListener
|
||||
|
||||
public void loadingFolder(ChangeEvent aEvent) {
|
||||
// start animation
|
||||
fAnimation.start();
|
||||
}
|
||||
|
||||
public void folderLoaded(ChangeEvent aEvent) {
|
||||
// stop animation
|
||||
fAnimation.stop();
|
||||
}
|
||||
|
||||
public void folderStatus(StatusEvent aEvent) {
|
||||
setStatusText(aEvent.getStatus());
|
||||
}
|
||||
|
||||
public void folderSelectionChanged(ChangeEvent aEvent) {
|
||||
TreePath path = null;
|
||||
Enumeration selection =
|
||||
((FolderPanel) aEvent.getSource()).getSelection();
|
||||
|
||||
if (selection.hasMoreElements()) {
|
||||
path = (TreePath) selection.nextElement();
|
||||
}
|
||||
if (path != null && !selection.hasMoreElements()) {
|
||||
// not multiple selection
|
||||
ViewedMessage node = (ViewedMessage) path.getPath()[path.getPath().length - 1];
|
||||
fMessage.setMessage(node.getMessage());
|
||||
} else {
|
||||
fMessage.setMessage(null);
|
||||
}
|
||||
}
|
||||
public void folderSelectionDoubleClicked(ChangeEvent aEvent) {
|
||||
TreePath path = null;
|
||||
Enumeration selection = ((FolderPanel)aEvent.getSource()).getSelection();
|
||||
|
||||
MessageDisplayManager master = MultiMessageDisplayManager.Get();
|
||||
|
||||
while (selection.hasMoreElements()) {
|
||||
path = (TreePath) selection.nextElement();
|
||||
if (path != null) {
|
||||
ViewedMessage node = (ViewedMessage) path.getPath()[path.getPath().length - 1];
|
||||
master.displayMessage(node.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MasterPanelListener
|
||||
|
||||
public void masterSelectionChanged(ChangeEvent aEvent) {
|
||||
TreePath path = null;
|
||||
Enumeration selection =
|
||||
((MasterPanel) aEvent.getSource()).getSelection();
|
||||
if (selection.hasMoreElements()) {
|
||||
path = (TreePath) selection.nextElement();
|
||||
}
|
||||
Object node = null;
|
||||
Folder folder = null;
|
||||
if (path != null && !selection.hasMoreElements()) {
|
||||
// not multiple selection
|
||||
node = path.getPath()[path.getPath().length - 1];
|
||||
}
|
||||
|
||||
folder = MasterPanel.getFolder(node);
|
||||
|
||||
if (folder != null) {
|
||||
try {
|
||||
if ((folder.getType() & Folder.HOLDS_MESSAGES) == 0) {
|
||||
folder = null;
|
||||
}
|
||||
} catch (MessagingException e) {
|
||||
folder = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (folder != null) {
|
||||
setTitle(folder.getName() +
|
||||
fLabels.getString("folderSuffixFrameLabel"));
|
||||
fThreads.setFolder(folder);
|
||||
} else {
|
||||
setTitle(fLabels.getString("appNameLabel"));
|
||||
fThreads.setFolder(null);
|
||||
}
|
||||
}
|
||||
|
||||
public void masterSelectionDoubleClicked(ChangeEvent aEvent) {
|
||||
}
|
||||
|
||||
// MessagePanelListener
|
||||
|
||||
public void loadingMessage(ChangeEvent aEvent) {
|
||||
startAnimation();
|
||||
}
|
||||
|
||||
public void messageLoaded(ChangeEvent aEvent) {
|
||||
stopAnimation();
|
||||
}
|
||||
|
||||
public void messageStatus(StatusEvent aEvent) {
|
||||
setStatusText(aEvent.getStatus());
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// LayoutAction class
|
||||
//
|
||||
|
||||
class LayoutAction extends Event {
|
||||
ImageIcon fIcon;
|
||||
String action;
|
||||
public LayoutAction(String aAction) {
|
||||
super(aAction);
|
||||
this.setEnabled(true);
|
||||
action = aAction;
|
||||
fIcon = new ImageIcon("ui/images/" + aAction + ".gif");
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent aEvent) {
|
||||
layoutPanels(action);
|
||||
}
|
||||
|
||||
public ImageIcon getEnabledIcon() {
|
||||
return fIcon;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,163 +0,0 @@
|
|||
<?xml version="1.0"?>
|
||||
<!-- ***** BEGIN LICENSE BLOCK *****
|
||||
- Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
-
|
||||
- The contents of this file are subject to the Mozilla Public License Version
|
||||
- 1.1 (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/MPL/
|
||||
-
|
||||
- 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 Grendel mail/news client.
|
||||
-
|
||||
- The Initial Developer of the Original Code is
|
||||
- R.J. Keller.
|
||||
- Portions created by the Initial Developer are Copyright (C) 2005
|
||||
- the Initial Developer. All Rights Reserved.
|
||||
-
|
||||
- Contributor(s):
|
||||
-
|
||||
- Alternatively, the contents of this file may be used under the terms of
|
||||
- either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
- the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
- in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
- of those above. If you wish to allow use of your version of this file only
|
||||
- under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
- use your version of this file under the terms of the MPL, indicate your
|
||||
- decision by deleting the provisions above and replace them with the notice
|
||||
- and other provisions required by the LGPL or the GPL. If you do not delete
|
||||
- the provisions above, a recipient may use your version of this file under
|
||||
- the terms of any one of the MPL, the GPL or the LGPL.
|
||||
-
|
||||
- ***** END LICENSE BLOCK ***** -->
|
||||
|
||||
<!DOCTYPE window [
|
||||
<!ENTITY % menuLabelsDTD SYSTEM "MenuLabels.dtd" >
|
||||
%menuLabelsDTD;
|
||||
<!ENTITY % toolbarDTD SYSTEM "Toolbar.dtd" >
|
||||
%toolbarDTD;
|
||||
]>
|
||||
|
||||
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
|
||||
<keyset><!--
|
||||
<key modifiers="accel" key="&folderNewAccel;" oncommand="msgNew"/>
|
||||
--></keyset>
|
||||
|
||||
<menubar id="mail.multi_pane">
|
||||
|
||||
<menu id="FileMenu" label="&multiFileLabel;" accesskey="&multiFileAccel;">
|
||||
<menupopup>
|
||||
<menu label="&newLabel;" accesskey="&newAccel;">
|
||||
<menupopup>
|
||||
<menuitem id="msgNew" onclick="msgNew" label="&msgNewLabel;" accesskey="&msgNewAccel;"/>
|
||||
<menuitem id="folderNew" onclick="folderNew" label="&folderNewLabel;" accesskey="&folderNewAccel;"/>
|
||||
<menuitem id="newAccount" onclick="prefSrvs" label="&accountNewLabel;" accesskey="&accountNewAccel;"/>
|
||||
</menupopup>
|
||||
</menu>
|
||||
<menuitem id="msgOpen" onclick="msgOpen" label="&msgOpenLabel;" accesskey="&msgOpenAccel;"/>
|
||||
<!--
|
||||
<menuitem id="msgSaveAs" onclick="msgSaveAs" label="&msgSaveAsLabel;" accesskey="&msgSaveAsAccel;"/>
|
||||
-->
|
||||
<menuseparator/>
|
||||
<menuitem id="msgGetNew" onclick="msgGetNew" label="&msgGetNewLabel;" accesskey="&msgGetNewAccel;"/>
|
||||
<menuseparator/>
|
||||
<menuitem id="appExit" onclick="appExit" label="&appExitLabel;" accesskey="&appExitAccel;"/>
|
||||
</menupopup>
|
||||
</menu>
|
||||
|
||||
<menu id="EditMenu" label="&multiEditLabel;" accesskey="&multiEditAccel;">
|
||||
<menupopup>
|
||||
<menuitem id="editUndo" onclick="editUndo" label="&editUndoLabel;" accesskey="&editUndoAccel;"/>
|
||||
<menuitem id="editRedo" onclick="editRedo" label="&editRedoLabel;" accesskey="&editRedoAccel;"/>
|
||||
<menuseparator/>
|
||||
<menuitem id="editCut" onclick="editCut" label="&editCutLabel;" accesskey="&editCutAccel;"/>
|
||||
<menuitem id="editCopy" onclick="editCopy" label="&editCopyLabel;" accesskey="&editCopyAccel;"/>
|
||||
<menuitem id="editPaste" onclick="editPaste" label="&editPasteLabel;" accesskey="&editPasteAccel;"/>
|
||||
<menuseparator/>
|
||||
<menuitem id="folderDelete" onclick="folderDelete" label="&folderDeleteLabel;" accesskey="&folderDeleteAccel;"/>
|
||||
<menuseparator/>
|
||||
<menuitem id="appSearch" onclick="appSearch" label="&appSearchLabel;" accesskey="&appSearchAccel;"/>
|
||||
<menuitem id="appRunFilters" onclick="appRunFilters" label="&appRunFiltersLabel;" accesskey="&appRunFiltersAccel;"/>
|
||||
</menupopup>
|
||||
</menu>
|
||||
|
||||
<menu id="ViewMenu" label="&multiViewLabel;" accesskey="&multiViewAccel;">
|
||||
<menupopup>
|
||||
<menu id="toolbars" label="&toolbarsLabel;" accesskey="&toolbarsAccel;">
|
||||
<menupopup>
|
||||
<menuitem onclick="toggleMailToolbar" label="&mailToolbarsLabel;" accesskey="&mailToolbarsAccel;"/>
|
||||
<menuitem onclick="toggleStatusbar" label="&statusbarLabel;" accesskey="&statusbarAccel;"/>
|
||||
</menupopup>
|
||||
</menu>
|
||||
<menu id="SortMenu" label="&viewSortLabel;" accesskey="&viewSortAccel;">
|
||||
<menupopup>
|
||||
<menuitem id="toggleThreading" onclick="toggleThreading" label="&toggleThreadingLabel;" accesskey="&toggleThreadingAccel;"/>
|
||||
<menuseparator/>
|
||||
<menuitem id="sortAuthor" onclick="sortAuthor" label="&sortAuthorLabel;" accesskey="&sortAuthorAccel;"/>
|
||||
<menuitem id="sortDate" onclick="sortDate" label="&sortDateLabel;" accesskey="&sortDateAccel;"/>
|
||||
<menuitem id="sortNumber" onclick="sortNumber" label="&sortNumberLabel;" accesskey="&sortNumberAccel;"/>
|
||||
<menuitem id="sortSubject" onclick="sortSubject" label="&sortSubjectLabel;" accesskey="&sortSubjectAccel;"/>
|
||||
</menupopup>
|
||||
</menu>
|
||||
</menupopup>
|
||||
</menu>
|
||||
|
||||
<menu id="MessageMenu" label="&multiMessageLabel;" accesskey="&multiMessageAccel;">
|
||||
<menupopup>
|
||||
<menuitem id="msgNew" onclick="msgNew" label="&msgNewLabel2;" accesskey="&msgNewAccel2;"/>
|
||||
<menuseparator/>
|
||||
<menuitem id="msgReply" onclick="msgReply" label="&msgReplyLabel;" accesskey="&msgReplyAccel;"/>
|
||||
<menuitem id="msgReplyAll" onclick="msgReplyAll" label="&msgReplyAllLabel;" accesskey="&msgReplyAllAccel;"/>
|
||||
<menuitem id="fwdQuoted" onclick="fwdQuoted" label="&fwdQuotedLabel;" accesskey="&fwdQuotedAccel;"/>
|
||||
<menuitem id="fwdInline" onclick="fwdInline" label="&fwdInlineLabel;" accesskey="&fwdInlineAccel;"/>
|
||||
<menuitem id="fwdAttachment" onclick="fwdAttachment" label="&fwdAttachmentLabel;" accesskey="&fwdAttachmentAccel;"/>
|
||||
<menuseparator/>
|
||||
<menu id="msgMark" label="&msgMarkLabel;" accesskey="&msgMarkAccel;">
|
||||
<menupopup>
|
||||
<menuitem id="markMsgRead" onclick="markMsgRead" label="&markMsgReadLabel;" accesskey="&markMsgReadAccel;"/>
|
||||
<menuitem id="markThreadRead" onclick="markThreadRead" label="&markThreadReadLabel;" accesskey="&markThreadReadAccel;"/>
|
||||
<menuitem id="markAllRead" onclick="markAllRead" label="&markAllReadLabel;" accesskey="&markAllReadAccel;"/>
|
||||
</menupopup>
|
||||
</menu>
|
||||
</menupopup>
|
||||
</menu>
|
||||
|
||||
<menu id="PrefsMenu" label="&multiPrefsLabel;" accesskey="&multiPrefsAccel;">
|
||||
<menupopup>
|
||||
<menuitem onclick="openAddressBook" label="&addressBookLabel;" accesskey="&addressBookAccel;"/>
|
||||
<menuseparator/>
|
||||
<menuitem id="prefGeneral" onclick="prefGeneral" label="&prefGeneralLabel;" accesskey="&prefGeneralAccel;"/>
|
||||
<menuitem id="prefIds" onclick="prefIds" label="&prefIdsLabel;" accesskey="&prefIdsAccel;"/>
|
||||
<menuitem id="prefSrvs" onclick="prefSrvs" label="&prefSrvsLabel;" accesskey="&prefSrvsAccel;"/>
|
||||
<menuitem id="prefUI" onclick="prefUI" label="&prefUILabel;" accesskey="&prefUIAccel;"/>
|
||||
</menupopup>
|
||||
</menu>
|
||||
|
||||
<menu id="HelpMenu" label="&helpLabel;" accesskey="&helpAccel;">
|
||||
<menupopup>
|
||||
<menuitem onclick="openHelp" label="&contentsLabel;" accesskey="&contentsAccel;"/>
|
||||
<menuitem onclick="openReleaseNotes" label="&releaseNotesLabel;" accesskey="&releaseNotesAccel;"/>
|
||||
<menuitem onclick="openAbout" label="&aboutLabel;" accesskey="&aboutAccel;"/>
|
||||
</menupopup>
|
||||
</menu>
|
||||
|
||||
</menubar>
|
||||
|
||||
<toolbar>
|
||||
<toolbarbutton label="&toolbar.msgGetNewLabel;" onclick="msgGetNew" tooltiptext="&msgGetNewTooltip;" image="widgets/toolbar/mozilla/getmsg.png"/>
|
||||
<toolbarbutton label="&toolbar.msgNewLabel;" onclick="msgNew" tooltiptext="&msgNewTooltip;" image="widgets/toolbar/mozilla/newmsg.png"/>
|
||||
<toolbarbutton label="&toolbar.msgReplyLabel;" onclick="msgReply" tooltiptext="&msgReplyTooltip;" image="widgets/toolbar/mozilla/reply.png"/>
|
||||
<toolbarbutton label="&toolbar.msgReplyAllLabel;" onclick="msgReplyAll" tooltiptext="&msgReplyAllTooltip;" image="widgets/toolbar/mozilla/replyall.png"/>
|
||||
<toolbarbutton label="&toolbar.fwdInlineLabel;" onclick="fwdInline" tooltiptext="&fwdInlineTooltip;" image="widgets/toolbar/mozilla/forward.png"/>
|
||||
<toolbarbutton label="&toolbar.markAllReadLabel;" onclick="markAllRead" tooltiptext="&markAllReadTooltip;" image="widgets/toolbar/mozilla/readall.png"/>
|
||||
<toolbarbutton label="&toolbar.msgDeleteLabel;" tooltiptext="&msgDeleteTooltip;" image="widgets/toolbar/mozilla/delete.png"/>
|
||||
<toolbarbutton label="&toolbar.printLabel;" tooltiptext="&printTooltip;" image="widgets/toolbar/mozilla/print.png"/>
|
||||
<toolbarbutton label="&toolbar.stopLabel;" tooltiptext="&stopTooltip;" image="widgets/toolbar/mozilla/stop.png"/>
|
||||
</toolbar>
|
||||
|
||||
</window>
|
|
@ -1,128 +0,0 @@
|
|||
/*
|
||||
* AddressCardTreeTable.java
|
||||
*
|
||||
* Created on 08 October 2005, 17:26
|
||||
*
|
||||
* To change this template, choose Tools | Template Manager
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package grendel.ui.prefs2;
|
||||
|
||||
import grendel.prefs.Preferences;
|
||||
import grendel.prefs.xml.XMLPreferences;
|
||||
|
||||
import grendel.ui.PrefsDialog;
|
||||
import grendel.widgets.TreeTableModelListener;
|
||||
import javax.swing.event.TreeExpansionEvent;
|
||||
import javax.swing.event.TreeModelEvent;
|
||||
import javax.swing.tree.TreeNode;
|
||||
|
||||
import org.jdesktop.swing.treetable.DefaultTreeTableModel;
|
||||
import org.jdesktop.swing.treetable.TreeTableModel;
|
||||
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author hash9
|
||||
*/
|
||||
public class PrefsTreeTableModel extends DefaultTreeTableModel
|
||||
implements TreeTableModel {
|
||||
/**
|
||||
* Creates a new instance of PrefsTreeTableModel
|
||||
*/
|
||||
public PrefsTreeTableModel() {
|
||||
this(Preferences.getPreferances());
|
||||
}
|
||||
|
||||
public PrefsTreeTableModel(XMLPreferences prefs) {
|
||||
super(new PrefsTreeNode(null, "Preferences", prefs));
|
||||
}
|
||||
|
||||
public boolean isCellEditable(Object object, int i) {
|
||||
if (i == 2) {
|
||||
if (object instanceof PrefsObjectTreeNode) {
|
||||
PrefsObjectTreeNode on = (PrefsObjectTreeNode) object;
|
||||
|
||||
if (on.getValue() instanceof String) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (on.getValue() instanceof Integer) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getColumnCount() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
public String getColumnName(int i) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
return "key";
|
||||
|
||||
case 1:
|
||||
return "type";
|
||||
|
||||
case 2:
|
||||
return "value";
|
||||
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public void setValueAt(Object object, Object object0, int i) {
|
||||
PrefsObjectTreeNode cn = (PrefsObjectTreeNode) object0;
|
||||
PrefsTreeNode n = (PrefsTreeNode) cn.getParent();
|
||||
|
||||
if (cn.getValue() instanceof String) {
|
||||
n.getPrefs().setProperty((String) cn.getUserObject(), (String) object);
|
||||
nodeChanged(n,cn);
|
||||
} else if (cn.getValue() instanceof Integer) {
|
||||
n.getPrefs().setProperty((String) cn.getUserObject(),
|
||||
Integer.parseInt((String) object));
|
||||
nodeChanged(n,cn);
|
||||
}
|
||||
}
|
||||
|
||||
private void nodeChanged(PrefsTreeNode n,PrefsObjectTreeNode cn) {
|
||||
for (int i = 0; i < n.getChildCount(); i++) {
|
||||
TreeNode ncn = n.getChildAt(i);
|
||||
if (cn.equals(ncn)) {
|
||||
nodesChanged(n,new int[] {i});
|
||||
return;
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
public Object getValueAt(Object object, int i) {
|
||||
if (object instanceof PrefsObjectTreeNode) {
|
||||
PrefsObjectTreeNode n = (PrefsObjectTreeNode) object;
|
||||
Object value = n.getValue();
|
||||
|
||||
if (i == 1) {
|
||||
return value.getClass().getCanonicalName();
|
||||
} else if (i == 2) {
|
||||
return value.toString();
|
||||
}
|
||||
} else if (object instanceof PrefsTreeNode) {
|
||||
PrefsTreeNode n = (PrefsTreeNode) object;
|
||||
Object value = n.getPrefs();
|
||||
|
||||
if (i == 1) {
|
||||
return value.getClass().getCanonicalName();
|
||||
} else if (i == 2) {
|
||||
return "{count: "+n.getChildCount()+"}";
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче