Search in sources :

Example 1 with AdminTask

use of web.AdminTask in project common by zenlunatics.

the class MailLists method readAndSend.

// --------------------------------------------------------------------------
@AdminTask
public void readAndSend() {
    DBConnection db = new DBConnection(m_site);
    Session session = Session.getInstance(new Properties(), null);
    new File(m_site.getBaseFilePath().append("inbox").toString()).listFiles(new FileFilter() {

        @Override
        public boolean accept(File file) {
            if (file.isDirectory() && file.getName().charAt(0) != '.')
                readAndSend(file, session, db);
            return false;
        }
    });
    db.close();
}
Also used : DBConnection(db.DBConnection) Properties(java.util.Properties) FileFilter(java.io.FileFilter) File(java.io.File) Session(javax.mail.Session) AdminTask(web.AdminTask)

Example 2 with AdminTask

use of web.AdminTask in project common by zenlunatics.

the class MailLists method checkAll.

// --------------------------------------------------------------------------
@AdminTask
public void checkAll(Request request) throws IOException {
    HTMLWriter writer = request.writer;
    List<String[]> rows = request.db.readRows(new Select("host,username,password,id,name").from("mail_lists").where("active"));
    Session session = Session.getInstance(new Properties(), null);
    for (String[] row : rows) if (row.length == 5 && row[0] != null && row[2] != null)
        try {
            Store store = session.getStore(((MailLists) request.site.getModule("MailLists")).m_store_protocol);
            String account = accountName(row[1], Integer.parseInt(row[3]));
            writer.h4(row[4]);
            store.connect(row[0], account, row[2]);
            Folder folder = store.getFolder("INBOX");
            folder.open(Folder.READ_ONLY);
            Message[] messages = folder.getMessages();
            if (messages.length > 0) {
                writer.write("<table border=\"1\">");
                for (Message message : messages) {
                    writer.write("<tr><td>");
                    Date date = message.getReceivedDate();
                    if (date != null)
                        writer.write(date);
                    writer.write("</td><td>");
                    writer.write(message.getFrom()[0]);
                    writer.write("</td><td>");
                    writer.write(message.getSubject());
                    writer.write("</td><td>");
                    writer.write(message.getSize());
                    writer.write("</td></tr>");
                }
                writer.write("</table>");
            } else
                writer.write("0 messages");
            folder.close(false);
            store.close();
        } catch (MessagingException e) {
            writer.write(e.toString());
        } catch (IOException e) {
            writer.write(e.toString());
        }
}
Also used : HTMLWriter(web.HTMLWriter) Message(javax.mail.Message) MimeMessage(javax.mail.internet.MimeMessage) MessagingException(javax.mail.MessagingException) Store(javax.mail.Store) IOException(java.io.IOException) Properties(java.util.Properties) Folder(javax.mail.Folder) Date(java.util.Date) LocalDate(java.time.LocalDate) Select(db.Select) Session(javax.mail.Session) AdminTask(web.AdminTask)

Example 3 with AdminTask

use of web.AdminTask in project common by zenlunatics.

the class FileColumn method checkFilesInDatabase.

