Пример #1
0
 @Override
 protected byte[] doDecoding(byte[] bytes) throws DecoderException {
   if (bytes == null) {
     return null;
   }
   boolean hasUnderscores = false;
   for (byte b : bytes) {
     if (b == UNDERSCORE) {
       hasUnderscores = true;
       break;
     }
   }
   if (hasUnderscores) {
     byte[] tmp = new byte[bytes.length];
     for (int i = 0; i < bytes.length; i++) {
       byte b = bytes[i];
       if (b != UNDERSCORE) {
         tmp[i] = b;
       } else {
         tmp[i] = BLANK;
       }
     }
     return QuotedPrintableCodec.decodeQuotedPrintable(tmp);
   }
   return QuotedPrintableCodec.decodeQuotedPrintable(bytes);
 }
 public void propertyValues(Collection<String> values) {
   curPropNode.propValue_vector = values;
   curPropNode.propValue = listToString(values);
   // decode value string to propValue_byts
   if (curPropNode.paraMap.containsKey("ENCODING")) {
     if (curPropNode.paraMap.getAsString("ENCODING").equalsIgnoreCase("BASE64")) {
       curPropNode.propValue_byts =
           Base64.decodeBase64(
               curPropNode
                   .propValue
                   .replaceAll(" ", "")
                   .replaceAll("\t", "")
                   .replaceAll("\r\n", "")
                   .getBytes());
     }
     if (curPropNode.paraMap.getAsString("ENCODING").equalsIgnoreCase("QUOTED-PRINTABLE")) {
       try {
         curPropNode.propValue_byts =
             QuotedPrintableCodec.decodeQuotedPrintable(
                 curPropNode.propValue.replaceAll("= ", " ").replaceAll("=\t", "\t").getBytes());
         curPropNode.propValue = new String(curPropNode.propValue_byts);
       } catch (Exception e) {
         System.out.println("=Decode quoted-printable exception.");
         e.printStackTrace();
       }
     }
   }
   curVNode.propList.add(curPropNode);
 }
Пример #3
0
  /**
   * @param prop
   * @return
   * @throws DecoderException
   */
  private String getDecodedPropertyalue(Property prop) throws DecoderException {
    Encoding enc = (Encoding) prop.getParameter(Parameter.Id.ENCODING);
    String val = prop.getValue();
    if (enc != null && enc.getValue().equalsIgnoreCase("QUOTED-PRINTABLE")) {

      /*
       * A special Outlook2003 hack.
       */
      if (val.endsWith("=")) {
        val = val.substring(0, val.length() - 1);
      }

      QuotedPrintableCodec codec = new QuotedPrintableCodec();
      return codec.decode(val);
    } else {
      return val;
    }
  }
Пример #4
0
 @Override
 protected byte[] doEncoding(byte[] bytes) {
   if (bytes == null) {
     return null;
   }
   byte[] data = QuotedPrintableCodec.encodeQuotedPrintable(PRINTABLE_CHARS, bytes);
   if (this.encodeBlanks) {
     for (int i = 0; i < data.length; i++) {
       if (data[i] == BLANK) {
         data[i] = UNDERSCORE;
       }
     }
   }
   return data;
 }