001 /* 002 * Copyright (c) 2009 The openGion Project. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, 013 * either express or implied. See the License for the specific language 014 * governing permissions and limitations under the License. 015 */ 016 package org.opengion.hayabusa.mail; 017 018 import static org.opengion.fukurou.util.StringUtil.nval; 019 020 import java.util.List; 021 import java.util.ArrayList; 022 import java.util.HashMap; 023 import java.util.Map; 024 025 import javax.mail.Address; 026 import javax.mail.SendFailedException; 027 import javax.mail.internet.InternetAddress; 028 029 import org.opengion.fukurou.db.DBUtil; 030 import org.opengion.fukurou.mail.MailTX; 031 import org.opengion.fukurou.util.ApplicationInfo; 032 import org.opengion.hayabusa.common.HybsSystem; 033 034 /** 035 * ã‚¿ã‚° mailSender2 åŠã?ãƒãƒƒãƒã«ã‚ˆã‚‹é€ä¿¡ã®å…±é€šå?ç?ƒ¨åˆ?‚’実è£?—ã¦ã?¾ã™ã? 036 * é€ä¿¡ã‚¿ã‚° mailSender2 ã‚‚ã—ãã?é€ä¿¡ãƒ??モンã‹ã‚‰ãƒ‘ラメータをå—å–りã¾ã™ã? 037 * パラメータä¸ã®å®šåž‹æ–‡IDåŠã?シスãƒ?ƒ IDã§å®šåž‹æ–??スタよりメールã®å®šåž‹æ–?‚’å–å¾—ã—ã¦ã€? 038 * パラメータ値ã¨ãƒžã?ジã—ã¦ãƒ¡ãƒ¼ãƒ«æ–?‚’åˆæ?ã—ã¾ã™ã?åŒæ™‚ã«ã€å®›å?ã«ã‚»ãƒ?ƒˆã—ãŸç¤¾å“¡IDã€? 039 * グループIDã¨å®šåž‹æ–??å®›å?è¨å®šã«åŸºã¥ãã?社員マスタã¨ã‚°ãƒ«ãƒ¼ãƒ—ã?スタよりメールアドレス 040 * æƒ??ã‚’å–å¾—ã—ã¦é€ä¿¡ã‚’行ã„ã¾ã™ã? 041 * エラーãŒãªã‘れã°é€ä¿¡ã—ãŸå†?®¹ã‚’å±¥æ´ãƒ??ブルã€å®›å?ãƒ??ãƒ–ãƒ«ã«æ›¸ãè¾¼ã¿ã¾ã™ã? 042 * æœ?¾Œã«æœ¬å‡¦ç??呼出å…?«é€ä¿¡çµæžœã€ã‚¨ãƒ©ãƒ¼ãƒ¡ãƒ?‚»ãƒ¼ã‚¸ã‚’è¿”ã—ã¾ã™ã? 043 * 044 * @og.group メールモジュール 045 * 046 * @version 4.0 047 * @author Sen.Li 048 * @since JDK1.6 049 */ 050 public abstract class AbstractMailManager { 051 052 // 5.2.0.0 (2010/09/01) Ver4互æ›ãƒ¢ãƒ¼ãƒ‰å¯¾å¿? 053 private static final String CONTENTS = HybsSystem.sysBool( "VER4_COMPATIBLE_MODE" ) ? "CONTENT" : "CONTENTS"; 054 055 private static final String selYkno = "SELECT GE32S02.NEXTVAL YKNO FROM DUAL"; 056 // 5.0.3.0 (2009/11/04) CONTENT â‡?CONTENTS 057 // 5.2.0.0 (2010/09/01) Ver4互æ›ãƒ¢ãƒ¼ãƒ‰å¯¾å¿? 058 // private static final String insGE32 = "INSERT INTO GE32(YKNO,PARA_KEY,PTN_ID,FROM_ADDR,TITLE,CONTENTS,ATTACH1,ATTACH2,ATTACH3,ATTACH4,ATTACH5,DYSET,USRSET,PGUPD,SYSTEM_ID,FGJ)" 059 private static final String insGE32 = "INSERT INTO GE32(YKNO,PARA_KEY,PTN_ID,FROM_ADDR,TITLE,"+CONTENTS+",ATTACH1,ATTACH2,ATTACH3,ATTACH4,ATTACH5,DYSET,USRSET,PGUPD,SYSTEM_ID,FGJ)" 060 + " VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,'1')"; 061 private static final String insGE34 = "INSERT INTO GE34(YKNO,DST_ID,GROUP_ID,DST_NAME,DST_ADDR,DST_KBN,FGJ,DYSET,USRSET,PGUPD)" 062 + " VALUES(?,?,?,?,?,?,?,?,?,?)"; 063 /** フラグ定数 {@value} */ 064 protected static final String FGJ_SEND_WAIT = "0"; 065 /** フラグ定数 {@value} */ 066 protected static final String FGJ_SEND_OVER = "1"; 067 /** フラグ定数 {@value} */ 068 protected static final String FGJ_ADDR_ERR = "7"; 069 /** フラグ定数 {@value} */ 070 protected static final String FGJ_ACNT_ERR = "8"; 071 072 // å†?ƒ¨ãƒ??ã‚¿ã®ã‚«ãƒ©ãƒ?•ªå·(å±¥æ´ãƒ??ブル) 073 private static final int GE32_YKNO = 0 ; 074 private static final int GE32_PARAKEY = 1 ; 075 private static final int GE32_PTN_ID = 2; 076 private static final int GE32_FROM_ADDR = 3; 077 private static final int GE32_TITLE = 4; 078 private static final int GE32_CONTENTS = 5; // 5.0.3.0 (2009/11/04) CONTENT â‡?CONTENTS 079 private static final int GE32_ATTACH1 = 6; 080 private static final int GE32_ATTACH2 = 7; 081 private static final int GE32_ATTACH3 = 8; 082 private static final int GE32_ATTACH4 = 9; 083 private static final int GE32_ATTACH5 = 10; 084 private static final int GE32_DYSET = 11; 085 private static final int GE32_USRSET = 12; 086 private static final int GE32_PGUPD = 13; 087 private static final int GE32_SYSTEM_ID = 14; 088 // å†?ƒ¨ãƒ??ã‚¿ã®ã‚«ãƒ©ãƒ?•ªå·(å±¥æ´ãƒ??ブル) 089 private static final int GE34_YKNO = 0 ; 090 private static final int GE34_DST_ID = 1 ; 091 private static final int GE34_GROUP_ID = 2 ; 092 private static final int GE34_DST_NAME = 3 ; 093 private static final int GE34_DST_ADDR = 4 ; 094 private static final int GE34_DST_KBN = 5 ; 095 private static final int GE34_FGJ = 6 ; 096 private static final int GE34_DYSET = 7 ; 097 private static final int GE34_USRSET = 8 ; 098 private static final int GE34_PGUPD = 9 ; 099 // private static String host = HybsSystem.sys( "COMMON_MAIL_SERVER" ); 100 private static String charset = HybsSystem.sys( "MAIL_DEFAULT_CHARSET" ); 101 // private static String smtpPort = HybsSystem.sys( "SMTP_PORT" ); // 5.4.3.2 (2012/01/06) 102 // private static String auth = HybsSystem.sys( "MAIL_SEND_AUTH" ); // 5.4.3.2 (2012/01/06) 103 // private static String authUser = HybsSystem.sys( "MAIL_SEND_AUTH_USER" ); // 5.4.3.2 (2012/01/06) 104 // private static String authPass = HybsSystem.sys( "MAIL_SEND_AUTH_PASSWORD" ); // 5.4.3.2 (2012/01/06) 105 private boolean debugFlag = false; 106 private final List<String> errAddrList = new ArrayList<String>(); 107 private static final int MAX_RETRY = 3 ; // メールアドレスエラー発生ã—ãŸå?åˆã?メールå†é?回数 108 109 // 5.6.6.0 (2013/07/05) hostç‰ã?外部æŒ?®šã«å¯¾å¿? 110 private String host = HybsSystem.sys( "COMMON_MAIL_SERVER" ); // 5.6.6.0 (2013/07/05) 111 private String smtpPort = HybsSystem.sys( "SMTP_PORT" ); // 5.6.6.0 (2013/07/05) 112 private String auth = HybsSystem.sys( "MAIL_SEND_AUTH" ); // 5.6.6.0 (2013/07/05) 113 private String authUser = HybsSystem.sys( "MAIL_SEND_AUTH_USER" ); // 5.6.6.0 (2013/07/05) 114 private String authPass = HybsSystem.sys( "MAIL_SEND_AUTH_PASSWORD" ); // 5.6.6.0 (2013/07/05) 115 116 private String mailTitle, mailContent, fromAddr; 117 private String[] attachFiles; 118 private Map<String, String[]> mailDstMap = null; 119 private Map<String,String> initParamMap = null; // パラメータマッãƒ? 120 private MailTX mail = null; 121 122 protected final String DBID = HybsSystem.sys( "RESOURCE_DBID" ); // 5.5.5.1 (2012/08/07) リソース系DBID 付ã‘忘れ対å¿? 123 124 /** コãƒã‚¯ã‚·ãƒ§ãƒ³ã«ã‚¢ãƒ—リケーションæƒ??を追記ã™ã‚‹ã‹ã©ã?‹æŒ?®?*/ 125 private static final boolean USE_DB_APPLICATION_INFO = HybsSystem.sysBool( "USE_DB_APPLICATION_INFO" ) ; 126 127 /** アプリケーションæƒ?? */ 128 public static final ApplicationInfo appInfo; 129 static { 130 if( USE_DB_APPLICATION_INFO ) { 131 appInfo = new ApplicationInfo(); 132 // ユーザーID,IPアドレス,ホストå 133 appInfo.setClientInfo( "MailModuel", HybsSystem.HOST_ADRS, HybsSystem.HOST_NAME ); 134 // ç”»é¢ID,æ“ä½?プãƒã‚°ãƒ©ãƒ?D 135 appInfo.setModuleInfo( "MailModuel", "MailManager", "MailManager" ); 136 } 137 else { 138 appInfo = null; 139 } 140 } 141 142 /** 143 * 呼出å…?‚ˆã‚Šãƒ‘ラメータマップをå—å–ã£ã¦ã€ãƒ¡ãƒ¼ãƒ«ã‚ªãƒ–ジェクãƒ?mailObj)を作æ?ã—ã¾ã™ã? 144 * メールオブジェクトã?定型文IDåŠã?シスãƒ?ƒ IDã«åŸºã¥ã?¦å®šåž‹æ–??スタã‹ã‚‰ãƒ¡ãƒ¼ãƒ«ã®å®šåž‹æ–?‚’å–å¾—ã—ã¦ã€? 145 * パラメータ値ã¨ãƒžã?ジã—ã¦ãƒ¡ãƒ¼ãƒ«æ–??å??ç›®ã‚’åˆæˆã—ã¾ã™ã? 146 * å®›å?ã«ã¤ã?¦ã¯ã€å®›å?ã«ã‚»ãƒ?ƒˆã—ãŸç¤¾å“¡IDã€ã‚°ãƒ«ãƒ¼ãƒ—IDã¨å®šåž‹æ–??å®›å?è¨å®šã«åŸºã¥ãã?社員マスタã¨ã‚°ãƒ«ãƒ¼ãƒ—ã?スタ 147 * よりメールアドレスをå–å¾—ã—ã¦å®›å?マップを作æ?ã—ã¾ã™ã? 148 * ã¾ã??添付ファイルã®ã‚»ãƒ?ƒˆå‡¦ç?‚‚行ã£ã¦ã?¾ã™ã? 149 * 150 * @og.rev 5.6.6.0 (2013/07/05) hostç‰ã?外部è¨å®šå¯¾å¿? 151 * 152 * @param params パラメータã®ãƒžãƒƒãƒ? 153 */ 154 public void create( final Map<String, String> params ) { 155 initParamMap = params; 156 MailPattern mailObj = new MailPattern( params ); 157 fromAddr = mailObj.getFromAddr(); 158 setAttachFiles( params.get( "ATTACH1" ) 159 , params.get( "ATTACH2" ) 160 , params.get( "ATTACH3" ) 161 , params.get( "ATTACH4" ) 162 , params.get( "ATTACH5" ) ); // 添付ファイルã®ã‚»ãƒ?ƒˆ 163 mailDstMap = mailObj.getDstMap(); 164 mailTitle = mailObj.getTitle(); 165 mailContent = mailObj.getContent(); 166 errAddrList.addAll( mailObj.getErrList() ); 167 168 // 5.6.6.0 (2013/07/05) 169 host = nval( mailObj.getHost() ,host ); 170 smtpPort = nval( mailObj.getSmtpPort() ,smtpPort ); 171 auth = nval( mailObj.getAuth() ,auth ); 172 authUser = nval( mailObj.getAuthUser() ,authUser ); 173 authPass = nval( mailObj.getAuthPass() ,authPass ); 174 } 175 176 /** 177 * メールé€ä¿¡ã‚’行ã†ãƒ¡ã‚½ãƒ?ƒ‰ã§ã™ã? 178 * createメソãƒ?ƒ‰ã‚ˆã‚Šåˆæ?ã—ãŸå†?®¹ã§é€ä¿¡ã‚’行ã„ã¾ã™ã?アドレスエラー発生時ã«ã€? 179 * ユーザーè¨å®?addrCheck)ã«ã‚ˆã‚Šå†é?/䏿¢ã—ã¾ã™ã? 180 * メールサーãƒã?ã«é€ä¿¡ã—ã¦ã€ä¾‹å¤?SendFailedException"ã‚’ã‚ャãƒ?ƒã§ããŸã‚‰ã? 181 * メールアカウントãŒã‚¨ãƒ©ãƒ¼ã¨ãªã‚‹ã?ã‚’å?ã‹ã‚Šã¾ã™ã?ãã—ã¦ã€ä¾‹å¤–ã?オブジェクトã‹ã‚? 182 * エラーã¨ãªã£ã¦ã?‚‹ã‚¢ã‚«ã‚¦ãƒ³ãƒˆã‚’å–å¾—ã—ã¦å®›å?マップã‹ã‚‰é™¤å¤–ã—ã¦ã€æ®‹ã‚Šã®ã‚¢ãƒ‰ãƒ¬ã‚¹ã«å†é?ã§ãã¾ã™ã? 183 * é€ä¿¡å¾Œå±¥æ´ãƒ??ブル(GE32)ã€å®›å?ãƒ??ブル(GE34)ã«é€ä¿¡çµæžœã‚’書ãè¾¼ã¿ã¾ã™ã? 184 * 185 * og.rev 5.4.3.2 (2012/01/06) é€ä¿¡æ™‚èªè¨¼å¯¾å¿? 186 * 187 */ 188 public void send() { 189 List<String> invalidAddrBuf = new ArrayList<String>(); 190 // mail = new MailTX( host, charset ); 191 mail = new MailTX( host, charset, smtpPort, auth, authUser, authPass ); // 5.4.3.2 èªè¨¼å¯¾å¿? 192 mail.setFrom( fromAddr ); // é€ä¿¡è€?‚¢ãƒ‰ãƒ¬ã‚¹ 193 mail.setFilename( attachFiles ); // 添付ファイルをセãƒ?ƒˆã—ã¾ã™ã? 194 mail.setSubject( mailTitle ); // メールタイトル 195 mail.setMessage( mailContent ); // メール本æ–? 196 mail.setDebug( debugFlag ); 197 setMailDst( invalidAddrBuf ); // å®›å?ã‚’ã‚»ãƒ?ƒˆã—ã¾ã™ã? 198 // メールé€ä¿¡ã‚’行ã„ã¾ã™ã? 199 int retryCount = MAX_RETRY; 200 while( retryCount > 0 ) { 201 try { 202 mail.sendmail(); 203 } 204 catch( RuntimeException rex ) { 205 Throwable cause = rex.getCause(); 206 if( cause instanceof SendFailedException ) { 207 Address[] invAddress = ( (SendFailedException) cause ).getInvalidAddresses(); 208 if( invAddress != null ) { 209 int invCount = invAddress.length; 210 for( int i = 0; i < invCount; i++ ) { 211 invalidAddrBuf.add( ( (InternetAddress) invAddress[i] ).getAddress() ); 212 } 213 } 214 } 215 else { 216 String errMsg = "é€ä¿¡æ™‚ã«ã‚¨ãƒ©ãƒ¼ç™ºç”Ÿã—ã¾ã—ãŸã€? + rex.getMessage(); 217 throw new RuntimeException( errMsg,rex ); 218 } 219 } 220 221 // if( invalidAddrBuf.size() > 0 ) { 222 // StringBuilder errMsgBuf = new StringBuilder(); 223 // for( int i = 0; i < invalidAddrBuf.size(); i++ ) { 224 // errMsgBuf.append( "," ).append( invalidAddrBuf.get( i ) ); 225 // } 226 // String userIds = getUserIds( invalidAddrBuf ); 227 // String errMsg = "アドレスエラー。ユーザーID?? + userIds + " アドレス?? + errMsgBuf.toString().substring( 1 ); 228 // if( "true".equals( initParamMap.get( "ADDR_CHECK" ) ) ){ 229 // throw new RuntimeException( errMsg ); 230 // } 231 // else { 232 // // メールアカウントãƒã‚§ãƒ?‚¯ã—ãªã??åˆã?無効ã®ãƒ¡ãƒ¼ãƒ«ã‚¢ãƒ‰ãƒ¬ã‚¹ã‚’除ã?¦å†é?ã—ã¾ã™ã? 233 // setMailDst( invalidAddrBuf ); 234 // retryCount--; 235 // invalidAddrBuf.clear(); 236 // errAddrList.add( errMsg ); 237 // } 238 // } 239 // else { 240 // retryCount = -1; 241 // } 242 243 if( invalidAddrBuf.isEmpty() ) { 244 retryCount = -1; 245 } 246 else { 247 StringBuilder errMsgBuf = new StringBuilder(); 248 for( int i = 0; i < invalidAddrBuf.size(); i++ ) { 249 errMsgBuf.append( ',' ).append( invalidAddrBuf.get( i ) ); 250 } 251 String userIds = getUserIds( invalidAddrBuf ); 252 String errMsg = "アドレスエラー。ユーザーID?? + userIds + " アドレス?? + errMsgBuf.toString().substring( 1 ); 253 if( "true".equals( initParamMap.get( "ADDR_CHECK" ) ) ){ 254 throw new RuntimeException( errMsg ); 255 } 256 else { 257 // メールアカウントãƒã‚§ãƒ?‚¯ã—ãªã??åˆã?無効ã®ãƒ¡ãƒ¼ãƒ«ã‚¢ãƒ‰ãƒ¬ã‚¹ã‚’除ã?¦å†é?ã—ã¾ã™ã? 258 setMailDst( invalidAddrBuf ); 259 retryCount--; 260 invalidAddrBuf.clear(); 261 errAddrList.add( errMsg ); 262 } 263 } 264 } 265 commitMailDB(); // é€ä¿¡çµæžœã‚’å±¥æ´ãƒ??ブルã€å®›å?ãƒ??ブルã«ã‚»ãƒ?ƒˆã—ã¾ã™ã? 266 } 267 268 /** 269 * ãƒ?ƒãƒ?‚°æƒ??ã®è¡¨ç¤ºã‚’行ã†ã‹ã©ã?‹[true/false]ã‚’ã‚»ãƒ?ƒˆã—ã¾ã™ã? 270 * 271 * @param debug [true:出力ã™ã‚?ãれ以å¤?ã—ãªã„] 272 */ 273 public void setDebug( final boolean debug ) { 274 debugFlag = debug; 275 } 276 277 /** 278 * メールé€ä¿¡è€?‚¢ãƒ‰ãƒ¬ã‚¹ã‚’ã‚»ãƒ?ƒˆã—ã¾ã™ã? 279 * 280 * @param from é€ä¿¡è€?‚¢ãƒ‰ãƒ¬ã‚¹ 281 */ 282 public void setFromAddr( final String from ) { 283 fromAddr = from; 284 } 285 286 /** 287 * メールタイトルをセãƒ?ƒˆã—ã¾ã™ã? 288 * 289 * @param title メールタイトル 290 */ 291 public void setTitle( final String title ) { 292 mailTitle = title; 293 } 294 295 /** 296 * メール本æ–?‚’ã‚»ãƒ?ƒˆã—ã¾ã™ã? 297 * 298 * @param content メール本æ–? 299 */ 300 public void setContent( final String content ) { 301 mailContent = content; 302 } 303 304 /** 305 * メールé€ä¿¡ãƒ›ã‚¹ãƒˆã‚’ã‚»ãƒ?ƒˆã—ã¾ã™ã? 306 * åˆæœŸå€¤ã¯ã€ã‚·ã‚¹ãƒ?ƒ 定数ã®COMMON_MAIL_SERVER を使用ã—ã¾ã™ã? 307 * 308 * (åˆæœŸå€¤:シスãƒ?ƒ 定数ã®COMMON_MAIL_SERVER[={@og.value org.opengion.hayabusa.common.SystemData#COMMON_MAIL_SERVER}])ã€? 309 * 310 * @og.rev 5.6.6.0 (2013/07/05) 311 * 312 * @param hostName é€ä¿¡ãƒ›ã‚¹ãƒ? 313 */ 314 public void setHost( final String hostName ) { 315 host = nval( hostName, host ); 316 } 317 318 /** 319 * メールé€ä¿¡ãƒã?ト番å·ã‚’ã‚»ãƒ?ƒˆã—ã¾ã™ã? 320 * åˆæœŸå€¤ã¯ã€ã‚·ã‚¹ãƒ?ƒ 定数ã®SMTP_PORT を使用ã—ã¾ã™ã? 321 * 322 * (åˆæœŸå€¤:シスãƒ?ƒ 定数ã®SMTP_PORT[={@og.value org.opengion.hayabusa.common.SystemData#SMTP_PORT}])ã€? 323 * 324 * @og.rev 5.6.6.0 (2013/07/05) 325 * 326 * @param port SMTPãƒã?ãƒ? 327 */ 328 public void setPort( final String port ) { 329 smtpPort = nval( port, smtpPort ); 330 } 331 332 /** 333 * メールé€ä¿¡æ™‚èªè¨¼æœ‰ç„¡ã‚’ã‚»ãƒ?ƒˆã—ã¾ã™ã? 334 * èªè¨¼ã‚’行ã†å ´åˆã?「POP_BEFORE_SMTPã€ã¨æŒ?®šã—ã¦ä¸‹ã•ã?? 335 * èªè¨¼æ™‚ã«ã¯èªè¨¼ãƒ¦ãƒ¼ã‚¶ã¨èªè¨¼ãƒ‘スワードをè¨å®šã™ã‚‹å¿?¦ãŒã‚りã¾ã™ã? 336 * åˆæœŸå€¤ã¯ã€ã‚·ã‚¹ãƒ?ƒ 定数ã®MAIL_SEND_AUTH を使用ã—ã¾ã™ã? 337 * 338 * (åˆæœŸå€¤:シスãƒ?ƒ 定数ã®MAIL_SEND_AUTH[={@og.value org.opengion.hayabusa.common.SystemData#MAIL_SEND_AUTH}])ã€? 339 * 340 * @og.rev 5.6.6.0 (2013/07/05) 341 * 342 * @param useAuth èªè¨¼æ–¹å¼? 343 */ 344 public void setAuth( final String useAuth ) { 345 auth = nval( useAuth, auth ); 346 } 347 348 /** 349 * メールé€ä¿¡èªè¨¼ãƒ¦ãƒ¼ã‚¶ã‚’ã‚»ãƒ?ƒˆã—ã¾ã™ã? 350 * åˆæœŸå€¤ã¯ã€ã‚·ã‚¹ãƒ?ƒ 定数ã®MAIL_SEND_AUTH_USER を使用ã—ã¾ã™ã? 351 * 352 * (åˆæœŸå€¤:シスãƒ?ƒ 定数ã®MAIL_SEND_AUTH_USER[={@og.value org.opengion.hayabusa.common.SystemData#MAIL_SEND_AUTH_USER}])ã€? 353 * 354 * @og.rev 5.6.6.0 (2013/07/05) 355 * 356 * @param user èªè¨¼ãƒ¦ãƒ¼ã‚¶ 357 */ 358 public void setAuthUser( final String user ) { 359 authUser = nval( user, authUser ); 360 } 361 362 /** 363 * メールé€ä¿¡èªè¨¼ãƒ‘スワードをセãƒ?ƒˆã—ã¾ã™ã? 364 * åˆæœŸå€¤ã¯ã€ã‚·ã‚¹ãƒ?ƒ 定数ã®MAIL_SEND_AUTH_PASSWORD を使用ã—ã¾ã™ã? 365 * 366 * (åˆæœŸå€¤:シスãƒ?ƒ 定数ã®MAIL_SEND_AUTH_PASSWORD[={@og.value org.opengion.hayabusa.common.SystemData#MAIL_SEND_AUTH_PASSWORD}])ã€? 367 * 368 * @og.rev 5.6.6.0 (2013/07/05) 369 * 370 * @param pass èªè¨¼ãƒ‘スワーãƒ? 371 */ 372 public void setAuthPass( final String pass ) { 373 authPass = nval( pass, authPass ); 374 } 375 376 /** 377 * メールé€ä¿¡è€?‚¢ãƒ‰ãƒ¬ã‚¹ã‚’è¿”ã—ã¾ã™ã? 378 * 379 * @return é€ä¿¡è€?‚¢ãƒ‰ãƒ¬ã‚¹ 380 */ 381 public String getFromAddr() { 382 return fromAddr; 383 } 384 385 /** 386 * メールタイトルを返ã—ã¾ã™ã? 387 * 388 * @return メールタイトル 389 */ 390 public String getTitle() { 391 return mailTitle; 392 } 393 394 /** 395 * メール本æ–?‚’è¿”ã—ã¾ã™ã? 396 * 397 * @return メール本æ–? 398 */ 399 public String getContent() { 400 return mailContent; 401 } 402 403 /** 404 * é€ä¿¡çµæžœã‚’å±¥æ´ãƒ??ブル(GE32)ã¨å®›å?ãƒ??ブル(GE34)ã«ç™»éŒ²ã—ã¾ã™ã? 405 * 登録時ã«ã€æ¡æ•°ã‚ªãƒ¼ãƒã?ã«ãªã‚‰ãªã?‚ˆã?«ã€ãƒ†ãƒ¼ãƒ–ãƒ«å®šç¾©ã®æ¡æ•°ã‚’上é™ã¨ã—ã¦ã€? 406 * 登録å‰ã«å??ç›®ã®æ¡æ•°æ•´ç?‚’行ã„ã¾ã™ã? 407 * 408 * @og.rev 5.5.5.1 (2012/08/07) リソース系DBID 付ã‘忘れ対ç? 409 */ 410 protected void commitMailDB(){ 411 // å±¥æ´ãƒ??ブルã®è¿½åŠ? 412 String[] insGE32Args = new String[15]; 413 String ykno = getYkno(); 414 insGE32Args[GE32_YKNO] = ykno; 415 insGE32Args[GE32_PARAKEY] = initParamMap.get( "PARAKEY" ); 416 insGE32Args[GE32_PTN_ID] = trim( initParamMap.get( "PTN_ID" ), 20 ); 417 insGE32Args[GE32_FROM_ADDR] = trim( fromAddr, 100); 418 insGE32Args[GE32_TITLE] = trim( mailTitle, 300); 419 insGE32Args[GE32_CONTENTS] = trim( mailContent,4000); // 5.0.3.0 (2009/11/04) CONTENT â‡?CONTENTS 420 insGE32Args[GE32_ATTACH1] = ""; 421 insGE32Args[GE32_ATTACH2] = ""; 422 insGE32Args[GE32_ATTACH3] = ""; 423 insGE32Args[GE32_ATTACH4] = ""; 424 insGE32Args[GE32_ATTACH5] = ""; 425 if ( attachFiles != null ) { 426 int attSize = attachFiles.length; 427 for( int i = 0; i < attSize; i++ ) { 428 insGE32Args[6 + i] = trim( attachFiles[i], 256); 429 } 430 } 431 insGE32Args[GE32_DYSET] = HybsSystem.getDate( "yyyyMMddHHmmss" ); 432 insGE32Args[GE32_USRSET] = initParamMap.get( "LOGIN_USERID" ); 433 insGE32Args[GE32_PGUPD] = initParamMap.get( "PGID" ); 434 insGE32Args[GE32_SYSTEM_ID] = initParamMap.get( "SYSTEM_ID" ); 435 // DBUtil.dbExecute( insGE32, insGE32Args, appInfo ); 436 DBUtil.dbExecute( insGE32, insGE32Args, appInfo, DBID ); // 5.5.5.1 (2012/08/07) 437 438 // å®›å?ãƒ??ブル追åŠ? 439 String[] insGE34Args = new String[10]; 440 insGE34Args[GE34_YKNO]= ykno; 441 for( String dstId : mailDstMap.keySet() ) { 442 insGE34Args[GE34_DST_ID] = trim( mailDstMap.get( dstId )[MailPattern.IDX_DST_ID] , 10 ); 443 insGE34Args[GE34_GROUP_ID] = trim( mailDstMap.get( dstId )[MailPattern.IDX_GROUP_ID], 20 ); 444 insGE34Args[GE34_DST_NAME] = trim( mailDstMap.get( dstId )[MailPattern.IDX_DST_NAME], 20 ); 445 insGE34Args[GE34_DST_ADDR] = trim( mailDstMap.get( dstId )[MailPattern.IDX_DST_ADDR], 100 ); 446 insGE34Args[GE34_DST_KBN] = mailDstMap.get( dstId )[MailPattern.IDX_DST_KBN]; 447 insGE34Args[GE34_FGJ] = mailDstMap.get( dstId )[MailPattern.IDX_FGJ]; 448 insGE34Args[GE34_DYSET] = HybsSystem.getDate( "yyyyMMddHHmmss" ); 449 insGE34Args[GE34_USRSET] = initParamMap.get( "LOGIN_USERID" ); 450 insGE34Args[GE34_PGUPD] = initParamMap.get( "PGID" ); 451 // DBUtil.dbExecute( insGE34, insGE34Args, appInfo ); 452 DBUtil.dbExecute( insGE34, insGE34Args, appInfo, DBID ); // 5.5.5.1 (2012/08/07) 453 } 454 } 455 456 /** 457 * パラメータマップをセãƒ?ƒˆã—ã¾ã™ã? 458 * 459 * @param params パラメータã®ãƒžãƒƒãƒ? 460 */ 461 protected void setInitParams( final Map<String, String> params ) { 462 initParamMap = params; 463 } 464 465 /** 466 * 添付ファイルé…å?ã‚’ã‚»ãƒ?ƒˆã—ã¾ã™ã? 467 * 468 * @param attach1 添付ファイルå? 469 * @param attach2 添付ファイルå? 470 * @param attach3 添付ファイルå? 471 * @param attach4 添付ファイルå? 472 * @param attach5 添付ファイルå? 473 */ 474 protected void setAttachFiles( final String attach1 475 , final String attach2 476 , final String attach3 477 , final String attach4 478 , final String attach5 ) { 479 List<String> fileList = new ArrayList<String>(); 480 if( attach1 != null && attach1.length() != 0 ) { fileList.add( attach1 ); } 481 if( attach2 != null && attach2.length() != 0 ) { fileList.add( attach2 ); } 482 if( attach3 != null && attach3.length() != 0 ) { fileList.add( attach3 ); } 483 if( attach4 != null && attach4.length() != 0 ) { fileList.add( attach4 ); } 484 if( attach5 != null && attach5.length() != 0 ) { fileList.add( attach5 ); } 485 attachFiles = fileList.toArray( new String[fileList.size()] ); 486 } 487 488 /** 489 * メール宛å?マップをセãƒ?ƒˆã—ã¾ã™ã? 490 * 491 * @param mailDst メール宛å?マッãƒ? 492 */ 493 protected void setMailDstMap( final Map<String, String[]> mailDst ) { 494 mailDstMap = mailDst; 495 } 496 497 /** 498 * メール宛å?マップをセãƒ?ƒˆã—ã¾ã™ã? 499 * 500 * @return メール宛å?マッãƒ? 501 */ 502 protected Map<String, String[]> getMailDstMap() { 503 return mailDstMap; 504 } 505 506 /** 507 * æŒ?®šã?é•·ã•以å†??æ–?—å?ã‚’è¿”ã—ã¾ã™ã? 508 * 509 * @param src ã‚ªãƒªã‚¸ãƒŠãƒ«ã®æ–?—å? 510 * @param maxLen æŒ?®šã?é•·ã? 511 * 512 * @return æŒ?®šã?é•·ã•ã«çŸç¸®ã•ã‚ŒãŸæ–‡å—å? 513 */ 514 protected String trim( final String src, final int maxLen ) { 515 String rtn = src; 516 if( src != null && src.length() > maxLen ) { 517 rtn = src.substring( 0, maxLen ); 518 } 519 return rtn; 520 } 521 522 /** 523 * アドレスãƒã‚§ãƒ?‚¯ã®ã‚¨ãƒ©ãƒ¼ãƒªã‚¹ãƒˆã‚’è¿”ã—ã¾ã™ã? 524 * 525 * @return エラーリスãƒ? 526 */ 527 protected List<String> getErrList(){ 528 return errAddrList; 529 } 530 531 /** 532 * å®›å?マップをå…?«ã€??信オブジェクトã«å®›å?ã‚’ã‚»ãƒ?ƒˆã—ã¾ã™ã? 533 * ã‚»ãƒ?ƒˆã™ã‚‹éš›ã«ã€ã‚¢ã‚«ã‚¦ãƒ³ãƒˆã‚¨ãƒ©ãƒ¼ã¨ãªã£ã¦ã?‚‹ã‚¢ãƒ‰ãƒ¬ã‚¹ã‚’除外ã—ã¾ã™ã? 534 * å®›å?ãŒå˜åœ¨ã—ãªã??åˆã?例外を投ã’ã¾ã™ã? 535 * 536 * @og.rev 4.3.7.5 (2009/07/08) é€ä¿¡å…ˆåç§°ãŒè¨å®šã•れã¦ã?ªã??åˆã?ã€ã‚¢ãƒ‰ãƒ¬ã‚¹ã‚?>ã§å›²ã‚ãªã? 537 * 538 * @param invalidAddr å®›å?ã®ãƒªã‚¹ãƒ? 539 */ 540 private void setMailDst( final List<String> invalidAddr ){ 541 ArrayList<String> toList = new ArrayList<String>(); 542 ArrayList<String> ccList = new ArrayList<String>(); 543 ArrayList<String> bccList = new ArrayList<String>(); 544 545 Map<Integer, ArrayList<String>> tempMap = new HashMap<Integer, ArrayList<String>>(); 546 tempMap.put( Integer.valueOf( MailPattern.KBN_TO ), toList ); 547 tempMap.put( Integer.valueOf( MailPattern.KBN_CC ), ccList ); 548 tempMap.put( Integer.valueOf( MailPattern.KBN_BCC ), bccList ); 549 550 for( String dstId : mailDstMap.keySet() ) { 551 String[] dstInfo = mailDstMap.get( dstId ); 552 Integer kbn = Integer.valueOf( dstInfo[MailPattern.IDX_DST_KBN] ); 553 if( !invalidAddr.contains( dstInfo[MailPattern.IDX_DST_ADDR] ) 554 && !FGJ_ADDR_ERR.equals( dstInfo[MailPattern.IDX_FGJ] )){ 555 dstInfo[MailPattern.IDX_FGJ] = FGJ_SEND_OVER; 556 557 // 4.3.7.5 (2009/07/08) 558 String name = dstInfo[MailPattern.IDX_DST_NAME]; 559 if( name != null && name.length() > 0 ) { 560 tempMap.get( kbn ).add( dstInfo[MailPattern.IDX_DST_NAME] + "<"+ dstInfo[MailPattern.IDX_DST_ADDR] + ">" ); 561 } 562 else { 563 tempMap.get( kbn ).add( dstInfo[MailPattern.IDX_DST_ADDR] ); 564 } 565 } 566 else { 567 if( FGJ_SEND_OVER.equals( dstInfo[MailPattern.IDX_FGJ] ) ) { 568 dstInfo[MailPattern.IDX_FGJ] = FGJ_ACNT_ERR; 569 } 570 } 571 } 572 573 mail.clearTo(); // å®›å?(TO)をクリア 574 mail.clearCc(); // å®›å?(CC)をクリア 575 mail.clearBcc(); // å®›å?(BCC)をクリア 576 boolean haveValidAddr = false ; 577 // if( toList.size() > 0 ) { // toã®ã‚»ãƒ?ƒˆ 578 if( ! toList.isEmpty() ) { // toã®ã‚»ãƒ?ƒˆ 579 haveValidAddr = true; 580 String[] to = toList.toArray( new String[toList.size()] ); 581 mail.setTo( to ); 582 } 583 // if( ccList.size() > 0 ) { // ??½??ã‚»ãƒ?ƒˆ 584 if( ! ccList.isEmpty() ) { // ??½??ã‚»ãƒ?ƒˆ 585 haveValidAddr = true; 586 String[] cc = ccList.toArray( new String[ccList.size()] ); 587 mail.setCc( cc ); 588 } 589 // if( bccList.size() > 0 ) { // bccã®ã‚»ãƒ?ƒˆ 590 if( ! bccList.isEmpty() ) { // bccã®ã‚»ãƒ?ƒˆ 591 haveValidAddr = true; 592 String[] bcc = bccList.toArray( new String[bccList.size()] ); 593 mail.setBcc( bcc ); 594 } 595 if( !haveValidAddr ){ // å®›å?全部無効ã®å ´åˆã?例外を投ã’ã¾ã™ã? 596 String errMsg = "å®›å?ã®ãƒ¡ãƒ¼ãƒ«ã‚¢ãƒ‰ãƒ¬ã‚¹ãŒæœ‰åйã§ã¯ã‚りã¾ã›ã‚“ã€? 597 + "TO , CC , BCC ã®ã?¥ã‚Œã«ã‚‚アドレスãŒè¨å®šã•れã¦ã?¾ã›ã‚“ã€?; // 5.1.8.0 (2010/07/01) errMsg ä¿®æ£ 598 throw new RuntimeException( errMsg ); 599 } 600 } 601 602 /** 603 * è¦æ±?Oを採番ã—ã¾ã™ã? 604 * ã“ã?è¦æ±?Oã§å±¥æ´ãƒ??ブル(GE32)ã¨å®›å?ãƒ??ブル(GE30)ã®é–¢é€£ä»˜ã‘ã‚’æŒãŸã›ã¾ã™ã? 605 * 606 * @og.rev 5.5.5.1 (2012/08/07) リソース系DBID 付ã‘忘れ対ç? 607 * 608 * @return è¦æ±?O 609 */ 610 private String getYkno() { 611 // String[][] tmp = DBUtil.dbExecute( selYkno, new String[0], appInfo ); 612 String[][] tmp = DBUtil.dbExecute( selYkno, new String[0], appInfo, DBID ); // 5.5.5.1 (2012/08/07) 613 if( tmp == null || tmp.length == 0 ) { 614 String errMsg = "è¦æ±?O採番エラー" 615 + " SQL=" + selYkno ; // 5.1.8.0 (2010/07/01) errMsg ä¿®æ£ 616 throw new RuntimeException( errMsg ); 617 } 618 return tmp[0][0]; 619 } 620 621 /** 622 * メールアドレスã®ãƒªã‚¹ãƒˆã‚ˆã‚Šãƒ¦ãƒ¼ã‚¶ãƒ¼IDã‚’é?引ãã—ã¾ã™ã? 623 * 624 * @param addressList メールアドレスã®ãƒªã‚¹ãƒ? 625 * 626 * @return ユーザーID 627 */ 628 private String getUserIds( final List<String> addressList ){ 629 StringBuilder idBuf = new StringBuilder(); 630 Map<String,String> addressMap = new HashMap<String, String>(); 631 for( String userId : mailDstMap.keySet() ) { 632 String[] dstInfo = mailDstMap.get( userId ); 633 addressMap.put( dstInfo[MailPattern.IDX_DST_ADDR], userId ); 634 } 635 for(int i=0; i < addressList.size(); i++){ 636 idBuf.append( ',' ).append( addressMap.get( addressList.get( i ) ) ); 637 } 638 String rtn = ""; 639 if ( idBuf.length() > 0 ) { 640 rtn = idBuf.toString().substring( 1 ); 641 } 642 return rtn; 643 } 644 }