1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-08-13 16:53:51 -04:00

Reformat and fixes from audit

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1702 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2011-06-08 19:58:29 +00:00
parent 551c608812
commit f89511775d
57 changed files with 277 additions and 92 deletions

View File

@ -20,11 +20,11 @@ package davmail;
import davmail.exception.DavMailException;
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Locale;
import java.util.ResourceBundle;
import java.io.Serializable;
/**
* Internationalization message.

View File

@ -77,7 +77,7 @@ public class DoubleDotInputStream extends PushbackInputStream {
}
// push back characters
if (index >= 0) {
while(index >= 0) {
while (index >= 0) {
unread(buffer[index--]);
}
}

View File

@ -31,7 +31,7 @@ import java.io.OutputStream;
public class DoubleDotOutputStream extends FilterOutputStream {
// remember last 2 bytes written
int[] buf = {0, 0};
final int[] buf = {0, 0};
/**
* @inheritDoc

View File

@ -658,7 +658,7 @@ public abstract class ExchangeSession {
public abstract void deleteMessage(Message message) throws IOException;
/**
* Send message to recipients, properties contains bcc recipients and other non MIME flags.
* Send message.
*
* @param messageBody MIME message body
* @throws IOException on error
@ -1435,7 +1435,7 @@ public abstract class ExchangeSession {
messages = ExchangeSession.this.searchMessages(folderPath, null);
fixUids(messages);
recent = 0;
for (Message message:messages) {
for (Message message : messages) {
if (message.recent) {
recent++;
}

View File

@ -95,6 +95,15 @@ public final class ExchangeSessionFactory {
}
}
/**
* Create authenticated Exchange session
*
* @param baseUrl OWA base URL
* @param userName user login
* @param password user password
* @return authenticated session
* @throws IOException on error
*/
public static ExchangeSession getInstance(String baseUrl, String userName, String password) throws IOException {
ExchangeSession session = null;
try {
@ -129,7 +138,7 @@ public final class ExchangeSessionFactory {
try {
session = new DavExchangeSession(poolKey.url, poolKey.userName, poolKey.password);
} catch (WebdavNotAvailableException e) {
ExchangeSession.LOGGER.debug(e.getMessage()+", retry with EWS");
ExchangeSession.LOGGER.debug(e.getMessage() + ", retry with EWS");
session = new EwsExchangeSession(poolKey.url, poolKey.userName, poolKey.password);
// success, enable EWS flag
ExchangeSession.LOGGER.debug("EWS found, changing davmail.enableEws setting");

View File

@ -19,8 +19,8 @@
package davmail.exchange;
import java.io.BufferedReader;
import java.io.Reader;
import java.io.IOException;
import java.io.Reader;
/**
* ICS Buffered Reader.
@ -32,6 +32,7 @@ public class ICSBufferedReader extends BufferedReader {
/**
* Create an ICS reader on the provided reader
*
* @param in input reader
* @throws IOException on error
*/

View File

@ -19,10 +19,13 @@
package davmail.exchange;
import javax.mail.internet.MimeUtility;
import java.io.*;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.text.SimpleDateFormat;
/**
* Mime OutputStreamWriter to build in memory Mime message.

View File

@ -26,6 +26,7 @@ import davmail.exception.DavMailException;
public class NetworkDownException extends DavMailException {
/**
* Build a network down exception with the provided BundleMessage key.
*
* @param key message key
*/
public NetworkDownException(String key) {
@ -34,6 +35,7 @@ public class NetworkDownException extends DavMailException {
/**
* Build a network down exception with the provided BundleMessage key.
*
* @param key message key
* @param message detailed message
*/

View File

@ -108,6 +108,11 @@ public class VCalendar extends VObject {
return "TRUE".equals(vObject.getPropertyValue("X-MICROSOFT-CDO-ALLDAYEVENT"));
}
/**
* Check if vCalendar is CDO allday.
*
* @return true if vCalendar has X-MICROSOFT-CDO-ALLDAYEVENT property set to TRUE
*/
public boolean isCdoAllDay() {
return firstVevent != null && isCdoAllDay(firstVevent);
}
@ -147,7 +152,7 @@ public class VCalendar extends VObject {
String tzid = null;
if (fromServer) {
// get current tzid
VObject vObject = getVTimezone();
VObject vObject = vTimezone;
if (vObject != null) {
String currentTzid = vObject.getPropertyValue("TZID");
// fix TZID with \n (Exchange 2010 bug)
@ -460,10 +465,14 @@ public class VCalendar extends VObject {
}
}
/**
* Remove VAlarm from VCalendar.
*/
public void removeVAlarm() {
if (vObjects != null) {
for (VObject vObject : vObjects) {
if ("VEVENT".equals(vObject.type)) {
// As VALARM is the only possible inner object, just drop all objects
if (vObject.vObjects != null) {
vObject.vObjects = null;
}
@ -472,6 +481,11 @@ public class VCalendar extends VObject {
}
}
/**
* Check if VCalendar has a VALARM item.
*
* @return true if VCalendar has a VALARM
*/
public boolean hasVAlarm() {
if (vObjects != null) {
for (VObject vObject : vObjects) {
@ -485,18 +499,39 @@ public class VCalendar extends VObject {
return false;
}
/**
* Check if this VCalendar is a meeting.
*
* @return true if this VCalendar has attendees
*/
public boolean isMeeting() {
return getFirstVeventProperty("ATTENDEE") != null;
}
/**
* Check if current user is meeting organizer.
*
* @return true it user email matched organizer email
*/
public boolean isMeetingOrganizer() {
return email.equals(getEmailValue(getFirstVeventProperty("ORGANIZER")));
return email.equalsIgnoreCase(getEmailValue(getFirstVeventProperty("ORGANIZER")));
}
/**
* Set property value on first VEVENT.
*
* @param propertyName property name
* @param propertyValue property value
*/
public void setFirstVeventPropertyValue(String propertyName, String propertyValue) {
firstVevent.setPropertyValue(propertyName, propertyValue);
}
/**
* Add property on first VEVENT.
*
* @param vProperty property object
*/
public void addFirstVeventProperty(VProperty vProperty) {
firstVevent.addProperty(vProperty);
}
@ -505,8 +540,19 @@ public class VCalendar extends VObject {
* VCalendar recipients for notifications
*/
public static class Recipients {
/**
* attendee list
*/
public String attendees;
/**
* optional attendee list
*/
public String optionalAttendees;
/**
* vCalendar organizer
*/
public String organizer;
}
@ -573,10 +619,15 @@ public class VCalendar extends VObject {
return status;
}
/**
* Get recurring VCalendar occurence exceptions.
*
* @return event occurences
*/
public List<VObject> getModifiedOccurrences() {
boolean first = true;
ArrayList<VObject> results = new ArrayList<VObject>();
for (VObject vObject:vObjects) {
for (VObject vObject : vObjects) {
if ("VEVENT".equals(vObject.type)) {
if (first) {
first = false;

View File

@ -84,6 +84,9 @@ public class VObject {
this(new ICSBufferedReader(new StringReader(itemBody)));
}
/**
* Create empty VCalendar object;
*/
public VObject() {
}
@ -101,6 +104,11 @@ public class VObject {
}
}
/**
* Add vObject.
*
* @param vObject inner object
*/
public void addVObject(VObject vObject) {
if (vObjects == null) {
vObjects = new ArrayList<VObject>();
@ -108,6 +116,11 @@ public class VObject {
vObjects.add(vObject);
}
/**
* Add vProperty.
*
* @param property vProperty
*/
public void addProperty(VProperty property) {
if (property.getValue() != null) {
if (properties == null) {
@ -154,6 +167,12 @@ public class VObject {
return properties;
}
/**
* Get vProperty by name.
*
* @param name property name
* @return property object
*/
public VProperty getProperty(String name) {
if (properties != null) {
for (VProperty property : properties) {
@ -166,6 +185,12 @@ public class VObject {
return null;
}
/**
* Get multivalued vProperty by name.
*
* @param name property name
* @return property list
*/
public List<VProperty> getProperties(String name) {
List<VProperty> result = null;
if (properties != null) {
@ -182,6 +207,12 @@ public class VObject {
return result;
}
/**
* Get vProperty value by name.
*
* @param name property name
* @return property value
*/
public String getPropertyValue(String name) {
VProperty property = getProperty(name);
if (property != null) {
@ -191,6 +222,12 @@ public class VObject {
}
}
/**
* Set vProperty value on vObject, remove property if value is null.
*
* @param name property name
* @param value property value
*/
public void setPropertyValue(String name, String value) {
if (value == null) {
removeProperty(name);
@ -205,6 +242,12 @@ public class VObject {
}
}
/**
* Add vProperty value on vObject.
*
* @param name property name
* @param value property value
*/
public void addPropertyValue(String name, String value) {
if (value != null) {
VProperty property = new VProperty(name, value);
@ -212,6 +255,11 @@ public class VObject {
}
}
/**
* Remove vProperty from vObject.
*
* @param name property name
*/
public void removeProperty(String name) {
if (properties != null) {
VProperty property = getProperty(name);
@ -221,6 +269,11 @@ public class VObject {
}
}
/**
* Remove vProperty object from vObject.
*
* @param property object
*/
public void removeProperty(VProperty property) {
if (properties != null) {
properties.remove(property);

View File

@ -234,6 +234,12 @@ public class VProperty {
addParam(paramName, (String) null);
}
/**
* Set param value on property.
*
* @param paramName param name
* @param paramValue param value
*/
public void setParam(String paramName, String paramValue) {
Param currentParam = getParam(paramName);
if (currentParam != null) {
@ -242,6 +248,12 @@ public class VProperty {
addParam(paramName, paramValue);
}
/**
* Add param value on property.
*
* @param paramName param name
* @param paramValue param value
*/
public void addParam(String paramName, String paramValue) {
List<String> paramValues = new ArrayList<String>();
paramValues.add(paramValue);

View File

@ -35,7 +35,7 @@ import java.util.Map;
* XmlStreamReader utility methods
*/
public final class XMLStreamUtil {
protected static final Logger LOGGER = Logger.getLogger(XMLStreamUtil.class);
private static final Logger LOGGER = Logger.getLogger(XMLStreamUtil.class);
private XMLStreamUtil() {
}
@ -167,6 +167,12 @@ public final class XMLStreamUtil {
return xmlInputFactory.createXMLStreamReader(inputStream);
}
/**
* Get element text.
*
* @param reader stream reader
* @return element text
*/
public static String getElementText(XMLStreamReader reader) {
String value = null;
try {

View File

@ -2577,7 +2577,8 @@ public class DavExchangeSession extends ExchangeSession {
int totalCount;
int lastLogCount;
public int read(byte buffer[], int offset, int length) throws IOException {
@Override
public int read(byte[] buffer, int offset, int length) throws IOException {
int count = super.read(buffer, offset, length);
totalCount += count;
if (totalCount - lastLogCount > 1024 * 1024) {

View File

@ -199,7 +199,6 @@ public class Field {
createField(URN_SCHEMAS_CALENDAR, "timezone"); // DistinguishedPropertySetType.PublicStrings/urn:schemas:calendar:timezone/String
createField(SCHEMAS_EXCHANGE, "sensitivity"); // PR_SENSITIVITY 0x0036 Integer
createField(URN_SCHEMAS_CALENDAR, "timezoneid"); // DistinguishedPropertySetType.PublicStrings/urn:schemas:calendar:timezoneid/Integer
// should use PidLidServerProcessed ?

View File

@ -21,7 +21,7 @@ package davmail.exchange.ews;
/**
* Item update conflict resolution
*/
@SuppressWarnings({"JavaDoc"})
@SuppressWarnings({"JavaDoc", "UnusedDeclaration"})
public final class ConflictResolution extends AttributeOption {
private ConflictResolution(String value) {
super("ConflictResolution", value);

View File

@ -21,7 +21,7 @@ package davmail.exchange.ews;
/**
* DeleteItem disposal type.
*/
@SuppressWarnings({"JavaDoc"})
@SuppressWarnings({"JavaDoc", "UnusedDeclaration"})
public class DeleteType extends AttributeOption {
private DeleteType(String value) {
super("DeleteType", value);

View File

@ -21,7 +21,7 @@ package davmail.exchange.ews;
/**
* Disposal.
*/
@SuppressWarnings({"JavaDoc"})
@SuppressWarnings({"JavaDoc", "UnusedDeclaration"})
public final class Disposal extends AttributeOption {
private Disposal(String value) {
super("DeleteType", value);

View File

@ -43,7 +43,7 @@ public final class DistinguishedFolderId extends FolderId {
publicfoldersroot, root, junkemail, searchfolders, voicemail
}
protected static final Map<Name, DistinguishedFolderId> folderIdMap = new HashMap<Name, DistinguishedFolderId>();
private static final Map<Name, DistinguishedFolderId> folderIdMap = new HashMap<Name, DistinguishedFolderId>();
static {
for (Name name : Name.values()) {

View File

@ -447,6 +447,9 @@ public abstract class EWSMethod extends PostMethod {
* Recurring event occurrence
*/
public static class Occurrence {
/**
* Original occurence start date
*/
public String originalStart;
}
@ -625,7 +628,7 @@ public abstract class EWSMethod extends PostMethod {
/**
* Add occurrence.
*
* @param attendee attendee object
* @param occurrence event occurence
*/
public void addOccurrence(Occurrence occurrence) {
if (occurrences == null) {
@ -634,6 +637,11 @@ public abstract class EWSMethod extends PostMethod {
occurrences.add(occurrence);
}
/**
* Get occurences.
*
* @return event occurences
*/
public List<Occurrence> getOccurrences() {
return occurrences;
}

View File

@ -25,7 +25,7 @@ import java.util.Map;
* EWS MAPI fields;
*/
public final class Field {
protected static final Map<String, FieldURI> FIELD_MAP = new HashMap<String, FieldURI>();
private static final Map<String, FieldURI> FIELD_MAP = new HashMap<String, FieldURI>();
private Field() {
}

View File

@ -32,7 +32,6 @@ public class GetUserConfigurationMethod extends EWSMethod {
/**
* Get User Configuration method.
*
*/
public GetUserConfigurationMethod() {
super("UserConfiguration", "GetUserConfiguration");

View File

@ -34,6 +34,8 @@ public class IndexedFieldURI implements FieldURI {
*
* @param fieldURI base field uri
* @param fieldIndex field name
* @param fieldItemType field item type
* @param collectionName collection name
*/
public IndexedFieldURI(String fieldURI, String fieldIndex, String fieldItemType, String collectionName) {
this.fieldURI = fieldURI;

View File

@ -229,9 +229,8 @@ public final class DavGatewayHttpClientFacade {
* @param httpClient httpClient instance
* @param url url string
* @return HttpStatus code
* @throws IOException on error
*/
public static int getHttpStatus(HttpClient httpClient, String url) throws IOException {
public static int getHttpStatus(HttpClient httpClient, String url) {
int status = 0;
HttpMethod testMethod = new GetMethod(url);
testMethod.setDoAuthentication(false);

View File

@ -30,6 +30,7 @@ public final class DavGatewayOTPPrompt {
/**
* Ask user token password
*
* @return user provided one time password
*/
public static String getOneTimePassword() {

View File

@ -18,23 +18,23 @@
*/
package davmail.http;
import davmail.Settings;
import davmail.BundleMessage;
import davmail.ui.tray.DavGatewayTray;
import davmail.Settings;
import davmail.ui.AcceptCertificateDialog;
import davmail.ui.tray.DavGatewayTray;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
import java.awt.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.security.*;
import java.security.cert.CertificateEncodingException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.text.SimpleDateFormat;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
/**
* Custom Trust Manager, let user accept or deny.

View File

@ -20,9 +20,9 @@ package davmail.http;
import sun.security.pkcs11.SunPKCS11;
import java.io.ByteArrayInputStream;
import java.security.Provider;
import java.security.Security;
import java.io.ByteArrayInputStream;
/**
* Add the SunPKCS11 Provider.

View File

@ -622,6 +622,7 @@ public class ImapConnection extends AbstractConnection {
/**
* Detect infinite loop on the client side.
*
* @param line IMAP command line
* @throws IOException on infinite loop
*/
@ -637,7 +638,7 @@ public class ImapConnection extends AbstractConnection {
lastCommandCount++;
if (lastCommandCount > 100 && !"NOOP".equalsIgnoreCase(lastCommand)) {
// more than a hundred times the same command => this is a client infinite loop, close connection
throw new IOException("Infinite loop on command "+command+" detected");
throw new IOException("Infinite loop on command " + command + " detected");
}
} else {
// new command, reset

View File

@ -487,7 +487,7 @@ public class LdapConnection extends AbstractConnection {
} finally {
// cancel all search threads
synchronized (searchThreadMap) {
for (SearchRunnable searchRunnable:searchThreadMap.values()) {
for (SearchRunnable searchRunnable : searchThreadMap.values()) {
searchRunnable.abandon();
}
}

View File

@ -93,7 +93,7 @@ public class PopConnection extends AbstractConnection {
try {
ExchangeSessionFactory.checkConfig();
sendOK("DavMail "+ DavGateway.getCurrentVersion()+" POP ready at " + new Date());
sendOK("DavMail " + DavGateway.getCurrentVersion() + " POP ready at " + new Date());
for (; ;) {
line = readClient();

View File

@ -37,6 +37,7 @@ public class PopServer extends AbstractServer {
/**
* Create a ServerSocket to listen for connections.
* Start the thread.
*
* @param port pop listen port, 110 if not defined (0)
*/
public PopServer(int port) {

View File

@ -62,7 +62,7 @@ public class SmtpConnection extends AbstractConnection {
try {
ExchangeSessionFactory.checkConfig();
sendClient("220 DavMail "+ DavGateway.getCurrentVersion()+" SMTP ready at " + new Date());
sendClient("220 DavMail " + DavGateway.getCurrentVersion() + " SMTP ready at " + new Date());
for (; ;) {
line = readClient();
// unable to read line, connection closed ?

View File

@ -36,6 +36,7 @@ public class SmtpServer extends AbstractServer {
/**
* Create a ServerSocket to listen for connections.
* Start the thread.
*
* @param port smtp port
*/
public SmtpServer(int port) {

View File

@ -18,10 +18,10 @@
*/
package davmail.ui;
import davmail.DavGateway;
import davmail.BundleMessage;
import davmail.ui.tray.DavGatewayTray;
import davmail.DavGateway;
import davmail.ui.browser.DesktopBrowser;
import davmail.ui.tray.DavGatewayTray;
import javax.imageio.ImageIO;
import javax.swing.*;

View File

@ -18,9 +18,9 @@
*/
package davmail.ui;
import davmail.BundleMessage;
import davmail.http.DavGatewayX509TrustManager;
import davmail.ui.tray.DavGatewayTray;
import davmail.BundleMessage;
import javax.swing.*;
import java.awt.*;

View File

@ -32,7 +32,7 @@ import java.awt.event.ActionListener;
*/
public class NotificationDialog extends JDialog {
protected boolean sendNotification = false;
protected boolean sendNotification;
protected JTextField toField;
protected JTextField ccField;
@ -56,6 +56,13 @@ public class NotificationDialog extends JDialog {
}
}
/**
* Notification dialog to let user edit message body or cancel notification.
*
* @param to main recipients
* @param cc copy recipients
* @param subject notification subject
*/
public NotificationDialog(String to, String cc, String subject) {
setModal(true);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
@ -157,22 +164,47 @@ public class NotificationDialog extends JDialog {
return bodyPanel;
}
/**
* Cancel notification flag.
*
* @return false if user chose to cancel notification
*/
public boolean getSendNotification() {
return sendNotification;
}
/**
* Get edited recipients.
*
* @return recipients string
*/
public String getTo() {
return toField.getText();
}
/**
* Get edited copy recipients.
*
* @return copy recipients string
*/
public String getCc() {
return ccField.getText();
}
/**
* Get edited subject.
*
* @return subject
*/
public String getSubject() {
return subjectField.getText();
}
/**
* Get edited body.
*
* @return edited notification body
*/
public String getBody() {
return bodyField.getText();
}

View File

@ -18,7 +18,10 @@
*/
package davmail.ui;
import java.lang.reflect.*;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
/**
* Reflection based MacOS handler
@ -195,6 +198,7 @@ public class OSXAdapter implements InvocationHandler {
//
//
/**
* Compare the method that was called to the intended method when the OSXAdapter instance was created
* (e.g. handleAbout, handleQuit, handleOpenFile, etc.).

View File

@ -18,9 +18,9 @@
*/
package davmail.ui.browser;
import java.awt.*;
import java.io.IOException;
import java.net.URI;
import java.awt.*;
/**
* Wrapper class to call Java6 Desktop class to launch default browser.

View File

@ -18,9 +18,9 @@
*/
package davmail.ui.browser;
import davmail.ui.tray.DavGatewayTray;
import davmail.ui.AboutFrame;
import davmail.BundleMessage;
import davmail.ui.AboutFrame;
import davmail.ui.tray.DavGatewayTray;
import java.net.URI;
import java.net.URISyntaxException;

View File

@ -36,6 +36,6 @@ public final class OSXDesktopBrowser {
* @throws IOException on error
*/
public static void browse(URI location) throws IOException {
Runtime.getRuntime().exec("open "+location.toString());
Runtime.getRuntime().exec("open " + location.toString());
}
}

View File

@ -18,13 +18,13 @@
*/
package davmail.ui.tray;
import davmail.Settings;
import davmail.BundleMessage;
import davmail.DavGateway;
import davmail.Settings;
import davmail.ui.AboutFrame;
import davmail.ui.SettingsFrame;
import org.apache.log4j.Logger;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.lf5.LF5Appender;
import org.apache.log4j.lf5.LogLevel;
import org.apache.log4j.lf5.viewer.LogBrokerMonitor;

View File

@ -18,11 +18,11 @@
*/
package davmail.ui.tray;
import davmail.Settings;
import davmail.BundleMessage;
import davmail.Settings;
import davmail.exchange.NetworkDownException;
import org.apache.log4j.Logger;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import javax.imageio.ImageIO;
import java.awt.*;

View File

@ -18,13 +18,13 @@
*/
package davmail.ui.tray;
import davmail.Settings;
import davmail.BundleMessage;
import davmail.DavGateway;
import davmail.Settings;
import davmail.ui.AboutFrame;
import davmail.ui.SettingsFrame;
import org.apache.log4j.Logger;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.lf5.LF5Appender;
import org.apache.log4j.lf5.LogLevel;
import org.apache.log4j.lf5.viewer.LogBrokerMonitor;

View File

@ -18,9 +18,9 @@
*/
package davmail.ui.tray;
import davmail.ui.OSXAdapter;
import davmail.BundleMessage;
import davmail.DavGateway;
import davmail.ui.OSXAdapter;
import javax.swing.*;
import java.awt.event.ActionEvent;

View File

@ -18,15 +18,15 @@
*/
package davmail.web;
import davmail.Settings;
import davmail.DavGateway;
import davmail.BundleMessage;
import davmail.DavGateway;
import davmail.Settings;
import davmail.ui.tray.DavGatewayTray;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletContextEvent;
import java.io.InputStream;
import javax.servlet.ServletContextListener;
import java.io.IOException;
import java.io.InputStream;
/**
* Context Listener to start/stop DavMail