1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-12-13 19:22:22 -05:00

Caldav: initial edit notification implementation

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1513 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-10-20 21:13:35 +00:00
parent 8df9595020
commit af6afe9042
5 changed files with 261 additions and 10 deletions

View File

@ -22,8 +22,10 @@ import davmail.BundleMessage;
import davmail.Settings; import davmail.Settings;
import davmail.exception.DavMailAuthenticationException; import davmail.exception.DavMailAuthenticationException;
import davmail.exception.DavMailException; import davmail.exception.DavMailException;
import davmail.exception.WebdavNotAvailableException;
import davmail.http.DavGatewayHttpClientFacade; import davmail.http.DavGatewayHttpClientFacade;
import davmail.http.DavGatewayOTPPrompt; import davmail.http.DavGatewayOTPPrompt;
import davmail.ui.NotificationDialog;
import davmail.util.StringUtil; import davmail.util.StringUtil;
import org.apache.commons.httpclient.*; import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.GetMethod; import org.apache.commons.httpclient.methods.GetMethod;
@ -191,6 +193,8 @@ public abstract class ExchangeSession {
BundleMessage message = new BundleMessage("EXCEPTION_CONNECT", exc.getClass().getName(), exc.getMessage()); BundleMessage message = new BundleMessage("EXCEPTION_CONNECT", exc.getClass().getName(), exc.getMessage());
ExchangeSession.LOGGER.error(message); ExchangeSession.LOGGER.error(message);
throw new DavMailException("EXCEPTION_DAVMAIL_CONFIGURATION", message); throw new DavMailException("EXCEPTION_DAVMAIL_CONFIGURATION", message);
} catch (WebdavNotAvailableException exc) {
throw exc;
} catch (IOException exc) { } catch (IOException exc) {
LOGGER.error(BundleMessage.formatLog("EXCEPTION_EXCHANGE_LOGIN_FAILED", exc)); LOGGER.error(BundleMessage.formatLog("EXCEPTION_EXCHANGE_LOGIN_FAILED", exc));
throw new DavMailException("EXCEPTION_EXCHANGE_LOGIN_FAILED", exc); throw new DavMailException("EXCEPTION_EXCHANGE_LOGIN_FAILED", exc);
@ -2206,22 +2210,37 @@ public abstract class ExchangeSession {
return null; return null;
} }
} else { } else {
// reset body
description = "";
String status = vCalendar.getAttendeeStatus(); String status = vCalendar.getAttendeeStatus();
if (status != null) { // notify only organizer
writer.writeHeader("Subject", BundleMessage.format(status) + vEventSubject); String to = recipients.organizer;
} else { String cc = null;
writer.writeHeader("Subject", subject); String notificationSubject = (status != null)?(BundleMessage.format(status) + vEventSubject):subject;
description = "";
// Allow end user notification edit
if (Settings.getBooleanProperty("davmail.caldavEditNotifications")) {
// create notification edit dialog
NotificationDialog notificationDialog = new NotificationDialog(recipients.organizer,
null, notificationSubject);
if (!notificationDialog.getSendNotification()) {
LOGGER.debug("Notification canceled by user");
return null;
}
// get description from dialog
to = notificationDialog.getTo();
cc = notificationDialog.getCc();
notificationSubject = notificationDialog.getSubject();
description = notificationDialog.getBody();
} }
// notify only organizer
writer.writeHeader("To", recipients.organizer);
// do not send notification if no recipients found // do not send notification if no recipients found
if (recipients.organizer == null) { if (to == null || to.length() == 0) {
return null; return null;
} }
writer.writeHeader("To", to);
writer.writeHeader("Cc", cc);
writer.writeHeader("Subject", notificationSubject);
} }
if (LOGGER.isDebugEnabled()) { if (LOGGER.isDebugEnabled()) {
StringBuilder logBuffer = new StringBuilder("Sending notification"); StringBuilder logBuffer = new StringBuilder("Sending notification");

View File

@ -0,0 +1,178 @@
/*
* DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
* Copyright (C) 2010 Mickael Guessant
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package davmail.ui;
import davmail.BundleMessage;
import davmail.ui.browser.DesktopBrowser;
import davmail.ui.tray.DavGatewayTray;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
* Edit Caldav scheduling notifications.
*/
public class NotificationDialog extends JDialog {
protected boolean sendNotification = false;
protected JTextField toField;
protected JTextField ccField;
protected JTextField subjectField;
protected JEditorPane bodyField;
protected void addRecipientComponent(JPanel panel, String label, JTextField textField, String toolTipText) {
JLabel fieldLabel = new JLabel(label);
fieldLabel.setHorizontalAlignment(SwingConstants.RIGHT);
fieldLabel.setVerticalAlignment(SwingConstants.CENTER);
textField.setMaximumSize(textField.getPreferredSize());
JPanel innerPanel = new JPanel();
innerPanel.setLayout(new BoxLayout(innerPanel, BoxLayout.X_AXIS));
innerPanel.setAlignmentX(Component.RIGHT_ALIGNMENT);
innerPanel.add(fieldLabel);
innerPanel.add(textField);
panel.add(innerPanel);
if (toolTipText != null) {
fieldLabel.setToolTipText(toolTipText);
textField.setToolTipText(toolTipText);
}
}
public NotificationDialog(String to, String cc, String subject) {
setModal(true);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
setTitle(BundleMessage.format("UI_CALDAV_NOTIFICATION"));
setIconImage(DavGatewayTray.getFrameIcon());
JPanel mainPanel = new JPanel();
// add help (F1 handler)
mainPanel.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke("F1"),
"help");
mainPanel.getActionMap().put("help", new AbstractAction() {
public void actionPerformed(ActionEvent e) {
DesktopBrowser.browse("http://davmail.sourceforge.net");
}
});
mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS));
mainPanel.add(getRecipientsPanel());
mainPanel.add(getBodyPanel());
JPanel recipientsPanel = getRecipientsPanel();
if (to != null) {
toField.setText(to);
}
if (cc != null) {
ccField.setText(cc);
}
if (subject != null) {
subjectField.setText(subject);
}
add(BorderLayout.NORTH, recipientsPanel);
JPanel bodyPanel = getBodyPanel();
add(BorderLayout.CENTER, bodyPanel);
bodyField.setPreferredSize(recipientsPanel.getPreferredSize());
JPanel buttonPanel = new JPanel();
JButton cancel = new JButton(BundleMessage.format("UI_BUTTON_CANCEL"));
JButton send = new JButton(BundleMessage.format("UI_BUTTON_SEND"));
send.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
sendNotification = true;
setVisible(false);
}
});
cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
// nothing to do, just hide
setVisible(false);
}
});
buttonPanel.add(send);
buttonPanel.add(cancel);
add(BorderLayout.SOUTH, buttonPanel);
pack();
setResizable(true);
// center frame
setLocation(getToolkit().getScreenSize().width / 2 -
getSize().width / 2,
getToolkit().getScreenSize().height / 2 -
getSize().height / 2);
bodyField.requestFocus();
setVisible(true);
}
protected JPanel getRecipientsPanel() {
JPanel recipientsPanel = new JPanel();
recipientsPanel.setLayout(new BoxLayout(recipientsPanel, BoxLayout.Y_AXIS));
recipientsPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
toField = new JTextField("", 40);
ccField = new JTextField("", 40);
subjectField = new JTextField("", 40);
addRecipientComponent(recipientsPanel, BundleMessage.format("UI_TO"), toField,
BundleMessage.format("UI_TO_HELP"));
addRecipientComponent(recipientsPanel, BundleMessage.format("UI_CC"), ccField,
BundleMessage.format("UI_CC"));
addRecipientComponent(recipientsPanel, BundleMessage.format("UI_SUBJECT"), subjectField,
BundleMessage.format("UI_SUBJECT_HELP"));
return recipientsPanel;
}
protected JPanel getBodyPanel() {
JPanel bodyPanel = new JPanel();
bodyPanel.setBorder(BorderFactory.createTitledBorder(BundleMessage.format("UI_NOTIFICATION_BODY")));
bodyField = new JEditorPane();
//HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
//bodyField.setEditorKit(htmlEditorKit);
//bodyField.setContentType("text/html");
bodyPanel.add(new JScrollPane(bodyField));
return bodyPanel;
}
public boolean getSendNotification() {
return sendNotification;
}
public String getTo() {
return toField.getText();
}
public String getCc() {
return ccField.getText();
}
public String getSubject() {
return subjectField.getText();
}
public String getBody() {
return bodyField.getText();
}
}

