use of web.AdminTask in project common by zenlunatics.
the class MailLists method checkForMail.
// --------------------------------------------------------------------------
@AdminTask
public void checkForMail() {
if (m_site.getBaseFilePath().toString().startsWith("/Users"))
return;
if (m_read_and_send)
readAndSend();
else {
if (m_lists != null && m_lists.size() == 0)
return;
DBConnection db = new DBConnection(m_site);
if (m_lists == null)
m_lists = db.readRows(new Select("name,username,host,password,id").from("mail_lists").where("active"));
try {
for (String[] list : m_lists) if (list[2] != null && list[3] != null)
fetchAndSend(list[0], accountName(list[1], Integer.parseInt(list[4])), list[2], list[3], db);
} catch (Exception e) {
System.out.println("fetchAndSendAll");
m_site.log(e);
}
db.close();
}
}
use of web.AdminTask in project common by zenlunatics.
the class MailLists method sendDigests.
// --------------------------------------------------------------------------
@AdminTask({ "date" })
public void sendDigests(LocalDate date, Site site, DBConnection db) {
Session session = getSession();
List<String> mail_lists = db.readValues(new Select("mail_lists_id").distinct().from("mail_lists_digest"));
for (String list_id : mail_lists) {
List<String> emails = db.readValues(new Select("email").from("people JOIN mail_lists_digest ON (mail_lists_digest.people_id=people.id)").where("mail_lists_id=" + list_id));
InternetAddress[] recipients = new InternetAddress[emails.size()];
for (int i = 0; i < emails.size(); i++) try {
recipients[i] = new InternetAddress(emails.get(i));
} catch (AddressException e) {
e.printStackTrace();
}
MailList mail_list = new MailList(Integer.parseInt(list_id), site, db);
MimeMessage message = mail_list.buildDigest(date, session, site, db);
if (message != null)
send(mail_list.getName(), message, recipients);
}
}
use of web.AdminTask in project common by zenlunatics.
the class MailLists method setupList.
// --------------------------------------------------------------------------
@AdminTask
public static void setupList(String name, Site site) {
File receive_script = new File(site.getBaseFilePath().append("inbox").append(name + ".sh").toString());
if (!receive_script.exists())
try {
FileWriter fw = new FileWriter(receive_script);
fw.write("cd ");
fw.write(site.getBaseFilePath().toString());
fw.write(";/usr/bin/java ReceiveMail ");
fw.write(name);
fw.close();
receive_script.setExecutable(true);
} catch (IOException e) {
}
new File(site.getBaseFilePath().append("inbox").append(name).toString()).mkdirs();
String base_file_path = site.getBaseFilePath().toString();
if (base_file_path.endsWith("/ROOT"))
base_file_path = base_file_path.substring(0, base_file_path.length() - 5);
site.runScript("new_email", base_file_path.substring(base_file_path.lastIndexOf('/') + 1), name, site.getDomain());
}
use of web.AdminTask in project common by zenlunatics.
the class MailLists method fetchAndSend.
// --------------------------------------------------------------------------
@AdminTask({ "list", "account name", "host", "password" })
public synchronized void fetchAndSend(String list, String account_name, String host, String password, DBConnection db) throws MessagingException {
Session session = Session.getInstance(new Properties(), null);
Folder folder = null;
Store store = null;
try {
store = session.getStore(m_store_protocol);
try {
store.connect(host, account_name, password);
} catch (AuthenticationFailedException e) {
if (e.toString().indexOf("temporarily unavailable") == -1)
try {
TimeUnit.SECONDS.sleep(15);
store.connect(host, account_name, password);
} catch (AuthenticationFailedException e1) {
if (e1.toString().indexOf("temporarily unavailable") == -1)
sendError(list, "fetchAndSend", "store.connect", null, e1);
return;
} catch (InterruptedException e1) {
sendError(list, "fetchAndSend", "store.connect", null, e1);
return;
}
else
return;
} catch (MailConnectException e) {
m_site.log(e);
if (host.equals("172.21.0.1") || host.equals("sonoracohousing.com"))
return;
}
if (store.isConnected()) {
folder = store.getFolder("INBOX");
try {
folder.open(Folder.READ_WRITE);
} catch (MessagingException e) {
if (e.toString().indexOf("* BYE") != -1)
return;
throw e;
}
Message[] messages = folder.getMessages();
long now = new Date().getTime();
for (Message message : messages) {
if (message.getHeader("X-ignore") != null || message.getHeader("auto-submitted") != null || message.getHeader("Auto-Submitted") != null || message.getHeader("X-Autoreply") != null || message.getHeader("X-Autorespond") != null) {
message.setFlag(Flags.Flag.DELETED, true);
continue;
}
Date received_date = message.getReceivedDate();
long minutes = (now - received_date.getTime()) / 60000;
if (minutes > 30)
sendError(list, "fetchAndSend", "message " + minutes + " minutes old", null, null);
Address[] recipients = message.getRecipients(RecipientType.TO);
if (recipients != null) {
String to = recipients[0].toString();
if (to == null)
System.out.println("to is null");
else if (to.indexOf('+') != -1)
message.setFlag(Flags.Flag.DELETED, true);
}
if (handleMessage(list, message, true, db))
message.setFlag(Flags.Flag.DELETED, true);
}
}
} catch (MessagingException e) {
if (e.toString().indexOf("Connection dropped by server?") == -1 && e.toString().indexOf("BYE JavaMail") == -1)
m_site.log(e);
// sendError(list, "fetchAndSend", null, e);
} finally {
try {
if (folder != null && folder.isOpen())
folder.close(true);
} catch (Exception e) {
sendError(list, "fetchAndSend", "closing folder", null, e);
}
store.close();
}
}
use of web.AdminTask in project common by zenlunatics.
the class EventProvider method writeICS.
// --------------------------------------------------------------------------
@AdminTask
public synchronized void writeICS(Request request) throws IOException {
ICalendar ical = new ICalendar();
String string = request.site.getSettings().getString("time zone");
TimeZone time_zone = TimeZone.getTimeZone(string);
TimezoneAssignment tza = TimezoneAssignment.download(time_zone, false);
ical.getTimezoneInfo().setDefaultTimezone(tza);
ArrayList<Event> events = new ArrayList<Event>();
addAllEvents(events, request);
for (Event event : events) {
VEvent vevent = event.newVEvent(request);
if (vevent != null)
ical.addEvent(vevent);
}
FilePathStringBuilder fpsb = request.site.getBaseFilePath().append("calendars");
new File(fpsb.toString()).mkdirs();
String file_path = fpsb.append(m_name).toString();
Biweekly.write(ical).go(new File(file_path));
new File(file_path).renameTo(new File(file_path + ".ics"));
}
Aggregations