com.sun.mail.util.BASE64DecoderStream Java Examples

The following examples show how to use com.sun.mail.util.BASE64DecoderStream. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MimeUtility.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
/**
    * Decode the given input stream. The Input stream returned is
    * the decoded input stream. All the encodings defined in RFC 2045
    * are supported here. They include "base64", "quoted-printable",
    * "7bit", "8bit", and "binary". In addition, "uuencode" is also
    * supported. <p>
    *
    * In the current implementation, if the
    * <code>mail.mime.ignoreunknownencoding</code> system property is set to
    * <code>"true"</code>, unknown encoding values are ignored and the
    * original InputStream is returned.
    *
    * @param	is		input stream
    * @param	encoding	the encoding of the stream.
    * @return			decoded input stream.
    * @exception MessagingException	if the encoding is unknown
    */
   public static InputStream decode(InputStream is, String encoding)
	throws MessagingException {
if (encoding.equalsIgnoreCase("base64"))
    return new BASE64DecoderStream(is);
else if (encoding.equalsIgnoreCase("quoted-printable"))
    return new QPDecoderStream(is);
else if (encoding.equalsIgnoreCase("uuencode") ||
	 encoding.equalsIgnoreCase("x-uuencode") ||
	 encoding.equalsIgnoreCase("x-uue"))
    return new UUDecoderStream(is);
else if (encoding.equalsIgnoreCase("binary") ||
	 encoding.equalsIgnoreCase("7bit") ||
	 encoding.equalsIgnoreCase("8bit"))
    return is;
else {
    if (!ignoreUnknownEncoding)
	throw new MessagingException("Unknown encoding: " + encoding);
    return is;
}
   }
 
Example #2
Source File: Protocol.java    From FairEmail with GNU General Public License v3.0 5 votes vote down vote up
@Override
void doAuth(String host, String authzid, String user, String passwd)
			throws IOException {
    // OAuth2 failure returns a JSON error code,
    // which looks like a "please continue" to the authenticate()
    // code, so we turn that into a clean failure here.
    String err = "";
    if (resp.data != null) {
	byte[] b = resp.data.getBytes(StandardCharsets.UTF_8);
	b = BASE64DecoderStream.decode(b);
	err = new String(b, StandardCharsets.UTF_8);
    }
    throw new EOFException("OAUTH2 authentication failed: " + err);
}
 
Example #3
Source File: AuthCommand.java    From greenmail with Apache License 2.0 5 votes vote down vote up
private boolean authenticate(UserManager userManager, String value) {
    // authorization-id\0authentication-id\0passwd
    final BASE64DecoderStream stream = new BASE64DecoderStream(
            new ByteArrayInputStream(value.getBytes(StandardCharsets.UTF_8)));
    readTillNullChar(stream); // authorizationId Not used
    String authenticationId = readTillNullChar(stream);
    String passwd = readTillNullChar(stream);
    return userManager.test(authenticationId, passwd);
}
 
Example #4
Source File: AuthCommand.java    From greenmail with Apache License 2.0 5 votes vote down vote up
@Deprecated // Remove once JDK baseline is 1.8
private String readTillNullChar(BASE64DecoderStream stream) {
    try {
        return EncodingUtil.readTillNullChar(stream);
    } catch (IOException e) {
        log.error("Can not decode", e);
        return null;
    }
}
 
Example #5
Source File: AuthCommand.java    From greenmail with Apache License 2.0 5 votes vote down vote up
@Deprecated // Remove once JDK baseline is 1.8
private String readTillNullChar(BASE64DecoderStream stream) {
    try {
        return EncodingUtil.readTillNullChar(stream);
    } catch (IOException e) {
        log.error("Can not decode", e);
        return null;
    }
}
 
Example #6
Source File: EncodingUtil.java    From greenmail with Apache License 2.0 5 votes vote down vote up
@Deprecated // Remove once JDK baseline is 1.8
public static String readTillNullChar(BASE64DecoderStream stream) throws IOException {
    StringBuilder buf = new StringBuilder();
    for (int chr = stream.read(); chr != '\u0000' && chr > 0; chr = stream.read()) {
        buf.append((char) chr);
    }
    return buf.toString();
}
 
Example #7
Source File: DigestMD5.java    From FairEmail with GNU General Public License v3.0 4 votes vote down vote up
/**
    * Tokenize a response from the server.
    *
    * @return	Map containing key/value pairs from server
    */
   @SuppressWarnings("fallthrough")
   private Map<String, String> tokenize(String serverResponse)
    throws IOException {
Map<String, String> map	= new HashMap<>();
byte[] bytes = serverResponse.getBytes("iso-8859-1");	// really ASCII?
String key = null;
int ttype;
StreamTokenizer	tokens
	= new StreamTokenizer(
	    new InputStreamReader(
	      new BASE64DecoderStream(
		new ByteArrayInputStream(bytes, 4, bytes.length - 4)
	      ), "iso-8859-1"	// really ASCII?
	    )
	  );

tokens.ordinaryChars('0', '9');	// reset digits
tokens.wordChars('0', '9');	// digits may start words
while ((ttype = tokens.nextToken()) != StreamTokenizer.TT_EOF) {
    switch (ttype) {
    case StreamTokenizer.TT_WORD:
	if (key == null) {
	    key = tokens.sval;
	    break;
	}
	// fall-thru
    case '"':
	if (logger.isLoggable(Level.FINE))
	    logger.fine("Received => " +
		 	 key + "='" + tokens.sval + "'");
	if (map.containsKey(key)) {  // concatenate multiple values
	    map.put(key, map.get(key) + "," + tokens.sval);
	} else {
	    map.put(key, tokens.sval);
	}
	key = null;
	break;
    default:	// XXX - should never happen?
	break;
    }
}
return map;
   }