Пример #1
0
  /**
   * @param rundata
   * @param context
   * @param msgList
   * @return
   * @throws ALPageNotFoundException
   * @throws ALDBErrorException
   */
  @Override
  protected boolean setFormData(RunData rundata, Context context, List<String> msgList)
      throws ALPageNotFoundException, ALDBErrorException {

    boolean res = super.setFormData(rundata, context, msgList);

    if (accountId <= 0 || userId <= 0) {
      return res;
    }
    try {
      fileuploadList = FileuploadUtils.getFileuploadList(rundata);
      // Body
      // オブジェクトモデルを取得
      EipMMailAccount account = ALMailUtils.getMailAccount(userId, accountId);
      // 署名を本文に追加
      if (!ALEipConstants.MODE_INSERT.equals(rundata.getParameters().get(ALEipConstants.MODE))
          && account.getSignature() != null
          && !"".equals(account.getSignature())) {
        StringBuffer bodybuf = new StringBuffer();
        if (body.getValue() != null) {
          bodybuf.append(body.getValue());
        }
        bodybuf.append("\r\n\r\n\r\n");
        bodybuf.append(account.getSignature());
        body.setValue(bodybuf.toString());
      }
    } catch (Exception ex) {
      logger.error("webmail", ex);
    }

    return res;
  }
Пример #2
0
  /**
   * タスク担当者へ通知メールを送る
   *
   * @param taskId タスクID
   * @return 成否
   */
  public static boolean sendMailForTaskMembers(
      RunData rundata,
      Context context,
      EipTProjectTask task,
      EipTProject project,
      List<ProjectTaskMemberResultData> mailUserList) {

    String orgId = Database.getDomainName();
    String subject =
        "["
            + ALOrgUtilsService.getAlias()
            + "]"
            + ALLocalizationUtils.getl10n("PROJECT_MAIL_TITLE");

    try {
      List<ALEipUser> memberList = new ArrayList<ALEipUser>();
      for (ProjectTaskMemberResultData rd : mailUserList) {
        memberList.add(ALEipUtils.getALEipUser(rd.getUserId().getValueWithInt()));
      }

      List<ALEipUserAddr> destMemberList =
          ALMailUtils.getALEipUserAddrs(memberList, ALEipUtils.getUserId(rundata), false);

      List<ALAdminMailMessage> messageList = new ArrayList<ALAdminMailMessage>();
      for (ALEipUserAddr destMember : destMemberList) {
        ALAdminMailMessage message = new ALAdminMailMessage(destMember);
        message.setPcSubject(subject);
        message.setCellularSubject(subject);
        message.setPcBody(createTaskMemberMsg(rundata, message.getPcMailAddr(), task, project));
        message.setCellularBody(
            createTaskMemberMsg(rundata, message.getCellMailAddr(), task, project));
        messageList.add(message);
      }

      ALMailService.sendAdminMailAsync(
          new ALAdminMailContext(
              orgId,
              ALEipUtils.getUserId(rundata),
              messageList,
              ALMailUtils.getSendDestType(ALMailUtils.KEY_MSGTYPE_WORKFLOW)));

    } catch (Exception ex) {
      logger.error("project", ex);
      return false;
    }
    return true;
  }
