Skip to content
Snippets Groups Projects
Commit 2d9fc442 authored by Thomas Mortagne's avatar Thomas Mortagne
Browse files

XWIKI-22312: The old mailsender plugin is using the standard Java temporary directory

(cherry picked from commit a866bea6)
parent d7ccaa4f
No related branches found
No related tags found
No related merge requests found
......@@ -27,6 +27,7 @@
import java.io.StringReader;
import java.io.StringWriter;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
......@@ -59,6 +60,7 @@
import org.apache.velocity.context.Context;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xwiki.environment.Environment;
import org.xwiki.localization.LocaleUtils;
import org.xwiki.logging.LoggerConfiguration;
import org.xwiki.velocity.VelocityManager;
......@@ -125,6 +127,8 @@ public class MailSenderPlugin extends XWikiDefaultPlugin
/** The name of the header that specifies the sender of the mail. */
private static final String FROM = "From";
private final Environment environment = Utils.getComponent((Type) Environment.class);
/**
* Default plugin constructor.
*
......@@ -271,7 +275,7 @@ public MimeBodyPart createAttachmentBodyPart(Attachment attachment, XWikiContext
{
String name = attachment.getFilename();
byte[] stream = attachment.getContent();
File temp = new TemporaryFile(File.createTempFile("tmpfile", ".tmp"));
File temp = new TemporaryFile(File.createTempFile("tmpfile", ".tmp", this.environment.getTemporaryDirectory()));
FileOutputStream fos = new FileOutputStream(temp);
fos.write(stream);
fos.close();
......
......@@ -23,6 +23,15 @@
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.xwiki.component.manager.ComponentLookupException;
import org.xwiki.component.manager.ComponentManager;
import org.xwiki.environment.Environment;
import org.xwiki.test.TestEnvironment;
import com.xpn.xwiki.web.Utils;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* Unit tests for the {@link MailSenderPlugin mailsender plugin}.
......@@ -38,8 +47,13 @@ public class MailSenderPluginTest
private static MailSenderPlugin plugin;
@BeforeClass
public static void setUpPlugin()
public static void setUpPlugin() throws ComponentLookupException
{
ComponentManager componentManager = mock(ComponentManager.class);
when(componentManager.getInstance(ComponentManager.class, "context")).thenReturn(componentManager);
when(componentManager.getInstance(Environment.class)).thenReturn(new TestEnvironment());
Utils.setComponentManager(componentManager);
plugin = new MailSenderPlugin("mail", MailSenderPlugin.class.getCanonicalName(), null);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment