use of javax.mail.internet.InternetHeaders in project zm-mailbox by Zimbra.
the class MockHttpStore method handle.
static void handle(Socket socket) throws IOException {
InputStream in = null;
OutputStream out = null;
try {
in = new BufferedInputStream(socket.getInputStream());
out = socket.getOutputStream();
StringBuilder reqline = new StringBuilder();
int b;
while ((b = in.read()) != -1 && b != '\n') {
reqline.append((char) b);
}
String[] reqparts = reqline.toString().trim().split(" ");
if (fail.compareAndSet(true, false)) {
out.write("HTTP/1.0 400 force fail".getBytes());
} else if (delay.compareAndSet(true, false)) {
try {
Thread.sleep(LC.httpclient_internal_connmgr_so_timeout.longValue() + 10000);
} catch (InterruptedException e) {
}
} else {
if (reqparts.length != 3 || !reqparts[2].startsWith("HTTP/")) {
out.write("HTTP/1.0 400 malformed request-line\r\n\r\n".getBytes());
} else {
String method = reqparts[0].toUpperCase(), filename = getFilename(reqparts[1]), version = reqparts[2];
try {
InternetHeaders headers = new InternetHeaders(in);
if (method.equals("GET")) {
doGet(version, filename, out);
} else if (method.equals("POST") || method.equals("PUT")) {
doPost(version, headers, in, out);
} else if (method.equals("DELETE")) {
doDelete(version, filename, out);
} else {
out.write((version + " 400 unknown method: " + reqparts[0] + "\r\n\r\n").getBytes());
}
} catch (MessagingException e) {
out.write((version + " 500 Internal Server Error\r\n\r\n").getBytes());
return;
}
}
}
out.flush();
} finally {
ByteUtil.closeStream(in);
ByteUtil.closeStream(out);
socket.close();
}
}
use of javax.mail.internet.InternetHeaders in project ats-framework by Axway.
the class MimePackage method getInternetHeaders.
private InternetHeaders getInternetHeaders(Object partContent) throws PackageException {
InternetHeaders internetHeaders = null;
if (partContent instanceof InputStream) {
try {
InputStream is = (InputStream) partContent;
internetHeaders = new InternetHeaders(is);
} catch (MessagingException e) {
// error converting to InternetHeaders
throw new PackageException("Error parsing internet headers with type rfc822-headers", e);
}
}
return internetHeaders;
}
use of javax.mail.internet.InternetHeaders in project nhin-d by DirectProject.
the class MDNStandard method getNotificationFieldsAsHeaders.
/**
* Parses the notification part fields of the MimeMultipart body of a MDN message. The multipart is expected to conform to the MDN specification
* as described in RFC3798.
* @return The notification part fields as a set of Internet headers.
*/
public static InternetHeaders getNotificationFieldsAsHeaders(MimeMultipart mm) {
InternetHeaders retVal = null;
if (mm == null)
throw new IllegalArgumentException("Multipart can not be null");
try {
if (mm.getCount() < 2)
throw new IllegalArgumentException("Multipart can not be null");
// the second part should be the notification
BodyPart part = mm.getBodyPart(1);
try {
Object contecntObj = part.getContent();
if (dsnClass != null && dsnClass.getCanonicalName().equals(contecntObj.getClass().getCanonicalName())) {
retVal = (InternetHeaders) getHeaders.invoke(contecntObj);
return retVal;
}
} catch (Exception e) {
/* no-op */
}
if (!part.getContentType().equalsIgnoreCase(MDNStandard.MediaType.DispositionNotification))
throw new IllegalArgumentException("Notification part content type is not " + MDNStandard.MediaType.DispositionNotification);
// parse fields
retVal = new InternetHeaders();
String[] fields = getPartContentBodyAsString(part).split("\r\n");
for (String field : fields) {
int idx = field.indexOf(":");
if (idx > -1) {
String name = field.substring(0, idx);
String value = field.substring(idx + 1).trim();
retVal.setHeader(name, value);
}
}
} catch (MessagingException e) {
throw new IllegalArgumentException("Failed to parse notification fields.", e);
}
return retVal;
}
use of javax.mail.internet.InternetHeaders in project nhin-d by DirectProject.
the class DSNStandard method getFinalRecipients.
/**
* Get the list final recipients as a comma delimited string from the delivery status part
* of a DSN message
* @param status The deliver status structure
* @return List of the final recipients as a command delimited string or an empty string if
* no final recipients exist.
*/
public static String getFinalRecipients(DeliveryStatus status) {
StringBuilder builder = new StringBuilder();
final int cnt = status.getRecipientDSNCount();
int recipientCount = 0;
for (int i = 0; i < cnt; ++i) {
final InternetHeaders recipHeaders = status.getRecipientDSN(i);
if (recipHeaders != null) {
final String value = recipHeaders.getHeader(DSNStandard.Headers.FinalRecipient, ",");
if (value != null && value.length() > 0) {
String recipient = value.substring(value.indexOf(";") + 1);
if (recipient != null && recipient.length() > 0) {
if (recipientCount > 0) {
builder.append(",");
}
builder.append(recipient.trim());
++recipientCount;
}
}
}
}
return builder.toString();
}
use of javax.mail.internet.InternetHeaders in project nhin-d by DirectProject.
the class DSNStandard method getHeaderValueFromDeliveryStatus.
/**
* Get header values from the delivery status part of a DNS message
* @param status The delivery status structure
* @param headerName The header name to get the value for.
* @return Return the value of the header, or an empty string if the header does not exist.
*/
public static String getHeaderValueFromDeliveryStatus(DeliveryStatus status, String headerName) {
String result = "";
final int cnt = status.getRecipientDSNCount();
for (int i = 0; i < cnt; ++i) {
final InternetHeaders recipHeaders = status.getRecipientDSN(i);
if (recipHeaders != null) {
final String value = recipHeaders.getHeader(headerName, ",");
if (value != null && value.length() > 0) {
result = value;
break;
}
}
}
return result;
}
Aggregations