001
014
015 package com.liferay.mail.util;
016
017 import com.liferay.mail.model.Filter;
018 import com.liferay.portal.kernel.log.Log;
019 import com.liferay.portal.kernel.log.LogFactoryUtil;
020 import com.liferay.portal.kernel.process.ProcessUtil;
021 import com.liferay.portal.kernel.util.PropsKeys;
022 import com.liferay.portal.kernel.util.StringPool;
023 import com.liferay.portal.kernel.util.StringUtil;
024 import com.liferay.portal.util.PropsUtil;
025
026 import java.util.List;
027 import java.util.concurrent.Future;
028
029
032 public class ShellHook implements Hook {
033
034 public static final String SHELL_SCRIPT = PropsUtil.get(
035 PropsKeys.MAIL_HOOK_SHELL_SCRIPT);
036
037 public void addFilters(long companyId, long userId, List<String> filters) {
038 }
039
040 public void addForward(
041 long companyId, long userId, List<Filter> filters,
042 List<String> emailAddresses, boolean leaveCopy) {
043
044 execute(
045 new String[] {
046 SHELL_SCRIPT, "addForward", String.valueOf(userId),
047 StringUtil.merge(emailAddresses)
048 }
049 );
050 }
051
052 public void addUser(
053 long companyId, long userId, String password, String firstName,
054 String middleName, String lastName, String emailAddress) {
055
056 execute(
057 new String[] {
058 SHELL_SCRIPT, "addUser", String.valueOf(userId), password,
059 firstName, middleName, lastName, emailAddress
060 }
061 );
062 }
063
064 public void addVacationMessage(
065 long companyId, long userId, String emailAddress,
066 String vacationMessage) {
067
068 execute(
069 new String[] {
070 SHELL_SCRIPT, "addVacationMessage", String.valueOf(userId),
071 emailAddress, vacationMessage
072 }
073 );
074 }
075
076 public void deleteEmailAddress(long companyId, long userId) {
077 execute(
078 new String[] {
079 SHELL_SCRIPT, "deleteEmailAddress", String.valueOf(userId)
080 }
081 );
082 }
083
084 public void deleteUser(long companyId, long userId) {
085 execute(
086 new String[] {
087 SHELL_SCRIPT, "deleteUser", String.valueOf(userId)
088 }
089 );
090 }
091
092 public void updateBlocked(
093 long companyId, long userId, List<String> blocked) {
094
095 execute(
096 new String[] {
097 SHELL_SCRIPT, "updateBlocked", String.valueOf(userId),
098 StringUtil.merge(blocked)
099 }
100 );
101 }
102
103 public void updateEmailAddress(
104 long companyId, long userId, String emailAddress) {
105
106 execute(
107 new String[] {
108 SHELL_SCRIPT, "updateEmailAddress", String.valueOf(userId),
109 emailAddress
110 }
111 );
112 }
113
114 public void updatePassword(long companyId, long userId, String password) {
115 execute(
116 new String[] {
117 SHELL_SCRIPT, "updatePassword", String.valueOf(userId), password
118 }
119 );
120 }
121
122 protected void execute(String[] cmdLine) {
123 for (int i = 0; i < cmdLine.length; i++) {
124 if (cmdLine[i].trim().length() == 0) {
125 cmdLine[i] = StringPool.UNDERLINE;
126 }
127 }
128
129 try {
130 Future<?> future = ProcessUtil.execute(
131 ProcessUtil.LOGGING_OUTPUT_PROCESSOR, cmdLine);
132
133 future.get();
134 }
135 catch (Exception e) {
136 _log.error(e);
137 }
138 }
139
140 private static Log _log = LogFactoryUtil.getLog(ShellHook.class);
141
142 }