Пример #1
0
  @Override
  protected boolean processFile(AbstractFile file, Object recurseParams) {
    if (getState() == INTERRUPTED) return false;

    // Send file attachment
    try {
      sendAttachment(file);
    } catch (IOException e) {
      showErrorDialog(Translator.get("email.send_file_error", file.getName()));
      return false;
    }

    // If this was the last file, notify the mail server that the mail is over
    if (getCurrentFileIndex() == getNbFiles() - 1) {
      try {
        // Say goodbye to the server
        sayGoodBye();
      } catch (IOException e) {
        showErrorDialog(Translator.get("email.goodbye_failed"));
        return false;
      }
    }

    return true;
  }
Пример #2
0
  /**
   * Send file as attachment encoded in Base64, and returns true if file was successfully and
   * completely transferred.
   */
  private void sendAttachment(AbstractFile file) throws IOException {
    InputStream fileIn = null;
    try {
      // Send MIME type of attachment file
      String mimeType = MimeTypes.getMimeType(file);
      // Default mime type
      if (mimeType == null) mimeType = "application/octet-stream";
      writeLine("Content-Type:" + mimeType + "; name=" + file.getName());
      writeLine("Content-Disposition: attachment;filename=\"" + file.getName() + "\"");
      writeLine("Content-transfer-encoding: base64\r\n");
      fileIn = setCurrentInputStream(file.getInputStream());

      // Write file to socket
      StreamUtils.copyStream(fileIn, out64);

      // Writes padding bytes without closing the stream.
      out64.writePadding();

      writeLine("\r\n--" + boundary);
    } finally {
      if (fileIn != null) fileIn.close();
    }
  }