diff --git a/pom.xml b/pom.xml index 0b77f5bf5..ff1833367 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.support-project knowledge war - 0.4.5 + 0.4.6 webapp for knowledge https://support-project.org/ @@ -17,7 +17,7 @@ org.support-project web - 0.4.5 + 0.4.6 diff --git a/src/main/java/org/support/project/knowledge/bat/MailSendBat.java b/src/main/java/org/support/project/knowledge/bat/MailSendBat.java index 4095e5362..5984bf376 100644 --- a/src/main/java/org/support/project/knowledge/bat/MailSendBat.java +++ b/src/main/java/org/support/project/knowledge/bat/MailSendBat.java @@ -41,15 +41,23 @@ public class MailSendBat { public static final int MAIL_STATUS_UNSENT = 0; /** メールの状態:送信済 */ public static final int MAIL_STATUS_SENDED = 10; - + /** メールの状態:なんらかのエラーが発生した */ + public static final int MAIL_STATUS_ERROR = -1; + /** メールの状態:アドレスのフォーマットエラー */ + public static final int MAIL_STATUS_FORMAT_ERROR = -2; + + public static final String MAIL_FORMAT = "^[a-zA-Z0-9!#$%&'_`/=~\\*\\+\\-\\?\\^\\{\\|\\}]+(\\.[a-zA-Z0-9!#$%&'_`/=~\\*\\+\\-\\?\\^\\{\\|\\}]+)*" + + "@" + "[a-zA-Z0-9][a-zA-Z0-9\\-]*(\\.[a-zA-Z0-9\\-]+)*$"; + public static void main(String[] args) throws Exception { MailSendBat bat = new MailSendBat(); bat.start(); - + } - + /** * メール送信処理の実行 + * * @throws UnsupportedEncodingException * @throws MessagingException * @throws InvalidKeyException @@ -58,99 +66,118 @@ public static void main(String[] args) throws Exception { * @throws IllegalBlockSizeException * @throws BadPaddingException */ - public void start() throws UnsupportedEncodingException, MessagingException, InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException { + public void start() throws UnsupportedEncodingException, MessagingException, InvalidKeyException, NoSuchAlgorithmException, + NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException { MailConfigsDao mailConfigsDao = MailConfigsDao.get(); MailConfigsEntity mailConfigsEntity = mailConfigsDao.selectOnKey(org.support.project.knowledge.config.AppConfig.SYSTEM_NAME); if (mailConfigsEntity == null) { // メールの設定が登録されていなければ、送信処理は終了 return; } - + MailsDao dao = MailsDao.get(); List entities = dao.selectOnStatus(MAIL_STATUS_UNSENT); int count = 0; for (MailsEntity mailsEntity : entities) { - mailSend(mailConfigsEntity, mailsEntity); + if (mailsEntity.getToAddress().matches(MAIL_FORMAT)) { + mailSend(mailConfigsEntity, mailsEntity); + } else { + mailsEntity.setStatus(MAIL_STATUS_FORMAT_ERROR); + dao.save(mailsEntity); + } count++; } LOG.info("MAIL sended. count: " + count); } - + /** * メールを送信 - * @param config + * + * @param config * @param entity - * @throws MessagingException - * @throws UnsupportedEncodingException - * @throws BadPaddingException - * @throws IllegalBlockSizeException - * @throws NoSuchPaddingException - * @throws NoSuchAlgorithmException - * @throws InvalidKeyException + * @throws MessagingException + * @throws UnsupportedEncodingException + * @throws BadPaddingException + * @throws IllegalBlockSizeException + * @throws NoSuchPaddingException + * @throws NoSuchAlgorithmException + * @throws InvalidKeyException */ - private void mailSend(MailConfigsEntity config, MailsEntity entity) throws MessagingException, UnsupportedEncodingException, InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException { - String host = config.getHost(); - String port = String.valueOf(config.getPort()); - - String to = entity.getToAddress(); - String toName = entity.getToName(); - - String from = entity.getFromAddress(); - String fromName = entity.getFromName(); - if (StringUtils.isEmpty(from)) { - from = config.getFromAddress(); - } - if (StringUtils.isEmpty(fromName)) { - fromName = config.getFromName(); - } - - String title = entity.getTitle(); - String message = entity.getContent(); - - Properties property = new Properties(); - property.put("mail.smtp.host", host); - property.put("mail.smtp.port", port); - property.put("mail.smtp.socketFactory.port", port); - property.put("mail.smtp.debug", "true"); - - Session session; - if (1 == config.getAuthType()) { - // 認証あり - final String smtpid = config.getSmtpId(); - final String smtppass = PasswordUtil.decrypt(config.getSmtpPassword(), config.getSalt()); - - property.put("mail.smtp.auth", "true"); - property.put("mail.smtp.starttls.enable", "true"); - property.put("mail.smtp.ssl.trust", host); - - session = Session.getInstance(property, new javax.mail.Authenticator() { - protected PasswordAuthentication getPasswordAuthentication() { - return new PasswordAuthentication(smtpid, smtppass); - } - }); - } else { - // 認証無し - session = Session.getDefaultInstance(property); - } + private void mailSend(MailConfigsEntity config, MailsEntity entity) throws MessagingException, UnsupportedEncodingException, InvalidKeyException, + NoSuchAlgorithmException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException { + try { + String host = config.getHost(); + String port = String.valueOf(config.getPort()); - MimeMessage mimeMessage = new MimeMessage(session); - InternetAddress toAddress = new InternetAddress(to, toName, "ISO-2022-JP"); - mimeMessage.setRecipient(Message.RecipientType.TO, toAddress); - InternetAddress fromAddress = new InternetAddress(from, fromName, "ISO-2022-JP"); - mimeMessage.setFrom(fromAddress); - mimeMessage.setSubject(title, "ISO-2022-JP"); - mimeMessage.setText(message, "ISO-2022-JP"); - - // メールの形式を指定 - // mimeMessage.setHeader( "Content-Type", "text/html" ); - // 送信日付を指定 - mimeMessage.setSentDate( new Date() ); - Transport.send(mimeMessage); - LOG.debug("Mail sended."); - - // ステータス更新 - MailsDao dao = MailsDao.get(); - entity.setStatus(MAIL_STATUS_SENDED); - dao.save(entity); + String to = entity.getToAddress(); + String toName = entity.getToName(); + + String from = entity.getFromAddress(); + String fromName = entity.getFromName(); + if (StringUtils.isEmpty(from)) { + from = config.getFromAddress(); + } + if (StringUtils.isEmpty(fromName)) { + fromName = config.getFromName(); + } + + String title = entity.getTitle(); + String message = entity.getContent(); + + Properties property = new Properties(); + property.put("mail.smtp.host", host); + property.put("mail.smtp.port", port); + property.put("mail.smtp.socketFactory.port", port); + property.put("mail.smtp.debug", "true"); + + Session session; + if (1 == config.getAuthType()) { + // 認証あり + final String smtpid = config.getSmtpId(); + final String smtppass = PasswordUtil.decrypt(config.getSmtpPassword(), config.getSalt()); + + property.put("mail.smtp.auth", "true"); + property.put("mail.smtp.starttls.enable", "true"); + property.put("mail.smtp.ssl.trust", host); + + session = Session.getInstance(property, new javax.mail.Authenticator() { + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(smtpid, smtppass); + } + }); + } else { + // 認証無し + session = Session.getDefaultInstance(property); + } + + MimeMessage mimeMessage = new MimeMessage(session); + InternetAddress toAddress = new InternetAddress(to, toName, "ISO-2022-JP"); + mimeMessage.setRecipient(Message.RecipientType.TO, toAddress); + InternetAddress fromAddress = new InternetAddress(from, fromName, "ISO-2022-JP"); + mimeMessage.setFrom(fromAddress); + mimeMessage.setSubject(title, "ISO-2022-JP"); + mimeMessage.setText(message, "ISO-2022-JP"); + + // メールの形式を指定 + // mimeMessage.setHeader( "Content-Type", "text/html" ); + // 送信日付を指定 + mimeMessage.setSentDate(new Date()); + + Transport.send(mimeMessage); + LOG.debug("Mail sended."); + + // ステータス更新 + MailsDao dao = MailsDao.get(); + entity.setStatus(MAIL_STATUS_SENDED); + dao.save(entity); + } catch (Exception e) { + //TODO メール送信失敗、二度と送らないようにする(リトライする?) + // 未送信にしておけば、再送できるが永遠に再送してしまう + // カウント制御するべきか? + LOG.error("Mail send error", e); + MailsDao dao = MailsDao.get(); + entity.setStatus(MAIL_STATUS_ERROR); + dao.save(entity); + } } } diff --git a/src/main/resources/appresource.properties b/src/main/resources/appresource.properties index 0e4f00957..927c19ab5 100644 --- a/src/main/resources/appresource.properties +++ b/src/main/resources/appresource.properties @@ -51,7 +51,7 @@ message.success.save.target={1} was Saved. message.allready.updated=Allready updated. # Common Label -label.version=0.4.5 +label.version=0.4.6 label.login=Sign in label.previous = Previous label.next=Next diff --git a/src/main/resources/appresource_ja.properties b/src/main/resources/appresource_ja.properties index 35aabd663..d21b9c753 100644 --- a/src/main/resources/appresource_ja.properties +++ b/src/main/resources/appresource_ja.properties @@ -51,7 +51,7 @@ message.success.save.target={1} \u4fdd\u5b58\u3057\u307e\u3057\u305f\u3002 message.allready.updated=\u3059\u3067\u306b\u66f4\u65b0\u3055\u308c\u3066\u3044\u307e\u3059 # Common Label -label.version=0.4.5 +label.version=0.4.6 label.login=\u30b5\u30a4\u30f3\u30a4\u30f3 label.previous = \u524d\u3078 label.next = \u6b21\u3078 diff --git a/src/main/webapp/js/knowledge-list.js b/src/main/webapp/js/knowledge-list.js index 02bb0ea7e..13dd1d2a8 100644 --- a/src/main/webapp/js/knowledge-list.js +++ b/src/main/webapp/js/knowledge-list.js @@ -20,6 +20,12 @@ $(document).ready(function() { }); */ + $('.thumbnail').hover(function() { + $(this).css('border', '1px solid gray'); + }, function() { + $(this).css('border', '0px solid #ccc'); + }); + $('#input_tags').on('beforeItemRemove', function(event) { event.cancel = true; }); @@ -27,7 +33,7 @@ $(document).ready(function() { }); var showKnowledge = function(id, offset, keyword, tag, user) { - $('#discription_' + id).slideDown(20); + //$('#discription_' + id).slideDown(20); var url = _CONTEXT + '/open.knowledge/view/' + id; var param = '';