title: JavaMail MimeBodyPart.SaveFile provide corrupted files
body: <p>I'm using JavaMail Library to parser email mime message.
  I'm trying to extract the attached files and save them to the local disk but the saved files are not valid and their size is different from the original. only *.txt file are saved ok but *.PDF or *.xlsx are not.
  Can you please help me to fix the code?</p>
  
  <p>My code is:</p>
  
  <pre><code>private static void Test3() {
          String email_string = File_Reader.Read_File_To_String("D:\\8.txt");
          MimeMessage mm = Email_Parser.Get_MIME_Message_From_Email_String(email_string);
  
          Email_Parser.Save_Email_Attachments_To_Folder(mm,"D:\\TEST");
      }
  
  public static String Read_File_To_String(String file_path) {
      byte[] encoded = new byte[0];
  
      try {
          encoded = Files.readAllBytes(Paths.get(file_path));
      } catch (IOException exception) {
          Print_To_Console(exception.getMessage(), true,false);
      }
  
      return new String(encoded, m_encoding);
  }
  
  public static MimeMessage Get_MIME_Message_From_Email_String(String email_string) {
      MimeMessage mm = null;
  
      try {
          Session s = Session.getDefaultInstance(new Properties());
          InputStream is = new ByteArrayInputStream(email_string.getBytes());
          mm = new MimeMessage(s, is);
      } catch (MessagingException exception) {
          Print_To_Console(exception.getMessage(), true, false);
      }
      return mm;
  }
  
  public static void Save_Email_Attachments_To_Folder(MimeMessage mm, String output_folder_path) {
          ArrayList&lt;Pair&lt;String, InputStream&gt;&gt; attachments_InputStreams = Get_Attachments_InputStream_From_MimeMessage(mm);
          String attachment_filename;
          String attachment_filename_save_path;
          InputStream attachment_InputStream;
          MimeBodyPart mbp;
  
          for (Pair&lt;String, InputStream&gt; attachments_InputStream : attachments_InputStreams) {
              attachment_filename = attachments_InputStream.getKey();
              attachment_filename = Get_Encoded_String(attachment_filename);
              attachment_filename_save_path = String.format("%s\\%s", output_folder_path, attachment_filename);
              attachment_InputStream = attachments_InputStream.getValue();
  
              try {
                  mbp = new MimeBodyPart(attachment_InputStream);
                  mbp.saveFile(attachment_filename_save_path);
              } catch (MessagingException | IOException exception) {
                  Print_To_Console(exception.getMessage(), true, false);
              }
          }
      }
  </code></pre>