/** * Convert the String to either ASCII or UTF-8 bytes * depending on allowutf8. */ private byte[] toBytes(String s) { if (allowutf8) return s.getBytes(StandardCharsets.UTF_8); else // don't use StandardCharsets.US_ASCII because it rejects non-ASCII return ASCIIUtility.getBytes(s); }
public void writeln(String s) throws IOException { byte[] bytes = ASCIIUtility.getBytes(s); out.write(bytes); out.write(newline); }
public void writeln(String s) throws IOException { byte[] bytes; if (allowutf8) bytes = s.getBytes(StandardCharsets.UTF_8); else bytes = ASCIIUtility.getBytes(s); out.write(bytes); out.write(newline); }
public Response(String s) { buffer = ASCIIUtility.getBytes(s); size = buffer.length; parse(); }
/** * Sends command <code>cmd</code> to the server terminating * it with <code>CRLF</code>. * * @param cmd the command * @exception MessagingException for failures * @since JavaMail 1.4.1 */ protected void sendCommand(String cmd) throws MessagingException { sendCommand(ASCIIUtility.getBytes(cmd)); }
String getInitialResponse(String host, String authzid, String user, String passwd) throws MessagingException, IOException { // return "authzid<NUL>user<NUL>passwd" ByteArrayOutputStream bos = new ByteArrayOutputStream(); OutputStream b64os = new BASE64EncoderStream(bos, Integer.MAX_VALUE); if (authzid != null) b64os.write(ASCIIUtility.getBytes(authzid)); b64os.write(0); b64os.write(ASCIIUtility.getBytes(user)); b64os.write(0); b64os.write(ASCIIUtility.getBytes(passwd)); b64os.flush(); // complete the encoding return ASCIIUtility.toString(bos.toByteArray()); }
/** * Write out given string as an ASTRING, depending on the type * of the characters inside the string. The string should * contain only ASCII characters. <p> * * XXX: Hmm .. this should really be called writeASCII() * * @param s String to write out * @return this */ public Argument writeString(String s) { items.add(new AString(ASCIIUtility.getBytes(s))); return this; }
/** * Write out given string as an ASTRING, depending on the type * of the characters inside the string. The string should * contain only ASCII characters. <p> * * XXX: Hmm .. this should really be called writeASCII() * * @param s String to write out * @return this */ public Argument writeString(String s) { items.add(new AString(ASCIIUtility.getBytes(s))); return this; }
/** * Write out given string as an NSTRING, depending on the type * of the characters inside the string. The string should * contain only ASCII characters. <p> * * @param s String to write out * @return this * @since JavaMail 1.5.1 */ public Argument writeNString(String s) { if (s == null) items.add(new NString(null)); else items.add(new NString(ASCIIUtility.getBytes(s))); return this; }
/** * Write out given string as an NSTRING, depending on the type * of the characters inside the string. The string should * contain only ASCII characters. <p> * * @param s String to write out * @return this * @since JavaMail 1.5.1 */ public Argument writeNString(String s) { if (s == null) items.add(new NString(null)); else items.add(new NString(ASCIIUtility.getBytes(s))); return this; }
void doAuth(String host, String authzid, String user, String passwd) throws MessagingException, IOException { // send username resp = simpleCommand( BASE64EncoderStream.encode(ASCIIUtility.getBytes(user))); if (resp == 334) { // send passwd resp = simpleCommand( BASE64EncoderStream.encode(ASCIIUtility.getBytes(passwd))); } } }
String getInitialResponse(String host, String authzid, String user, String passwd) throws MessagingException, IOException { String resp = "user=" + user + "\001auth=Bearer " + passwd + "\001\001"; byte[] b = BASE64EncoderStream.encode(ASCIIUtility.getBytes(resp)); return ASCIIUtility.toString(b); }
/** * Allow the client to authenticate the server based on its * response. * * @param serverResponse the response that was received from the server * @return true if server is authenticated * @exception IOException for character conversion failures */ public boolean authServer(String serverResponse) throws IOException { Map<String, String> map = tokenize(serverResponse); // DIGEST-MD5 computation, server response (order critical) md5.update(ASCIIUtility.getBytes(":" + uri)); md5.update(ASCIIUtility.getBytes(clientResponse + toHex(md5.digest()))); String text = toHex(md5.digest()); if (!text.equals(map.get("rspauth"))) { if (logger.isLoggable(Level.FINE)) logger.fine("Expected => rspauth=" + text); return false; // server NOT authenticated by client !!! } return true; }
/** * Allow the client to authenticate the server based on its * response. * * @param serverResponse the response that was received from the server * @return true if server is authenticated * @exception IOException for character conversion failures */ public boolean authServer(String serverResponse) throws IOException { Map<String, String> map = tokenize(serverResponse); // DIGEST-MD5 computation, server response (order critical) md5.update(ASCIIUtility.getBytes(":" + uri)); md5.update(ASCIIUtility.getBytes(clientResponse + toHex(md5.digest()))); String text = toHex(md5.digest()); if (!text.equals(map.get("rspauth"))) { if (logger.isLoggable(Level.FINE)) logger.fine("Expected => rspauth=" + text); return false; // server NOT authenticated by client !!! } return true; }
} catch (UnsupportedEncodingException ex) { response = ASCIIUtility.getBytes(resp);
} catch (UnsupportedEncodingException ex) { response = ASCIIUtility.getBytes(resp);
/** * Parse the InputStream setting the <code>headers</code> and * <code>content</code> fields appropriately. Also resets the * <code>modified</code> flag. <p> * * This method is intended for use by subclasses that need to * control when the InputStream is parsed. * * @param is The message input stream * @exception MessagingException for failures */ protected void parse(InputStream is) throws MessagingException { if (!(is instanceof ByteArrayInputStream) && !(is instanceof BufferedInputStream) && !(is instanceof SharedInputStream)) is = new BufferedInputStream(is); headers = createInternetHeaders(is); if (is instanceof SharedInputStream) { SharedInputStream sis = (SharedInputStream)is; contentStream = sis.newStream(sis.getPosition(), -1); } else { try { content = ASCIIUtility.getBytes(is); } catch (IOException ioex) { throw new MessagingException("IOException", ioex); } } modified = false; }
/** * Parse the InputStream setting the <code>headers</code> and * <code>content</code> fields appropriately. Also resets the * <code>modified</code> flag. <p> * * This method is intended for use by subclasses that need to * control when the InputStream is parsed. * * @param is The message input stream * @exception MessagingException for failures */ protected void parse(InputStream is) throws MessagingException { if (!(is instanceof ByteArrayInputStream) && !(is instanceof BufferedInputStream) && !(is instanceof SharedInputStream)) is = new BufferedInputStream(is); headers = createInternetHeaders(is); if (is instanceof SharedInputStream) { SharedInputStream sis = (SharedInputStream)is; contentStream = sis.newStream(sis.getPosition(), -1); } else { try { content = ASCIIUtility.getBytes(is); } catch (IOException ioex) { throw new MessagingException("IOException", ioex); } } modified = false; }
} else { try { content = ASCIIUtility.getBytes(is); } catch (IOException ioex) { throw new MessagingException("Error reading input stream", ioex);
} else { try { content = ASCIIUtility.getBytes(is); } catch (IOException ioex) { throw new MessagingException("Error reading input stream", ioex);