Ejemplo n.º 1
0
  /**
   * Fetches all e-mail headers from the server, with appropriate fields already set.
   *
   * @param handler
   * @return ArrayList of MessageHeaders
   * @throws ConnectionException
   */
  public ArrayList fetchAllHeaders() throws SystemException, ConnectionException {
    ArrayList headers = null;
    Folder fold = null;
    try {
      fold = getFolder();
      closeFolder(fold);
      fold = getFolder();

      headers = new ArrayList();
      EmailHeader header = null;

      Message[] msgs = fold.getMessages();
      FetchProfile fp = new FetchProfile();
      fp.add(FetchProfile.Item.ENVELOPE);
      fp.add(FetchProfile.Item.FLAGS);
      fp.add(FetchProfile.Item.CONTENT_INFO);
      fp.add("Size");
      fp.add("Date");
      fold.fetch(msgs, fp);

      Message msg = null;
      for (int i = 0; i < msgs.length; i++) {
        try {
          header = new EmailHeader();
          msg = msgs[i];

          header.setMultipart((msg.isMimeType("multipart/*")) ? true : false);
          header.setMessageId(i + 1);
          header.setFrom(msg.getFrom());
          header.setTo(msg.getRecipients(Message.RecipientType.TO));
          header.setCc(msg.getRecipients(Message.RecipientType.CC));
          header.setBcc(msg.getRecipients(Message.RecipientType.BCC));
          header.setDate(msg.getSentDate());
          header.setReplyTo(msg.getReplyTo());
          header.setSize(msg.getSize());
          header.setSubject(msg.getSubject());

          // now set the human readables.
          header.setDateShown(Formatter.formatDate(header.getDate(), "dd.MM.yyyy HH:mm"));
          header.setFromShown(Utility.addressArrToString(header.getFrom()));
          header.setToShown(Utility.addressArrToString(header.getTo()));
          header.setCcShown(Utility.addressArrToString(header.getCc()));
          header.setSizeShown(Utility.sizeToHumanReadable(header.getSize()));

          // it is time to add it to the arraylist
          headers.add(header);
        } catch (MessagingException e1) {
          System.out.println(
              "Could not parse headers of e-mail. Message might be defuncted or illegal formatted.");
        }
      }
    } catch (Exception e) {
      System.out.println("Could not fetch message headers. Is mbox connection still alive???");
      throw new ConnectionException(e);
    }
    return headers;
  }
Ejemplo n.º 2
0
  /**
   * The doPost method of the servlet. <br>
   * This method is called when a form has its tag value method equals to post.
   *
   * @param request the request send by the client to the server
   * @param response the response send by the server to the client
   * @throws ServletException if an error occurred
   * @throws IOException if an error occurred
   */
  public void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    response.setHeader("Expires", "-1");
    response.setHeader("Pragma", "no-cache");
    response.setHeader("Cache-control", "no-cache");
    response.setHeader("Content-Type", "text/html; charset=utf-8");

    request.setCharacterEncoding("UTF-8");

    ArrayList parts = (ArrayList) request.getSession().getAttribute("attachments");
    if (parts == null) {
      parts = new ArrayList();
    }

    String fileName = null;
    try {
      // Create a factory for disk-based file items
      DiskFileItemFactory factory = new DiskFileItemFactory();

      // Set factory constraints
      factory.setRepository(new File(tmpDir));

      // Create a new file upload handler
      ServletFileUpload upload = new ServletFileUpload(factory);

      // Set overall request size constraint
      upload.setSizeMax(MAX_SIZE);

      // Parse the request
      List items = upload.parseRequest(request);

      Iterator iter = items.iterator();
      while (iter.hasNext()) {
        FileItem item = (FileItem) iter.next();

        if (!item.isFormField()) {
          // String fieldName = item.getFieldName();
          fileName = item.getName();
          // ie6 bug. it sends whole file path as file name. use firefox!
          if (fileName.indexOf("\\") >= 0) {
            fileName = fileName.substring(fileName.lastIndexOf("\\") + 1);
          }

          File uploadDir = WebdiskController.getUploadDir(getAuthProfile(request).getUsername());
          File uploadedFile = new File(uploadDir.getAbsolutePath() + "/" + fileName);
          item.write(uploadedFile);
          uploadedFile = null;

          if (fileName.indexOf("\\") > 0) {
            fileName = fileName.substring(fileName.lastIndexOf("\\") + 1);
          }
          item.delete();
        }
      }
      response.sendRedirect("../upload_file_ok.jsp?result=0");
    } catch (SizeLimitExceededException e) {
      // attachment exceeded the attachment upload size limit
      response.sendRedirect(
          "../upload_file_ok.jsp?result=1&maxAttSize=" + Utility.sizeToHumanReadable(MAX_SIZE));
    } catch (Exception e) {
      response.sendRedirect("../upload_file_ok.jsp?result=3");
    }
  }
