Example usage for com.liferay.portal.kernel.util PropsKeys MAIL_HOOK_CYRUS_HOME

List of usage examples for com.liferay.portal.kernel.util PropsKeys MAIL_HOOK_CYRUS_HOME

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util PropsKeys MAIL_HOOK_CYRUS_HOME.

Prototype

String MAIL_HOOK_CYRUS_HOME

To view the source code for com.liferay.portal.kernel.util PropsKeys MAIL_HOOK_CYRUS_HOME.

Click Source Link

Usage

From source file:com.liferay.mail.util.CyrusHook.java

License:Open Source License

public void addForward(long companyId, long userId, List<Filter> filters, List<String> emailAddresses,
        boolean leaveCopy) {

    try {//from   w ww. ja  va  2s . c o m
        if (emailAddresses != null) {
            String home = PropsUtil.get(PropsKeys.MAIL_HOOK_CYRUS_HOME);

            File file = new File(home + "/" + userId + ".procmail.forward");

            if ((filters.size() > 0) || (emailAddresses.size() > 0) || (leaveCopy)) {

                StringBundler sb = new StringBundler();

                for (int i = 0; i < filters.size(); i++) {
                    Filter filter = filters.get(i);

                    sb.append(":0\n");
                    sb.append("* ^(From|Cc|To).*");
                    sb.append(filter.getEmailAddress());
                    sb.append("\n");
                    sb.append("| $DELIVER -e -a $USER -m user.$USER.");
                    sb.append(filter.getFolder());
                    sb.append("\n\n");
                }

                if (leaveCopy) {
                    sb.append(":0 c\n");
                    sb.append("| $DELIVER -e -a $USER -m user.$USER\n\n");
                }

                if (emailAddresses.size() > 0) {
                    sb.append(":0\n");
                    sb.append("!");

                    for (String emailAddress : emailAddresses) {
                        sb.append(" ");
                        sb.append(emailAddress);
                    }
                }

                String content = sb.toString();

                while (content.endsWith("\n")) {
                    content = content.substring(0, content.length() - 1);
                }

                FileUtil.write(file, content);
            } else {
                file.delete();
            }
        }
    } catch (Exception e) {
        _log.error(e, e);
    }
}

From source file:com.liferay.mail.util.CyrusHook.java

License:Open Source License

public void addVacationMessage(long companyId, long userId, String emailAddress, String vacationMessage) {

    try {//from   w w w  . j  a v a 2  s  .  com
        String home = PropsUtil.get(PropsKeys.MAIL_HOOK_CYRUS_HOME);

        // Remove vacation cache

        new File(home + "/" + userId + ".vacation.cache").delete();

        // Update vacation message

        File vacation = new File(home + "/" + userId + ".vacation");

        if (Validator.isNull(vacationMessage)) {
            vacation.delete();
        } else {
            FileUtil.write(vacation, emailAddress + "\n" + vacationMessage);
        }
    } catch (Exception e) {
        _log.error(e, e);
    }
}

From source file:com.liferay.mail.util.CyrusHook.java

License:Open Source License

public void deleteUser(long companyId, long userId) {
    try {//from w ww.j av  a  2  s.c om
        CyrusServiceUtil.deleteUser(userId);

        // Expect

        String deleteUserCmd = PropsUtil.get(PropsKeys.MAIL_HOOK_CYRUS_DELETE_USER);

        deleteUserCmd = StringUtil.replace(deleteUserCmd, "%1%", String.valueOf(userId));

        Runtime rt = Runtime.getRuntime();

        Process p = rt.exec(deleteUserCmd);

        ProcessUtil.close(p);

        // Procmail

        String home = PropsUtil.get(PropsKeys.MAIL_HOOK_CYRUS_HOME);

        File file = new File(home + "/" + userId + ".procmail.blocked");

        if (file.exists()) {
            file.delete();
        }

        file = new File(home + "/" + userId + ".procmail.forward");

        if (file.exists()) {
            file.delete();
        }

        file = new File(home + "/" + userId + ".vacation");

        if (file.exists()) {
            file.delete();
        }

        file = new File(home + "/" + userId + ".vacation.cache");

        if (file.exists()) {
            file.delete();
        }
    } catch (Exception e) {
        _log.error(e, e);
    }
}

From source file:com.liferay.mail.util.CyrusHook.java

License:Open Source License

public void updateBlocked(long companyId, long userId, List<String> blocked) {

    String home = PropsUtil.get(PropsKeys.MAIL_HOOK_CYRUS_HOME);

    File file = new File(home + "/" + userId + ".procmail.blocked");

    if ((blocked == null) || (blocked.size() == 0)) {
        file.delete();//  w ww. j  a  v  a  2  s  .  co m

        return;
    }

    StringBundler sb = new StringBundler(blocked.size() * 9);

    for (int i = 0; i < blocked.size(); i++) {
        String emailAddress = blocked.get(i);

        sb.append("\n");
        sb.append(":0\n");
        sb.append("* ^From.*");
        sb.append(emailAddress);
        sb.append("\n");
        sb.append("{\n");
        sb.append(":0\n");
        sb.append("/dev/null\n");
        sb.append("}\n");
    }

    try {
        FileUtil.write(file, sb.toString());
    } catch (Exception e) {
        _log.error(e, e);
    }
}