View File

@ -262,3 +262,12 @@ TENTATIVE=Tentative:
DECLINED=Declined: DECLINED=Declined:
UI_ENABLE_EWS=Enable EWS UI_ENABLE_EWS=Enable EWS
UI_ENABLE_EWS_HELP=Enable EWS mode on Exchange 2010 or Exchange 2007 with Webdav disabled UI_ENABLE_EWS_HELP=Enable EWS mode on Exchange 2010 or Exchange 2007 with Webdav disabled
UI_CALDAV_NOTIFICATION=DavMail: Caldav scheduling notification
UI_BUTTON_SEND=Send
UI_TO=To:
UI_TO_HELP=Recipients
UI_CC=Cc:
UI_CC_HELP=Copy recipients
UI_SUBJECT=Subject:
UI_SUBJECT_HELP=Caldav notification subject
UI_NOTIFICATION_BODY=Caldav notification comment

View File

@ -261,3 +261,12 @@ TENTATIVE=Provisoire :
DECLINED=Refusé : DECLINED=Refusé :
UI_ENABLE_EWS=Activer EWS UI_ENABLE_EWS=Activer EWS
UI_ENABLE_EWS_HELP=Activer le mode EWS sur Exchange 2010 ou Exchange 2007 sans support Webdav UI_ENABLE_EWS_HELP=Activer le mode EWS sur Exchange 2010 ou Exchange 2007 sans support Webdav
UI_CALDAV_NOTIFICATION=DavMail : Notification Caldav
UI_BUTTON_SEND=Envoyer
UI_SUBJECT=Sujet :
UI_SUBJECT_HELP=Sujet notification Caldav
UI_TO=Pour :
UI_TO_HELP=Destinataires
UI_NOTIFICATION_BODY=Commentaire notification Caldav
UI_CC=Copie à :
UI_CC_HELP=Destinataires en copie

View File

@ -0,0 +1,36 @@
/*
* DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
* Copyright (C) 2010 Mickael Guessant
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package davmail.ui;
import junit.framework.TestCase;
import javax.swing.*;
import java.io.IOException;
/**
* Test Notification Frame
*/
public class TestNotificationDialog extends TestCase {
public void testCreateNotificationFrame() throws IOException, ClassNotFoundException, UnsupportedLookAndFeelException, IllegalAccessException, InstantiationException {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
NotificationDialog notificationDialog = new NotificationDialog("to", "cc", "subject");
notificationDialog.setVisible(true);
System.out.println(notificationDialog.getSendNotification());
}
}