Ejemplo n.º 3
0
  /**
   * Fetches all e-mail headers from the server, with appropriate fields already set.
   *
   * @param handler
   * @return ArrayList of MessageHeaders
   * @throws ConnectionException
   */
  public ArrayList fetchAllHeaders() throws SystemException, ConnectionException {
    ArrayList headers = new ArrayList();
    Folder fold = null;
    try {
      fold = getFolder();
      EmailHeader header = null;

      Message[] msgs = fold.getMessages();
      FetchProfile fp = new FetchProfile();
      fp.add(FetchProfile.Item.ENVELOPE);
      fp.add(FetchProfile.Item.FLAGS);
      fp.add(FetchProfile.Item.CONTENT_INFO);
      fp.add("Size");
      fp.add("Date");
      fp.add("Disposition-Notification-To");
      fp.add("X-Priority");
      fp.add("X-MSMail-Priority");
      fp.add("Sensitivity");
      fold.fetch(msgs, fp);

      Message msg = null;
      for (int i = 0; i < msgs.length; i++) {
        try {
          header = new EmailHeader();
          msg = msgs[i];

          header.setMultipart((msg.isMimeType("multipart/*")) ? true : false);
          header.setMessageId(i + 1);
          header.setFrom(msg.getFrom());
          header.setTo(msg.getRecipients(Message.RecipientType.TO));
          header.setCc(msg.getRecipients(Message.RecipientType.CC));
          header.setBcc(msg.getRecipients(Message.RecipientType.BCC));
          header.setDate(msg.getSentDate());
          header.setReplyTo(msg.getReplyTo());
          header.setSize(msg.getSize());
          header.setSubject(org.claros.commons.utility.Utility.updateTRChars(msg.getSubject()));

          // now set the human readables.
          header.setDateShown(Formatter.formatDate(header.getDate(), "dd.MM.yyyy HH:mm"));
          header.setFromShown(
              org.claros.commons.utility.Utility.updateTRChars(
                  Utility.addressArrToStringShort(header.getFrom())));
          header.setToShown(Utility.addressArrToStringShort(header.getTo()));
          header.setCcShown(Utility.addressArrToStringShort(header.getCc()));
          header.setSizeShown(Utility.sizeToHumanReadable(header.getSize()));

          org.claros.commons.mail.parser.MessageParser.setHeaders(msg, header);

          boolean deleted = false;
          if (profile.getProtocol().equals(Constants.IMAP)) {
            Flags.Flag flags[] = msg.getFlags().getSystemFlags();
            if (flags != null) {
              Flags.Flag flag = null;
              for (int m = 0; m < flags.length; m++) {
                flag = flags[m];
                if (flag.equals(Flags.Flag.SEEN)) {
                  header.setUnread(new Boolean(false));
                }

                if (flag.equals(Flags.Flag.DELETED)) {
                  deleted = true;
                }
              }
            }
          }
          if (header.getUnread() == null) {
            header.setUnread(new Boolean(true));
          }

          // it is time to add it to the arraylist
          if (!deleted) {
            headers.add(header);
          }
        } catch (MessagingException e1) {
          log.error(
              "Could not parse headers of e-mail. Message might be defuncted or illegal formatted.",
              e1);
        }
      }
    } catch (MessagingException e) {
      log.error("Could not fetch message headers. Is mbox connection still alive???", e);
      //			throw new ConnectionException(e);
    } catch (Exception e) {
      log.error("Could not fetch message headers. Is mbox connection still alive???", e);
      //			throw new ConnectionException(e);
    }
    return headers;
  }