Program: 52506
Project: 52506
Buggy source:
static void outputBodyPart(OutputStream out,BodyPart bodyPart,String defaultContentTransferEncoding) throws MessagingException, IOException {
  if (bodyPart instanceof MimeBodyPart) {
    MimeBodyPart mimePart=(MimeBodyPart)bodyPart;
    String[] cte=mimePart.getHeader("String_Node_Str");
    String contentTransferEncoding;
    if (mimePart.getContent() instanceof MimeMultipart) {
      MimeMultipart mp=(MimeMultipart)bodyPart.getContent();
      ContentType contentType=new ContentType(mp.getContentType());
      String boundary="String_Node_Str" + contentType.getParameter("String_Node_Str");
      SMIMEUtil.LineOutputStream lOut=new SMIMEUtil.LineOutputStream(out);
      Enumeration headers=mimePart.getAllHeaderLines();
      while (headers.hasMoreElements()) {
        String header=(String)headers.nextElement();
        lOut.writeln(header);
      }
      lOut.writeln();
      outputPreamble(lOut,mimePart,boundary);
      for (int i=0; i < mp.getCount(); i++) {
        lOut.writeln(boundary);
        BodyPart part=mp.getBodyPart(i);
        outputBodyPart(out,part,defaultContentTransferEncoding);
        if (!(part.getContent() instanceof MimeMultipart)) {
          lOut.writeln();
        }
 else {
          outputPostamble(lOut,mimePart,boundary,part);
        }
      }
      lOut.writeln(boundary + "String_Node_Str");
      outputPostamble(lOut,mimePart,mp.getCount(),boundary);
      return;
    }
    if (cte == null) {
      contentTransferEncoding=defaultContentTransferEncoding;
    }
 else {
      contentTransferEncoding=cte[0];
    }
    if (!contentTransferEncoding.equalsIgnoreCase("String_Node_Str") && !contentTransferEncoding.equalsIgnoreCase("String_Node_Str")) {
      if (!contentTransferEncoding.equalsIgnoreCase("String_Node_Str")) {
        out=new CRLFOutputStream(out);
      }
      bodyPart.writeTo(out);
      out.flush();
      return;
    }
    boolean base64=contentTransferEncoding.equalsIgnoreCase("String_Node_Str");
    InputStream inRaw;
    try {
      inRaw=mimePart.getRawInputStream();
    }
 catch (    MessagingException e) {
      out=new CRLFOutputStream(out);
      bodyPart.writeTo(out);
      out.flush();
      return;
    }
    LineOutputStream outLine=new LineOutputStream(out);
    for (Enumeration e=mimePart.getAllHeaderLines(); e.hasMoreElements(); ) {
      String header=(String)e.nextElement();
      outLine.writeln(header);
    }
    outLine.writeln();
    outLine.flush();
    OutputStream outCRLF;
    if (base64) {
      outCRLF=new Base64CRLFOutputStream(out);
    }
 else {
      outCRLF=new CRLFOutputStream(out);
    }
    byte[] buf=new byte[BUF_SIZE];
    int len;
    while ((len=inRaw.read(buf,0,buf.length)) > 0) {
      outCRLF.write(buf,0,len);
    }
    outCRLF.flush();
  }
 else {
    if (!defaultContentTransferEncoding.equalsIgnoreCase("String_Node_Str")) {
      out=new CRLFOutputStream(out);
    }
    bodyPart.writeTo(out);
    out.flush();
  }
}

Fixed version (ground truth):
static void outputBodyPart(OutputStream out,boolean topLevel,BodyPart bodyPart,String defaultContentTransferEncoding) throws MessagingException, IOException {
  if (bodyPart instanceof MimeBodyPart) {
    MimeBodyPart mimePart=(MimeBodyPart)bodyPart;
    String[] cte=mimePart.getHeader("String_Node_Str");
    String contentTransferEncoding;
    if (mimePart.getContent() instanceof MimeMultipart) {
      MimeMultipart mp=(MimeMultipart)bodyPart.getContent();
      ContentType contentType=new ContentType(mp.getContentType());
      String boundary="String_Node_Str" + contentType.getParameter("String_Node_Str");
      SMIMEUtil.LineOutputStream lOut=new SMIMEUtil.LineOutputStream(out);
      Enumeration headers=mimePart.getAllHeaderLines();
      while (headers.hasMoreElements()) {
        String header=(String)headers.nextElement();
        lOut.writeln(header);
      }
      lOut.writeln();
      outputPreamble(lOut,mimePart,boundary);
      for (int i=0; i < mp.getCount(); i++) {
        lOut.writeln(boundary);
        BodyPart part=mp.getBodyPart(i);
        outputBodyPart(out,false,part,defaultContentTransferEncoding);
        if (!(part.getContent() instanceof MimeMultipart)) {
          lOut.writeln();
        }
 else {
          outputPostamble(lOut,mimePart,boundary,part);
        }
      }
      lOut.writeln(boundary + "String_Node_Str");
      if (topLevel) {
        outputPostamble(lOut,mimePart,mp.getCount(),boundary);
      }
      return;
    }
    if (cte == null) {
      contentTransferEncoding=defaultContentTransferEncoding;
    }
 else {
      contentTransferEncoding=cte[0];
    }
    if (!contentTransferEncoding.equalsIgnoreCase("String_Node_Str") && !contentTransferEncoding.equalsIgnoreCase("String_Node_Str")) {
      if (!contentTransferEncoding.equalsIgnoreCase("String_Node_Str")) {
        out=new CRLFOutputStream(out);
      }
      bodyPart.writeTo(out);
      out.flush();
      return;
    }
    boolean base64=contentTransferEncoding.equalsIgnoreCase("String_Node_Str");
    InputStream inRaw;
    try {
      inRaw=mimePart.getRawInputStream();
    }
 catch (    MessagingException e) {
      out=new CRLFOutputStream(out);
      bodyPart.writeTo(out);
      out.flush();
      return;
    }
    LineOutputStream outLine=new LineOutputStream(out);
    for (Enumeration e=mimePart.getAllHeaderLines(); e.hasMoreElements(); ) {
      String header=(String)e.nextElement();
      outLine.writeln(header);
    }
    outLine.writeln();
    outLine.flush();
    OutputStream outCRLF;
    if (base64) {
      outCRLF=new Base64CRLFOutputStream(out);
    }
 else {
      outCRLF=new CRLFOutputStream(out);
    }
    byte[] buf=new byte[BUF_SIZE];
    int len;
    while ((len=inRaw.read(buf,0,buf.length)) > 0) {
      outCRLF.write(buf,0,len);
    }
    outCRLF.flush();
  }
 else {
    if (!defaultContentTransferEncoding.equalsIgnoreCase("String_Node_Str")) {
      out=new CRLFOutputStream(out);
    }
    bodyPart.writeTo(out);
    out.flush();
  }
}