// --------------------------------------------------------------------------
@AdminTask({ "table", "column", "show only problems" })
public static void checkFilesInDatabase(String table, String column, boolean show_only_problems, Request request) {
    HTMLWriter writer = request.writer;
    try {
        FileColumn file_column = (FileColumn) request.site.getViewDef(table, request.db).getColumn(column);
        String dir_column = file_column.getDirColumn();
        StringBuilder sql = new StringBuilder("SELECT ").append(column);
        if (dir_column != null)
            sql.append(',').append(dir_column);
        sql.append(" FROM ").append(table).append(" ORDER BY ");
        if (dir_column != null)
            sql.append(dir_column).append(',');
        sql.append(column);
        ResultSet rs = request.db.select(sql.toString());
        writer.write("<table class=\"table table-condensed table-bordered\" style=\"width:auto;\"><tr><th>filename</th>");
        if (dir_column != null)
            writer.write("<th>dir column</th>");
        writer.write("<th>status</th></tr>");
        while (rs.next()) {
            String dir_column_value = null;
            String filename = rs.getString(1);
            String problem = null;
            if (filename == null)
                problem = column + " is null";
            else {
                if (dir_column != null)
                    dir_column_value = rs.getString(2);
                FilePathStringBuilder file_path = file_column.getDirectory(dir_column_value, request.site);
                file_path.append(filename);
                if (!new File(file_path.toString()).exists())
                    problem = "missing";
            }
            if (problem != null || !show_only_problems) {
                writer.write("<tr><td>");
                if (filename != null)
                    writer.write(filename);
                if (dir_column != null) {
                    writer.write("</td><td>");
                    if (dir_column_value != null)
                        writer.write(dir_column_value);
                }
                writer.write("</td><td>").write(problem == null ? "ok" : problem).write("</td></tr>");
            }
        }
        writer.write("</table>");
        rs.getStatement().close();
    } catch (SQLException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : HTMLWriter(web.HTMLWriter) FilePathStringBuilder(web.FilePathStringBuilder) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) FilePathStringBuilder(web.FilePathStringBuilder) IOException(java.io.IOException) File(java.io.File) AdminTask(web.AdminTask)

Example 4 with AdminTask

use of web.AdminTask in project common by zenlunatics.

the class FileColumn method checkFilesNotInDatabase.

// --------------------------------------------------------------------------
@AdminTask({ "table", "column" })
public static void checkFilesNotInDatabase(final String table, final String column, final Request request) {
    try {
        FileColumn file_column = (FileColumn) request.site.getViewDef(table, request.db).getColumn(column);
        request.writer.h3("Files not in database");
        new File(file_column.getDirectory(request).toString()).list(new FilenameFilter() {

            @Override
            public boolean accept(File file, String filename) {
                if (!request.db.rowExists(table, column + "='" + DBConnection.escape(filename) + "'"))
                    try {
                        request.writer.write(filename).br();
                    } catch (IOException e) {
                    }
                return false;
            }
        });
    } catch (IOException e) {
        request.abort(e);
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) IOException(java.io.IOException) File(java.io.File) AdminTask(web.AdminTask)

Example 5 with AdminTask

use of web.AdminTask in project common by zenlunatics.

the class Pictures method syncPictures.

// --------------------------------------------------------------------------
@AdminTask
public void syncPictures(Request request) {
    FilePathStringBuilder file_path = request.site.getBaseFilePath();
    file_path.append(m_table);
    String pictures_directory = file_path.toString() + File.separator;
    String[] files = new File(pictures_directory).list();
    for (String file : files) {
        String id = file;
        int index = id.indexOf('.');
        if (index != -1)
            id = id.substring(0, index);
        if (Character.isDigit(file.charAt(0)) && request.db.lookupString("id", "pictures", Integer.parseInt(id)) == null)
            new File(pictures_directory + file).delete();
    }
    files = new File(pictures_directory + "thumbs/").list();
    for (String file : files) if (Character.isDigit(file.charAt(0))) {
        String id = file;
        int index = id.indexOf('.');
        if (index != -1)
            id = id.substring(0, index);
        if (request.db.lookupString("id", "pictures", Integer.parseInt(id)) == null)
            new File(pictures_directory + "thumbs/" + file).delete();
    }
}
Also used : FilePathStringBuilder(web.FilePathStringBuilder) File(java.io.File) AdminTask(web.AdminTask)

Aggregations

AdminTask (web.AdminTask)16 IOException (java.io.IOException)9 File (java.io.File)7 SQLException (java.sql.SQLException)7 Select (db.Select)6 ResultSet (java.sql.ResultSet)5 Session (javax.mail.Session)4 FilePathStringBuilder (web.FilePathStringBuilder)4 LocalDate (java.time.LocalDate)3 Properties (java.util.Properties)3 MessagingException (javax.mail.MessagingException)3 AddressException (javax.mail.internet.AddressException)3 MimeMessage (javax.mail.internet.MimeMessage)3 ICalendar (biweekly.ICalendar)2 VEvent (biweekly.component.VEvent)2 MailConnectException (com.sun.mail.util.MailConnectException)2 DBConnection (db.DBConnection)2 NameValuePairs (db.NameValuePairs)2 FileNotFoundException (java.io.FileNotFoundException)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2