本文整理汇总了Java中javax.mail.internet.InternetHeaders类的典型用法代码示例。如果您正苦于以下问题:Java InternetHeaders类的具体用法?Java InternetHeaders怎么用?Java InternetHeaders使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InternetHeaders类属于javax.mail.internet包,在下文中一共展示了InternetHeaders类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseDescriptionFile
import javax.mail.internet.InternetHeaders; //导入依赖的package包/类
/**
* Parses metadata stored in a Debian Control File-like format.
*
* @see <a href="https://cran.r-project.org/doc/manuals/r-release/R-exts.html#The-DESCRIPTION-file">Description File</a>
*/
public static Map<String, String> parseDescriptionFile(final InputStream in) {
checkNotNull(in);
try {
LinkedHashMap<String, String> results = new LinkedHashMap<>();
InternetHeaders headers = new InternetHeaders(in);
Enumeration headerEnumeration = headers.getAllHeaders();
while (headerEnumeration.hasMoreElements()) {
Header header = (Header) headerEnumeration.nextElement();
String name = header.getName();
String value = header.getValue()
.replace("\r\n", "\n")
.replace("\r", "\n"); // TODO: "should" be ASCII only, otherwise need to know encoding?
results.put(name, value); // TODO: Supposedly no duplicates, is this true?
}
return results;
} catch (MessagingException e) {
throw new RException(null, e);
}
}
示例2: addHeaders
import javax.mail.internet.InternetHeaders; //导入依赖的package包/类
/**
* Adds the given name-values header to the given headers object.
*
* @param headers the headers object.
* @param name the header name.
* @param values the header values.
*/
private void addHeaders(Object headers, String name, Object[] values) {
if (name != null) {
for (int i=0; i<values.length; i++) {
if (headers instanceof StringWriter) {
StringWriter outs = (StringWriter)headers;
outs.write(name+": "+values[i]+"\r\n");
continue;
}
StringTokenizer subvalues = new StringTokenizer(
values[i].toString(), ",");
while (subvalues.hasMoreTokens()) {
String subvalue = subvalues.nextToken().trim();
if (headers instanceof MimeHeaders) {
((MimeHeaders)headers).addHeader(name, subvalue);
}
else if (headers instanceof InternetHeaders) {
((InternetHeaders)headers).addHeader(name, subvalue);
}
}
}
}
}
示例3: AS2Message
import javax.mail.internet.InternetHeaders; //导入依赖的package包/类
/**
* Creates a new instance of AS2Message.
*
* @param headers the headers of this message.
* @param content the content stream.
* @throws AS2MessageException if unable to construct from the given content stream.
*/
public AS2Message(InternetHeaders headers, InputStream content)
throws AS2MessageException {
try {
load(headers, content);
} catch (Exception e) {
throw new AS2MessageException(
"Unable to construct AS2 message from content stream", e);
}
}
示例4: setBodyPart
import javax.mail.internet.InternetHeaders; //导入依赖的package包/类
public static void setBodyPart(Multipart multipart, byte[] content, String contentType) throws MessagingException {
String disposition = null;
for (int i = 0; i < multipart.getCount(); i++) {
BodyPart bp = multipart.getBodyPart(i);
if (contentType.equalsIgnoreCase(bp.getContentType())) {
disposition = bp.getDisposition();
multipart.removeBodyPart(i);
break;
}
}
InternetHeaders ih1 = new InternetHeaders();
ih1.setHeader("Content-Type", contentType);
BodyPart bodyPart = new MimeBodyPart(ih1, content);
if (disposition != null) {
bodyPart.setDisposition(disposition);
}
multipart.addBodyPart(bodyPart);
}
示例5: provideHeaders
import javax.mail.internet.InternetHeaders; //导入依赖的package包/类
/**
* Provides parsed email headers from the "headers" param in a multipart/form-data request.
* <p>
* Although SendGrid parses some headers for us, it doesn't parse "reply-to", so we need to do
* this. Once we are doing it, it's easier to be consistent and use this as the sole source of
* truth for information that originates in the headers.
*/
@Provides
@Singleton
InternetHeaders provideHeaders(FileItemIterator iterator) {
try {
while (iterator != null && iterator.hasNext()) {
FileItemStream item = iterator.next();
// SendGrid sends us the headers in the "headers" param.
if (item.getFieldName().equals("headers")) {
try (InputStream stream = item.openStream()) {
// SendGrid always sends headers in UTF-8 encoding.
return new InternetHeaders(new ByteArrayInputStream(
CharStreams.toString(new InputStreamReader(stream, UTF_8.name())).getBytes(UTF_8)));
}
}
}
} catch (MessagingException | FileUploadException | IOException e) {
// If we fail parsing the headers fall through returning the empty header object below.
}
return new InternetHeaders(); // Parsing failed or there was no "headers" param.
}
示例6: getControlHeaders
import javax.mail.internet.InternetHeaders; //导入依赖的package包/类
/**
* Add the defined package data to an RFC822 formatted header formatted for a Debian package
* control file.
* Order of fields determined from:
* <a href="http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-binarycontrolfiles">Debian Policy Manual</a>
*/
public InternetHeaders getControlHeaders ()
{
final InternetHeaders headers = new InternetHeaders();
headers.addHeader(_name.getField(), _name.getFieldValue());
headers.addHeader(_version.getField(), _version.getFieldValue());
headers.addHeader(_section.getField(), _section.getFieldValue());
headers.addHeader(_priority.getField(), _priority.getFieldValue());
headers.addHeader(_architecture.getField(), _architecture.getFieldValue());
if (_dependencies.size() > 0) {
headers.addHeader(_dependencies.getField(), _dependencies.getFieldValue());
}
if (_conflicts.size() > 0) {
headers.addHeader(_conflicts.getField(), _conflicts.getFieldValue());
}
if (_replacements.size() > 0) {
headers.addHeader(_replacements.getField(), _replacements.getFieldValue());
}
headers.addHeader(_maintainer.getField(), _maintainer.getFieldValue());
headers.addHeader(_description.getField(), _description.getFieldValue());
return headers;
}
示例7: addControlFile
import javax.mail.internet.InternetHeaders; //导入依赖的package包/类
/**
* Add the control file to the tar file.
*/
private void addControlFile (TarOutputStream tar, PackageInfo info, PackageTarFile dataTar)
throws IOException
{
// setup the RFC822 formatted header used for package metadata.
final InternetHeaders headers = info.getControlHeaders();
// add the "Installed-Size" field.
headers.addHeader(INSTALLED_SIZE, String.valueOf(dataTar.getTotalDataSize()));
final StringBuilder controlFile = new StringBuilder();
@SuppressWarnings("unchecked")
final
Enumeration<String> en = headers.getAllHeaderLines();
while (en.hasMoreElements())
{
controlFile.append(en.nextElement()).append('\n');
}
final TarEntry entry = standardEntry(DEB_CONTROL_FILE, UnixStandardPermissions.STANDARD_FILE_MODE, controlFile.length());
tar.putNextEntry(entry);
IOUtils.write(controlFile.toString(), tar);
tar.closeEntry();
}
示例8: saveStreamToFile
import javax.mail.internet.InternetHeaders; //导入依赖的package包/类
private static File saveStreamToFile(InternetHeaders headers, InputStream content, File tempFile)
throws IOException
{
OutputStream out = new FileOutputStream(tempFile);
Enumeration en = headers.getAllHeaderLines();
while (en.hasMoreElements())
{
writeHeader(out, (String)en.nextElement());
}
writeSeperator(out);
saveContentToStream(out, content);
return tempFile;
}
示例9: createBodyPart
import javax.mail.internet.InternetHeaders; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static MimeBodyPart createBodyPart(Providers providers, SMIMEOutput out) throws IOException, MessagingException {
ByteArrayOutputStream bodyOs = new ByteArrayOutputStream();
MessageBodyWriter writer = providers.getMessageBodyWriter(out.getType(), out.getGenericType(), null, out.getMediaType());
if (writer == null) {
throw new RuntimeException("Failed to find writer for type: " + out.getType().getName());
}
MultivaluedMap<String, String> bodyHeaders = new MultivaluedHashMap<String, String>();
bodyHeaders.add("Content-Type", out.getMediaType().toString());
writer.writeTo(out.getEntity(), out.getType(), out.getGenericType(), null, out.getMediaType(), bodyHeaders, bodyOs);
InternetHeaders ih = new InternetHeaders();
for (Map.Entry<String, List<String>> entry : bodyHeaders.entrySet()) {
for (String value : entry.getValue()) {
ih.addHeader(entry.getKey(), value);
}
}
return new MimeBodyPart(ih, bodyOs.toByteArray());
}
示例10: testHeaders
import javax.mail.internet.InternetHeaders; //导入依赖的package包/类
@Test
public void testHeaders()
throws Exception {
InternetHeaders ih = new InternetHeaders();
ih.addHeader("Content-Type", "application/xml");
MimeBodyPart _msg = new MimeBodyPart(ih, "<customer name=\"bill\"/>".getBytes());
SMIMEEnvelopedGenerator gen = new SMIMEEnvelopedGenerator();
OutputEncryptor encryptor = new JceCMSContentEncryptorBuilder(CMSAlgorithm.DES_EDE3_CBC)
.setProvider("BC")
.build();
RecipientInfoGenerator generator = new JceKeyTransRecipientInfoGenerator(cert);
gen.addRecipientInfoGenerator(generator);
//
// generate a MimeBodyPart object which encapsulates the content
// we want encrypted.
//
MimeBodyPart mp = gen.generate(_msg, encryptor);
output(mp);
}
示例11: testFromPythonGenerated
import javax.mail.internet.InternetHeaders; //导入依赖的package包/类
@Test
public void testFromPythonGenerated() throws Exception {
InternetHeaders ih = new InternetHeaders();
ih.addHeader("Content-Disposition", "attachment; filename=\"smime.p7m\"");
ih.addHeader("Content-Type", "application/pkcs7-mime; smime-type=enveloped-data; name=\"smime.p7m\"");
ih.addHeader("Content-Transfer-Encoding", "base64");
MimeBodyPart mp = new MimeBodyPart(ih, python_smime.getBytes());
output(mp);
System.out.println("------------");
mp = decode2Mime(mp);
Assert.assertEquals("application/xml", mp.getContentType());
String body = toString(mp.getInputStream());
Assert.assertEquals("<customer name=\"bill\"/>", body.trim());
}
示例12: sendEvents
import javax.mail.internet.InternetHeaders; //导入依赖的package包/类
/**
* Send the contents of the cyclic buffer as an e-mail message.
* @param layout The layout for formatting the events.
* @param appendEvent The event that triggered the send.
*/
public void sendEvents(final Layout<?> layout, final LogEvent appendEvent) {
if (message == null) {
connect(appendEvent);
}
try {
final LogEvent[] priorEvents = buffer.removeAll();
// LOG4J-310: log appendEvent even if priorEvents is empty
final byte[] rawBytes = formatContentToBytes(priorEvents, appendEvent, layout);
final String contentType = layout.getContentType();
final String encoding = getEncoding(rawBytes, contentType);
final byte[] encodedBytes = encodeContentToBytes(rawBytes, encoding);
final InternetHeaders headers = getHeaders(contentType, encoding);
final MimeMultipart mp = getMimeMultipart(encodedBytes, headers);
sendMultipartMessage(message, mp);
} catch (final MessagingException | IOException | RuntimeException e) {
logError("Caught exception while sending e-mail notification.", e);
throw new LoggingException("Error occurred while sending email", e);
}
}
示例13: buildPackages
import javax.mail.internet.InternetHeaders; //导入依赖的package包/类
static Content buildPackages(final Collection<Map<String, String>> entries) throws IOException {
CompressorStreamFactory compressorStreamFactory = new CompressorStreamFactory();
ByteArrayOutputStream os = new ByteArrayOutputStream();
try (CompressorOutputStream cos = compressorStreamFactory.createCompressorOutputStream(GZIP, os)) {
try (OutputStreamWriter writer = new OutputStreamWriter(cos, UTF_8)) {
for (Map<String, String> entry : entries) {
InternetHeaders headers = new InternetHeaders();
headers.addHeader(P_PACKAGE, entry.get(P_PACKAGE));
headers.addHeader(P_VERSION, entry.get(P_VERSION));
headers.addHeader(P_DEPENDS, entry.get(P_DEPENDS));
headers.addHeader(P_IMPORTS, entry.get(P_IMPORTS));
headers.addHeader(P_SUGGESTS, entry.get(P_SUGGESTS));
headers.addHeader(P_LICENSE, entry.get(P_LICENSE));
headers.addHeader(P_NEEDS_COMPILATION, entry.get(P_NEEDS_COMPILATION));
Enumeration<String> headerLines = headers.getAllHeaderLines();
while (headerLines.hasMoreElements()) {
String line = headerLines.nextElement();
writer.write(line, 0, line.length());
writer.write('\n');
}
writer.write('\n');
}
}
}
catch ( CompressorException e ) {
throw new RException(null, e);
}
return new Content(new BytesPayload(os.toByteArray(), "application/x-gzip"));
}
示例14: processRequest
import javax.mail.internet.InternetHeaders; //导入依赖的package包/类
/**
* processRequest
* @param request
* @param response
* @return String
* @throws RequestListenerException
* @see hk.hku.cecid.piazza.commons.servlet.http.HttpRequestListener#processRequest(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public String processRequest(HttpServletRequest request,
HttpServletResponse response) throws RequestListenerException {
try {
Headers headers = new Headers(request, response);
InternetHeaders requestHeaders = headers.getInternetHeaders();
InputStream requestStream = request.getInputStream();
AS2Message requestMessage = new AS2Message(requestHeaders, requestStream);
if (requestMessage.getFromPartyID() == null || requestMessage.getToPartyID() == null) {
response.sendError(HttpURLConnection.HTTP_BAD_REQUEST, "Invalid AS2 Message");
return null;
}
AS2Request as2request = new AS2Request(request);
as2request.setMessage(requestMessage);
AS2Response as2response = new AS2Response(response);
processRequest(as2request, as2response);
AS2Message responseMessage = as2response.getMessage();
if (responseMessage == null) {
return null;
}
InternetHeaders responseHeaders = responseMessage.getHeaders();
headers.putInternetHeaders(responseHeaders);
InputStream contentStream= responseMessage.getContentStream();
OutputStream responseStream= response.getOutputStream();
IOHandler.pipe(contentStream, responseStream);
return null;
}
catch (Exception e) {
throw new RequestListenerException("Error in processing AS2 request", e);
}
}
示例15: DispositionNotification
import javax.mail.internet.InternetHeaders; //导入依赖的package包/类
public DispositionNotification() throws AS2MessageException {
multiPart = new MimeMultipart();
textPart = new MimeBodyPart();
reportPart = new MimeBodyPart();
reportValues = new InternetHeaders();
try {
multiPart.setSubType(CONTENT_SUBTYPE);
multiPart.addBodyPart(textPart);
multiPart.addBodyPart(reportPart);
}
catch (MessagingException e) {
throw new AS2MessageException("Unable to construct a new disposition notification", e);
}
}