Пример #3
0
  /**
   * 送信するメールの内容を作成する.
   *
   * @return
   */
  public static String createTaskMemberMsg(
      RunData rundata, String addr, EipTProjectTask task, EipTProject project) {
    VelocityContext context = new VelocityContext();
    boolean enableAsp = JetspeedResources.getBoolean("aipo.asp", false);
    String CR = ALMailUtils.CR;

    context.put("user_email", addr);

    // (さんの申請は承認されました。など)
    StringBuffer message = new StringBuffer("");
    message.append(CR);
    message
        .append(getl10nFormat("PROJECT_MAIL_TEXT", project.getProjectName(), task.getTaskName()))
        .append(CR);
    context.put("message", message);

    // サービス
    context.put("serviceAlias", ALOrgUtilsService.getAlias());
    // サービス(Aipo)へのアクセス
    context.put("enableAsp", enableAsp);
    context.put("globalurl", ALMailUtils.getGlobalurl());
    context.put("localurl", ALMailUtils.getLocalurl());
    CustomLocalizationService locService =
        (CustomLocalizationService) ServiceUtil.getServiceByName(LocalizationService.SERVICE_NAME);
    String lang = locService.getLocale(rundata).getLanguage();
    StringWriter writer = new StringWriter();
    try {
      if (lang != null && lang.equals("ja")) {
        Template template =
            Velocity.getTemplate(
                "portlets/mail/" + lang + "/project-notification-mail.vm", "utf-8");
        template.merge(context, writer);
      } else {
        Template template =
            Velocity.getTemplate("portlets/mail/project-notification-mail.vm", "utf-8");
        template.merge(context, writer);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    writer.flush();
    String ret = writer.getBuffer().toString();
    return ret;
  }
Пример #4
0
 public String getAccountName() {
   return ALMailUtils.getAccountName(userId, accountId);
 }
Пример #5
0
  /**
   * @param rundata
   * @param context
   * @param msgList
   * @return
   */
  @Override
  protected boolean loadFormData(RunData rundata, Context context, List<String> msgList) {

    mailType.setValue(rundata.getParameters().getInt(WebMailUtils.MAIL_TYPE, TYPE_NEW_MAIL));

    try {
      ALLocalMailMessage msg =
          (ALLocalMailMessage)
              WebMailUtils.getSelectedLocalMailMessage(
                  rundata, context, (int) getMailType().getValue());
      if (msg == null) {
        return false;
      }

      String tmpSubject = null;
      if (getMailType().getValue() == TYPE_NEW_MAIL) {
        // unreachable flow
        // TO
        Address[] tos = msg.getRecipients(Message.RecipientType.TO);
        this.setTo(ALMailUtils.getAddressString(tos));

        // CC
        Address[] ccs = msg.getRecipients(Message.RecipientType.CC);
        this.setCc(ALMailUtils.getAddressString(ccs));
        // BCC
        Address[] bccs = msg.getRecipients(Message.RecipientType.BCC);
        this.setBcc(ALMailUtils.getAddressString(bccs));

        tmpSubject = msg.getSubject();
      } else if (getMailType().getValue() == TYPE_REPLY_MAIL) {
        // TO
        this.setTo(ALMailUtils.getFromDelegateExtract(msg));
        tmpSubject = "Re: " + msg.getSubject();
      } else if (getMailType().getValue() == TYPE_FORWARD_MAIL) {
        tmpSubject = "Fwd: " + msg.getSubject();
      } else if (getMailType().getValue() == TYPE_REPLY_ALL_MAIL) {
        // TO
        Address[] from = ALMailUtils.getFromDelegateExtractForAddress(msg);
        Address[] to = msg.getRecipients(Message.RecipientType.TO, false);

        EipMMailAccount myaccount = ALMailUtils.getMailAccount(userId, accountId);
        String myaddress = myaccount.getMailAddress();

        List<Address> allList = new ArrayList<Address>();
        allList.addAll(Arrays.asList(from));
        allList.addAll(Arrays.asList(to));
        List<Address> replayList = new ArrayList<Address>();
        for (Address address : allList) {
          if (address instanceof InternetAddress) {
            InternetAddress internetAddress = (InternetAddress) address;
            String email = internetAddress.getAddress();
            if (email != null
                && !email.equalsIgnoreCase(myaddress)
                && !email.contains("<" + myaddress + ">")) {
              replayList.add(address);
            }
          }
        }
        this.setTo(
            ALMailUtils.getAddressString(replayList.toArray(new Address[replayList.size()])));

        // CC
        Address[] ccs = msg.getRecipients(Message.RecipientType.CC, false);
        this.setCc(ALMailUtils.getAddressString(ccs));

        // BCC
        Address[] bccs = msg.getRecipients(Message.RecipientType.BCC);
        this.setBcc(ALMailUtils.getAddressString(bccs));

        tmpSubject = "Re: " + msg.getSubject();
      }

      // Subject
      this.setSubject(tmpSubject);

      // 返信の原文付与
      String[] tmp2 = msg.getBodyTextArray();

      StringBuffer replies = new StringBuffer();
      replies.append("\r\n\r\n\r\n" + "------Original Message-------\r\n");
      if (tmp2 != null) {
        for (String factor : tmp2) {
          replies.append("> " + factor + "\r\n");
        }
      }

      // Body
      try {
        // オブジェクトモデルを取得
        EipMMailAccount account = ALMailUtils.getMailAccount(userId, accountId);
        // 署名と返信とを本文に追加
        if (account.getSignature() != null && !"".equals(account.getSignature())) {
          body.setValue(replies + "\r\n\r\n\r\n" + account.getSignature());
        } else {
          body.setValue(replies.toString());
        }
      } catch (Exception ex) {
        logger.error("webmail", ex);
      }

      if (getMailType().getValue() == TYPE_FORWARD_MAIL) {
        msg =
            (ALLocalMailMessage)
                WebMailUtils.getSelectedLocalMailMessage(rundata, context, TYPE_NEW_MAIL);
        if (msg == null) {
          return false;
        }
        String[] filenames = msg.getAttachmentFileNameArray();
        if (filenames != null && filenames.length > 0) {
          /** 添付ファイルを含んだメールを転送する */
          if (folderName == null || folderName.equals("")) {
            folderName = "undefined";
          }

          for (int i = 0; i < filenames.length; i++) {
            /** 各々の添付ファイルを、一度ファイルに書き出して再度添付する */
            int fileId = Long.valueOf(System.nanoTime()).intValue();
            String newAttachmentFileName = String.valueOf(fileId);
            String realfilename = filenames[i];

            if (realfilename == null) {
              continue;
            }

            ALStorageService.createNewTmpFile(
                msg.getInputStream(i), userId, folderName, newAttachmentFileName, realfilename);

            FileuploadLiteBean filebean = new FileuploadLiteBean();
            filebean.initField();
            filebean.setFileId(fileId);
            filebean.setFileName(realfilename);
            filebean.setFolderName(folderName);
            fileuploadList.add(filebean);
          }
        }
      }
      return true;
    } catch (Exception e) {
      logger.error("webmail", e);
      return false;
    }
  }
Пример #6
0
  /**
   * @param rundata
   * @param context
   * @param msgList
   * @return
   */
  @Override
  protected boolean insertFormData(RunData rundata, Context context, List<String> msgList) {

    String[] attachmentFilepaths = null;
    try {
      FileuploadLiteBean filebean = null;
      boolean hasAttachments = (fileuploadList != null && fileuploadList.size() > 0);
      if (hasAttachments) {
        int size = fileuploadList.size();
        attachmentFilepaths = new String[size];
        for (int i = 0; i < size; i++) {
          filebean = fileuploadList.get(i);
          attachmentFilepaths[i] =
              ALStorageService.getDocumentPath(
                      FileuploadUtils.FOLDER_TMP_FOR_ATTACHMENT_FILES,
                      userId + ALStorageService.separator() + folderName)
                  + ALStorageService.separator()
                  + filebean.getFileId();
        }
      }

      // 件名の値を検証
      if (subject.getValue() == null || subject.getValue().equals("")) {
        subject.setValue("無題");
      }

      // 返信メールの場合は,ヘッダを追加する.
      Map<String, String> map = null;
      if (getMailType().getValue() == TYPE_REPLY_MAIL
          || getMailType().getValue() == TYPE_REPLY_ALL_MAIL) {
        ALLocalMailMessage msg = null;
        try {
          msg =
              (ALLocalMailMessage)
                  WebMailUtils.getSelectedLocalMailMessage(
                      rundata, context, (int) getMailType().getValue());
          if (msg == null) {
            return false;
          }
        } catch (Exception e) {
          return false;
        }
        String in_reply_tos = msg.getMessageID();
        StringBuffer reference = new StringBuffer();
        String[] references = msg.getHeader("References");
        map = new LinkedHashMap<String, String>();
        if (references != null && references.length > 0) {
          reference.append(ALMailUtils.getOneString(references, " "));
        }
        if (in_reply_tos != null && (!in_reply_tos.equals(""))) {
          map.put("In-Reply-To", in_reply_tos);
          reference.append(" ").append(in_reply_tos);
        }

        map.put("References", reference.toString());
      }

      if (map != null && map.size() == 0) {
        map = null;
      }

      String delim = ",;";

      // オブジェクトモデルを取得
      EipMMailAccount account = ALMailUtils.getMailAccount(userId, accountId);

      ALMailHandler handler = ALMailFactoryService.getInstance().getMailHandler();
      // 送信サーバ情報
      ALMailSenderContext scontext = ALMailUtils.getALSmtpMailSenderContext(orgId, account);

      // 送信メッセージのコンテキスト
      ALSmtpMailContext mailcontext =
          ALMailUtils.getALSmtpMailContext(
              ALMailUtils.getTokens(ALStringUtil.unsanitizing(to.getValue()), delim),
              ALMailUtils.getTokens(ALStringUtil.unsanitizing(cc.getValue()), delim),
              ALMailUtils.getTokens(ALStringUtil.unsanitizing(bcc.getValue()), delim),
              account.getMailAddress(),
              ALStringUtil.unsanitizing(account.getMailUserName()),
              ALStringUtil.unsanitizing(subject.getValue()),
              ALStringUtil.unsanitizing(body.getValue()),
              attachmentFilepaths,
              map);

      int success_send = handler.send(scontext, mailcontext);

      if (success_send == ALSmtpMailSender.SEND_MSG_SUCCESS) {
        if (hasAttachments) {
          // 添付ファイル保存先のフォルダを削除
          ALStorageService.deleteTmpFolder(userId, folderName);
        }
      } else {
        if (success_send == ALSmtpMailSender.SEND_MSG_FAIL) {
          msgList.add("メールを送信できませんでした。アカウント設定が間違っている可能性があります。");
        } else if (success_send == ALSmtpMailSender.SEND_MSG_OVER_MAIL_MAX_SIZE) {
          msgList.add(
              String.valueOf(FileuploadUtils.getMaxFileSize()).concat("MB を超えるサイズのメールは送信できません。"));
        } else if (success_send == ALSmtpMailSender.SEND_MSG_FAIL_SMTP_AUTH) {
          msgList.add("メールを送信できませんでした。SMTP認証の認証に失敗しました。");
        }

        return false;
      }
    } catch (Exception e) {
      logger.error("webmail", e);
      msgList.add("メールを送信できませんでした。アカウント設定が間違っている可能性があります。");
      return false;
    }
    return true;
  }