19 package org.turro.mail.recipients;
22 import java.io.FileOutputStream;
23 import java.io.InputStream;
24 import java.util.ArrayList;
25 import java.util.Collection;
27 import net.sf.jasperreports.engine.JRDataSource;
28 import net.sf.jasperreports.engine.JRException;
29 import org.turro.action.Contacts;
30 import org.turro.command.Command;
31 import org.turro.elephant.context.Application;
32 import org.turro.elephant.context.ElephantContext;
33 import org.turro.elephant.security.IUser;
34 import org.turro.elephant.util.Images;
35 import org.turro.elephant.util.Messages;
36 import org.turro.i18n.I_;
37 import org.turro.mail.message.MailMessage;
38 import org.turro.mail.provider.MailProvider;
39 import org.turro.mail.provider.MailProviders;
40 import org.turro.plugin.contacts.IContact;
41 import org.turro.zkoss.contact.IContactCombobox;
42 import org.turro.zkoss.dialog.SelectionDialog;
43 import org.turro.zkoss.layout.GridLayout;
44 import org.turro.zkoss.print.SignedReport;
45 import org.turro.zul.frame.Framework;
46 import org.zkoss.zk.ui.event.Event;
47 import org.zkoss.zk.ui.event.EventListener;
48 import org.zkoss.zk.ui.event.Events;
49 import org.zkoss.zul.A;
50 import org.zkoss.zul.Row;
51 import org.zkoss.zul.Textbox;
59 private Collection<IContact> recipients =
new ArrayList<>();
61 private static String comment;
64 if(recipients !=
null) {
65 this.recipients.addAll(recipients);
71 public static void selectRecipients(Collection<IContact> recipients, Command command) {
74 mr.setStyle(
"overflow:auto;");
78 mr,
"425px",
"350px", command);
85 public static void send(String title, JRDataSource dataSource, Map parameters, String jasperFile,
86 String defaultFile, String type, String certificateStore, Collection<IContact> contacts)
throws JRException {
88 if(contacts ==
null)
return;
93 sr.setSrc(jasperFile);
95 sr.setSrc(defaultFile);
97 sr.setParameters(parameters);
98 sr.setDatasource(dataSource);
100 File attach = File.createTempFile(
"attach_",
"_mail");
101 FileOutputStream fos =
new FileOutputStream(attach);
102 InputStream is = sr.getReport().getStreamData();
104 byte[] bytes =
new byte[1024];
105 while ((read = is.read(bytes)) != -1) {
106 fos.write(bytes, 0, read);
111 StringBuilder sb =
new StringBuilder();
117 mm.
addTo(c.getEmail(), c.getName());
118 sb.append(email).append(
": ").append(c.getName()).append(
"\n");
122 "<p><i>" +
I_.
get(
"Automatically generated") +
"</i></p>" +
129 if(sb.length() > 0) {
134 }
catch (Exception ex) {
138 private void addRecipients() {
139 for(
final IContact c : recipients) {
146 final IContactCombobox cc =
new IContactCombobox();
147 cc.setWidth(
"390px");
148 cc.addEventListener(Events.ON_OK,
new EventListener<Event>() {
150 public void onEvent(Event event) throws Exception {
151 event.stopPropagation();
152 IContact c = cc.getObjectValue();
153 if(c != null && c.isWebUser() && Contacts.hasValidEmail(c)) {
154 insertBeforeRow(editRow);
156 cc.setObjectValue(null);
162 final Textbox commentBox =
new Textbox();
163 commentBox.setWidth(
"390px");
164 commentBox.setRows(4);
165 commentBox.setPlaceholder(I_.get(
"Comment"));
166 commentBox.addEventListener(Events.ON_CHANGE,
new EventListener<Event>() {
168 public void onEvent(Event event) throws Exception {
169 event.stopPropagation();
170 comment = commentBox.getValue();
173 addSpannedComponent(commentBox, 2);
176 private void addRecipient(
final IContact c) {
177 final Row row = getCurrentRow();
179 addCaption(c.getName() +
" : " + c.getConnector(IUser.CONNECTOR_EMAIL));
180 A del =
new A(
null, Images.getImage(
"edit-delete"));
181 del.addEventListener(Events.ON_CLICK,
new EventListener<Event>() {
183 public void onEvent(Event event) throws Exception {
191 recipients =
new ArrayList<>();
192 for(Object o : getRows().getChildren()) {
193 if(o instanceof Row) {
194 if(((Row) o).getValue() instanceof
IContact) {
195 recipients.add((
IContact) ((Row) o).getValue());
static Application getApplication()
static String getRealPath(String path)
static String getSiteName()
Messages add(String word)
static String get(String msg)
void attach(String path, String description, String name)
Email setFrom(String email, String name)
Email addTo(String email, String name)
void setMessage(String message)
static MailMessage of(MailProvider provider)
void setSubject(String subject)
MailProvider getProvider(String name)
static MailProviders instance()
static void send(String title, JRDataSource dataSource, Map parameters, String jasperFile, String defaultFile, String type, String certificateStore, Collection< IContact > contacts)
IMailRecipients(Collection< IContact > recipients)
static String getComment()
static void selectRecipients(Collection< IContact > recipients, Command command)
Collection< IContact > getRecipients()
void setColumns(int columns)
GridLayout addSpannedComponent(HtmlBasedComponent comp, int cols)
void setCertificateStore(String certificateStore)
static Framework getCurrent()
static final String CONNECTOR_EMAIL