IDEMPIERE-82 Modify filename of attachment send by emails
This commit is contained in:
parent
e3ae21da2b
commit
f221ba73f1
|
@ -23,6 +23,8 @@ import java.io.FileReader;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Calendar;
|
||||||
|
|
||||||
import org.compiere.util.Util;
|
import org.compiere.util.Util;
|
||||||
|
|
||||||
|
@ -418,4 +420,15 @@ public class FileUtil
|
||||||
new FileUtil(directory, filter, action, from, to);
|
new FileUtil(directory, filter, action, from, to);
|
||||||
} // main
|
} // main
|
||||||
|
|
||||||
|
public static String getTempMailName(String subject, String extension) {
|
||||||
|
Calendar cal = Calendar.getInstance();
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||||
|
String dt = sdf.format(cal.getTime());
|
||||||
|
String cleanName = subject.replaceAll("[ &/]", "");
|
||||||
|
String localFile = System.getProperty("java.io.tmpdir")
|
||||||
|
+ System.getProperty("file.separator") + cleanName + "_" + dt
|
||||||
|
+ extension;
|
||||||
|
return localFile;
|
||||||
|
}
|
||||||
|
|
||||||
} // FileUtil
|
} // FileUtil
|
||||||
|
|
|
@ -24,6 +24,7 @@ import net.sf.jasperreports.view.JRViewer;
|
||||||
|
|
||||||
import org.compiere.apps.EMailDialog;
|
import org.compiere.apps.EMailDialog;
|
||||||
import org.compiere.model.MUser;
|
import org.compiere.model.MUser;
|
||||||
|
import org.compiere.tools.FileUtil;
|
||||||
import org.compiere.util.CLogger;
|
import org.compiere.util.CLogger;
|
||||||
import org.compiere.util.Env;
|
import org.compiere.util.Env;
|
||||||
import org.compiere.util.Msg;
|
import org.compiere.util.Msg;
|
||||||
|
@ -136,7 +137,7 @@ class SendByEmailListener implements ActionListener {
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
attachment = File.createTempFile("mail", ".pdf");
|
attachment = new File(FileUtil.getTempMailName(subject, ".pdf"));
|
||||||
JasperExportManager.exportReportToPdfFile(viewer.getJasperPrint(), attachment.getAbsolutePath());
|
JasperExportManager.exportReportToPdfFile(viewer.getJasperPrint(), attachment.getAbsolutePath());
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
package org.compiere.print;
|
package org.compiere.print;
|
||||||
|
|
||||||
|
import static org.compiere.model.SystemIDs.WINDOW_PRINTFORMAT;
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Cursor;
|
import java.awt.Cursor;
|
||||||
|
@ -39,6 +41,7 @@ import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
@ -80,7 +83,6 @@ import org.compiere.model.MQuery;
|
||||||
import org.compiere.model.MRole;
|
import org.compiere.model.MRole;
|
||||||
import org.compiere.model.MUser;
|
import org.compiere.model.MUser;
|
||||||
import org.compiere.model.PrintInfo;
|
import org.compiere.model.PrintInfo;
|
||||||
import static org.compiere.model.SystemIDs.*;
|
|
||||||
import org.compiere.model.X_C_Invoice;
|
import org.compiere.model.X_C_Invoice;
|
||||||
import org.compiere.swing.CButton;
|
import org.compiere.swing.CButton;
|
||||||
import org.compiere.swing.CCheckBox;
|
import org.compiere.swing.CCheckBox;
|
||||||
|
@ -89,6 +91,7 @@ import org.compiere.swing.CFrame;
|
||||||
import org.compiere.swing.CLabel;
|
import org.compiere.swing.CLabel;
|
||||||
import org.compiere.swing.CMenuItem;
|
import org.compiere.swing.CMenuItem;
|
||||||
import org.compiere.swing.CPanel;
|
import org.compiere.swing.CPanel;
|
||||||
|
import org.compiere.tools.FileUtil;
|
||||||
import org.compiere.util.CLogMgt;
|
import org.compiere.util.CLogMgt;
|
||||||
import org.compiere.util.CLogger;
|
import org.compiere.util.CLogger;
|
||||||
import org.compiere.util.DB;
|
import org.compiere.util.DB;
|
||||||
|
@ -99,6 +102,7 @@ import org.compiere.util.Language;
|
||||||
import org.compiere.util.Login;
|
import org.compiere.util.Login;
|
||||||
import org.compiere.util.Msg;
|
import org.compiere.util.Msg;
|
||||||
import org.compiere.util.NamePair;
|
import org.compiere.util.NamePair;
|
||||||
|
import org.compiere.util.TimeUtil;
|
||||||
import org.compiere.util.ValueNamePair;
|
import org.compiere.util.ValueNamePair;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -911,7 +915,7 @@ public class Viewer extends CFrame
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
attachment = File.createTempFile("mail", ".pdf");
|
attachment = new File(FileUtil.getTempMailName(subject, ".pdf"));
|
||||||
m_reportEngine.getPDF(attachment);
|
m_reportEngine.getPDF(attachment);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
package org.adempiere.webui.window;
|
package org.adempiere.webui.window;
|
||||||
|
|
||||||
|
import static org.compiere.model.SystemIDs.WINDOW_PRINTFORMAT;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
@ -57,10 +59,10 @@ import org.compiere.model.MRole;
|
||||||
import org.compiere.model.MSysConfig;
|
import org.compiere.model.MSysConfig;
|
||||||
import org.compiere.model.MTable;
|
import org.compiere.model.MTable;
|
||||||
import org.compiere.model.MUser;
|
import org.compiere.model.MUser;
|
||||||
import static org.compiere.model.SystemIDs.*;
|
|
||||||
import org.compiere.print.ArchiveEngine;
|
import org.compiere.print.ArchiveEngine;
|
||||||
import org.compiere.print.MPrintFormat;
|
import org.compiere.print.MPrintFormat;
|
||||||
import org.compiere.print.ReportEngine;
|
import org.compiere.print.ReportEngine;
|
||||||
|
import org.compiere.tools.FileUtil;
|
||||||
import org.compiere.util.CLogger;
|
import org.compiere.util.CLogger;
|
||||||
import org.compiere.util.DB;
|
import org.compiere.util.DB;
|
||||||
import org.compiere.util.Env;
|
import org.compiere.util.Env;
|
||||||
|
@ -723,7 +725,7 @@ public class ZkReportViewer extends Window implements EventListener<Event>, ITab
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
attachment = File.createTempFile("mail", ".pdf");
|
attachment = new File(FileUtil.getTempMailName(subject, ".pdf"));
|
||||||
m_reportEngine.getPDF(attachment);
|
m_reportEngine.getPDF(attachment);
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|
Loading…
Reference in New Issue