Program: 31240
Project: 31240
Buggy source:
private void handleBodyFetch(MimeMessage mimeMessage,String sectionSpecifier,String partial,StringBuilder response) throws Exception {
  if (sectionSpecifier.length() == 0) {
    ByteArrayOutputStream bout=new ByteArrayOutputStream();
    mimeMessage.writeTo(bout);
    byte[] bytes=bout.toByteArray();
    bytes=doPartial(partial,bytes,response);
    addLiteral(bytes,response);
  }
 else   if ("String_Node_Str".equalsIgnoreCase(sectionSpecifier)) {
    Enumeration inum=mimeMessage.getAllHeaderLines();
    addHeaders(inum,response);
  }
 else   if (sectionSpecifier.startsWith("String_Node_Str")) {
    String[] excludeNames=extractHeaderList(sectionSpecifier,"String_Node_Str".length());
    Enumeration inum=mimeMessage.getNonMatchingHeaderLines(excludeNames);
    addHeaders(inum,response);
  }
 else   if (sectionSpecifier.startsWith("String_Node_Str")) {
    String[] includeNames=extractHeaderList(sectionSpecifier,"String_Node_Str".length());
    Enumeration inum=mimeMessage.getMatchingHeaderLines(includeNames);
    addHeaders(inum,response);
  }
 else   if (sectionSpecifier.endsWith("String_Node_Str")) {
    String[] strs=sectionSpecifier.trim().split("String_Node_Str");
    int partNumber=Integer.parseInt(strs[0]) - 1;
    MimeMultipart mp=(MimeMultipart)mimeMessage.getContent();
    byte[] bytes=GreenMailUtil.getHeaderAsBytes(mp.getBodyPart(partNumber));
    bytes=doPartial(partial,bytes,response);
    addLiteral(bytes,response);
  }
 else   if ("String_Node_Str".equalsIgnoreCase(sectionSpecifier)) {
    byte[] bytes=GreenMailUtil.getBodyAsBytes(mimeMessage);
    bytes=doPartial(partial,bytes,response);
    addLiteral(bytes,response);
  }
 else {
    if (log.isDebugEnabled()) {
      log.debug("String_Node_Str" + sectionSpecifier);
    }
    MimeMultipart mp=(MimeMultipart)mimeMessage.getContent();
    BodyPart part=null;
    String[] nestedIdx=sectionSpecifier.split("String_Node_Str");
    for (    String idx : nestedIdx) {
      int partNumber=Integer.parseInt(idx) - 1;
      if (null == part) {
        part=mp.getBodyPart(partNumber);
      }
 else {
        part=((Multipart)part.getContent()).getBodyPart(partNumber);
      }
    }
    byte[] bytes=GreenMailUtil.getBodyAsBytes(part);
    bytes=doPartial(partial,bytes,response);
    addLiteral(bytes,response);
  }
}

Fixed version (ground truth):
private void handleBodyFetch(MimeMessage mimeMessage,String sectionSpecifier,String partial,StringBuilder response) throws Exception {
  if (sectionSpecifier.length() == 0) {
    ByteArrayOutputStream bout=new ByteArrayOutputStream();
    mimeMessage.writeTo(bout);
    byte[] bytes=bout.toByteArray();
    bytes=doPartial(partial,bytes,response);
    addLiteral(bytes,response);
  }
 else   if ("String_Node_Str".equalsIgnoreCase(sectionSpecifier)) {
    Enumeration inum=mimeMessage.getAllHeaderLines();
    addHeaders(inum,response);
  }
 else   if (sectionSpecifier.startsWith("String_Node_Str")) {
    String[] excludeNames=extractHeaderList(sectionSpecifier,"String_Node_Str".length());
    Enumeration inum=mimeMessage.getNonMatchingHeaderLines(excludeNames);
    addHeaders(inum,response);
  }
 else   if (sectionSpecifier.startsWith("String_Node_Str")) {
    String[] includeNames=extractHeaderList(sectionSpecifier,"String_Node_Str".length());
    Enumeration inum=mimeMessage.getMatchingHeaderLines(includeNames);
    addHeaders(inum,response);
  }
 else   if (sectionSpecifier.endsWith("String_Node_Str")) {
    String[] strs=sectionSpecifier.trim().split("String_Node_Str");
    int partNumber=Integer.parseInt(strs[0]) - 1;
    MimeMultipart mp=(MimeMultipart)mimeMessage.getContent();
    byte[] bytes=GreenMailUtil.getHeaderAsBytes(mp.getBodyPart(partNumber));
    bytes=doPartial(partial,bytes,response);
    addLiteral(bytes,response);
  }
 else   if ("String_Node_Str".equalsIgnoreCase(sectionSpecifier)) {
    handleBodyFetchForText(mimeMessage,partial,response);
  }
 else {
    if (log.isDebugEnabled()) {
      log.debug("String_Node_Str" + sectionSpecifier + "String_Node_Str"+ mimeMessage.getContentType());
    }
    String contentType=mimeMessage.getContentType();
    if (contentType.startsWith("String_Node_Str") && "String_Node_Str".equals(sectionSpecifier)) {
      handleBodyFetchForText(mimeMessage,partial,response);
    }
 else {
      MimeMultipart mp=(MimeMultipart)mimeMessage.getContent();
      BodyPart part=null;
      String[] nestedIdx=sectionSpecifier.split("String_Node_Str");
      for (      String idx : nestedIdx) {
        int partNumber=Integer.parseInt(idx) - 1;
        if (null == part) {
          part=mp.getBodyPart(partNumber);
        }
 else {
          part=((Multipart)part.getContent()).getBodyPart(partNumber);
        }
      }
      byte[] bytes=GreenMailUtil.getBodyAsBytes(part);
      bytes=doPartial(partial,bytes,response);
      addLiteral(bytes,response);
    }
  }
}