# This patch file was generated by NetBeans IDE
# Following Index: paths are relative to: D:\Work\Java\Open_Source\xwiki-trunks\xwiki-platform-core\xwiki-core\src\main\java\com\xpn\xwiki
# This patch can be applied using context Tools: Patch action on respective folder.
# It uses platform neutral UTF-8 encoding and \n newlines.
# Above lines and this line are ignored by the patching process.
Index: XWiki.java
--- XWiki.java Base (BASE)
+++ XWiki.java Locally Modified (Based On LOCAL)
@@ -118,6 +118,7 @@
import com.xpn.xwiki.objects.meta.MetaClass;
import com.xpn.xwiki.plugin.XWikiPluginInterface;
import com.xpn.xwiki.plugin.XWikiPluginManager;
+import com.xpn.xwiki.plugin.mailsender.MailSenderPluginApi;
import com.xpn.xwiki.plugin.query.QueryPlugin;
import com.xpn.xwiki.plugin.query.XWikiCriteria;
import com.xpn.xwiki.plugin.query.XWikiQuery;
@@ -2688,13 +2689,24 @@
needsUpdate |= bclass.addTextAreaField("menu", "Menu", 60, 8);
needsUpdate |= bclass.addTextAreaField("meta", "HTTP Meta Info", 60, 8);
- needsUpdate |= bclass.addBooleanField("use_email_verification", "Use eMail Verification", "yesno");
- needsUpdate |= bclass.addTextField("smtp_server", "SMTP Server", 30);
- needsUpdate |= bclass.addTextField("admin_email", "Admin eMail", 30);
- needsUpdate |= bclass.addTextAreaField("validation_email_content", "Validation eMail Content", 72, 10);
- needsUpdate |= bclass.addTextAreaField("confirmation_email_content", "Confirmation eMail Content", 72, 10);
- needsUpdate |= bclass.addTextAreaField("invitation_email_content", "Invitation eMail Content", 72, 10);
+ // registration
+ needsUpdate |=
+ bclass.addBooleanField(XWikiPrefs.use_email_verification, "Use eMail Verification", "yesno");
+ needsUpdate |= bclass.addTextField(XWikiPrefs.validation_email_subject, "Validation eMail Subject", 72);
+ needsUpdate |= bclass.addTextAreaField(XWikiPrefs.validation_email_content, "Validation eMail Content", 72, 10);
+ needsUpdate |= bclass.addTextField(XWikiPrefs.confirmation_email_subject, "Confirmation eMail Subject", 72);
+ needsUpdate |= bclass.addTextAreaField(XWikiPrefs.confirmation_email_content, "Confirmation eMail Content", 72, 10);
+ needsUpdate |= bclass.addTextField(XWikiPrefs.invitation_email_subject, "Invitation eMail Subject", 72);
+ needsUpdate |= bclass.addTextAreaField(XWikiPrefs.invitation_email_content, "Invitation eMail Content", 72, 10);
+ // mail
+ needsUpdate |= bclass.addTextField(XWikiPrefs.admin_email, "Admin eMail", 30);
+ needsUpdate |= bclass.addTextField(XWikiPrefs.default_email_subject, "Default eMail Subject", 72);
+ needsUpdate |= bclass.addTextField(XWikiPrefs.smtp_server, "SMTP Server", 30);
+ needsUpdate |= bclass.addTextField(XWikiPrefs.smtp_server_username, "SMTP Server username (optional)", 30);
+ needsUpdate |= bclass.addTextField(XWikiPrefs.smtp_server_password, "SMTP Server password (optional)", 30);
+ needsUpdate |= bclass.addTextAreaField(XWikiPrefs.javamail_extra_props, "Additional JavaMail properties", 60, 6);
+
needsUpdate |= bclass.addTextField("macros_languages", "Macros Languages", 60);
needsUpdate |= bclass.addTextField("macros_velocity", "Macros for Velocity", 60);
needsUpdate |= bclass.addTextField("macros_groovy", "Macros for Groovy", 60);
@@ -2998,7 +3010,8 @@
saveDocument(docuser, context);
if (withConfirmEmail) {
- sendValidationEmail(xwikiname, password, email, validkey, "confirmation_email_content", context);
+ sendValidationEmail(xwikiname, password, email, validkey,
+ XWikiPrefs.confirmation_email_content, context);
}
return 0;
@@ -3070,7 +3083,8 @@
if ((result > 0) && (withValidation)) {
// Send the validation email
- sendValidationEmail(xwikiname, password, email, validkey, "validation_email_content", context);
+ sendValidationEmail(xwikiname, password, email, validkey,
+ XWikiPrefs.validation_email_content, context);
}
return result;
@@ -3119,15 +3133,25 @@
sendValidationEmail(xwikiname, password, email, "validkey", validkey, contentfield, context);
}
- public void sendValidationEmail(String xwikiname, String password, String email, String addfieldname,
- String addfieldvalue, String contentfield, XWikiContext context) throws XWikiException
+ // DEV NOTE: this is actually used both for validation and confirmation
+ public void sendValidationEmail(String xwikiname, String password,
+ String email, String addfieldname, String addfieldvalue,
+ String contentField, XWikiContext context)
+ throws XWikiException
{
String sender;
+ String subject;
String content;
+ // TODO - make it less hackish
+ // for now using unsupported contentField will just set subject to "",
+ // and it will be replaced later by a default subject.
+ String subjectField = contentField.replace("content", "subject");
+
try {
- sender = getXWikiPreference("admin_email", context);
- content = getXWikiPreference(contentfield, context);
+ sender = getXWikiPreference(XWikiPrefs.admin_email, context);
+ subject = getXWikiPreference(subjectField, "", context);
+ content = getXWikiPreference(contentField, context);
} catch (Exception e) {
throw new XWikiException(XWikiException.MODULE_XWIKI_EMAIL,
XWikiException.ERROR_XWIKI_EMAIL_CANNOT_GET_VALIDATION_CONFIG,
@@ -3142,6 +3166,7 @@
vcontext.put("password", password);
vcontext.put("sender", sender);
vcontext.put("xwikiname", xwikiname);
+ subject = parseContent(subject, context);
content = parseContent(content, context);
} catch (Exception e) {
throw new XWikiException(XWikiException.MODULE_XWIKI_EMAIL,
@@ -3151,7 +3176,7 @@
}
// Let's now send the message
- sendMessage(sender, email, content, context);
+ sendMessage(sender, email, subject, content, context);
}
/**
@@ -3162,6 +3187,72 @@
public void sendMessage(String sender, String[] recipient, String message, XWikiContext context)
throws XWikiException
{
+ String subject = getXWikiPreference("default_email_subject",
+ XWikiDefaults.default_email_subject, context);
+
+ sendMessage(sender, recipient, subject, message, context);
+ }
+
+ /**
+ * @deprecated replaced by the Mail Sender
+ * Plugin
+ */
+ public void sendMessage(String sender, String[] recipient, String subject,
+ String message, XWikiContext context) throws XWikiException
+ {
+ LOG.debug("Entering sendMessage(...)...");
+
+ // sanity check
+ if( subject == null || subject.trim().length() == 0 )
+ {
+ subject = getXWikiPreference("default_email_subject",
+ XWikiDefaults.default_email_subject, context);
+ }
+
+ MailSenderPluginApi mailSenderApi =
+ (MailSenderPluginApi)getPluginApi("mailsender", context);
+
+ /*
+ LOG.debug("mailSenderApi = " + mailSenderApi);
+
+ LOG.debug("sender = " + sender);
+ LOG.debug("recipient.length = " + recipient.length);
+ for(int i = 0; i < recipient.length; i++)
+ {
+ LOG.debug("recipient[" + i + "] = " + recipient[i]);
+ }
+ LOG.debug("subject = " + subject);
+ LOG.debug("message = " + message);
+ LOG.debug("context = " + context);
+ */
+
+ String recipientsAsString = recipient[0];
+ for(int i = 1; i < recipient.length; i++)
+ {
+ recipientsAsString = recipientsAsString + "," + recipient[i];
+ }
+
+
+ int result = mailSenderApi.sendTextMessage(sender, recipientsAsString,
+ subject, message);
+
+ // note: -1 is magic number for any error
+ if( result == -1 )
+ {
+ String errorString = (String)context.get("error");
+ XWikiException xwe =
+ new XWikiException(XWikiException.MODULE_XWIKI_EMAIL,
+ XWikiException.ERROR_XWIKI_EMAIL_ERROR_SENDING_EMAIL,
+ errorString);
+ LOG.error(xwe, xwe);
+ throw xwe;
+ }
+
+ LOG.debug("Exiting sendMessage(...). It seems everything went ok.");
+
+
+ /*
SMTPClient smtpc = null;
try {
String server = getXWikiPreference("smtp_server", context);
@@ -3226,6 +3317,7 @@
}
}
}
+ */
}
/**
@@ -3240,6 +3332,18 @@
sendMessage(sender, recip, message, context);
}
+ /**
+ * @deprecated replaced by the Mail Sender
+ * Plugin
+ */
+ @Deprecated
+ public void sendMessage(String sender, String recipient, String subject, String message, XWikiContext context)
+ throws XWikiException
+ {
+ String[] recip = recipient.split(",");
+ sendMessage(sender, recip, subject, message, context);
+ }
+
public String generateRandomString(int size)
{
return RandomStringUtils.randomAlphanumeric(size);
Index: XWikiDefaults.java
--- XWikiDefaults.java Locally New
+++ XWikiDefaults.java Locally New
@@ -0,0 +1,28 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package com.xpn.xwiki;
+
+
+public interface XWikiDefaults
+{
+
+ String default_email_subject = "XWiki message";
+
+}
Index: XWikiPrefs.java
--- XWikiPrefs.java Locally New
+++ XWikiPrefs.java Locally New
@@ -0,0 +1,41 @@
+/*
+ * See the NOTICE file distributed with this work for additional
+ * information regarding copyright ownership.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package com.xpn.xwiki;
+
+
+public interface XWikiPrefs
+{
+
+ String use_email_verification = "use_email_verification";
+ String validation_email_subject = "validation_email_subject";
+ String validation_email_content = "validation_email_content";
+ String confirmation_email_subject = "confirmation_email_subject";
+ String confirmation_email_content = "confirmation_email_content";
+ String invitation_email_subject = "invitation_email_subject";
+ String invitation_email_content = "invitation_email_content";
+
+ String admin_email = "admin_email";
+ String default_email_subject = "default_email_subject";
+ String smtp_server = "smtp_server";
+ String smtp_server_username = "smtp_server_username";
+ String smtp_server_password = "smtp_server_password";
+ String javamail_extra_props = "javamail_extra_props";
+
+}