javax.mail.internet.MimeBodyPart.getSingleHeader()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(116)

本文整理了Java中javax.mail.internet.MimeBodyPart.getSingleHeader()方法的一些代码示例,展示了MimeBodyPart.getSingleHeader()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MimeBodyPart.getSingleHeader()方法的具体详情如下:
包路径:javax.mail.internet.MimeBodyPart
类名称:MimeBodyPart
方法名:getSingleHeader

MimeBodyPart.getSingleHeader介绍

暂无

代码示例

代码示例来源:origin: org.apache.geronimo.specs/geronimo-javamail_1.4_spec

  1. public String getContentType() throws MessagingException {
  2. String value = getSingleHeader("Content-Type");
  3. if (value == null) {
  4. value = "text/plain";
  5. }
  6. return value;
  7. }

代码示例来源:origin: org.apache.geronimo.specs/geronimo-javamail_1.4_spec

  1. /**
  2. * Retrieve the value of the "Content-ID" header. Returns null
  3. * if the header does not exist.
  4. *
  5. * @return The current header value or null.
  6. * @exception MessagingException
  7. */
  8. public String getContentID() throws MessagingException {
  9. return getSingleHeader("Content-ID");
  10. }

代码示例来源:origin: org.apache.geronimo.specs/geronimo-javamail_1.3.1_spec

  1. public String getContentType() throws MessagingException {
  2. String value = getSingleHeader("Content-Type");
  3. if (value == null) {
  4. value = "text/plain";
  5. }
  6. return value;
  7. }

代码示例来源:origin: org.apache.geronimo.specs/geronimo-javamail_1.3.1_spec

  1. /**
  2. * Retrieve the value of the "Content-ID" header. Returns null
  3. * if the header does not exist.
  4. *
  5. * @return The current header value or null.
  6. * @exception MessagingException
  7. */
  8. public String getContentID() throws MessagingException {
  9. return getSingleHeader("Content-ID");
  10. }

代码示例来源:origin: org.apache.geronimo.specs/geronimo-javamail_1.4_spec

  1. public String getContentMD5() throws MessagingException {
  2. return getSingleHeader("Content-MD5");
  3. }

代码示例来源:origin: org.apache.geronimo.specs/geronimo-javamail_1.3.1_spec

  1. public String getContentMD5() throws MessagingException {
  2. return getSingleHeader("Content-MD5");
  3. }

代码示例来源:origin: org.apache.geronimo.specs/geronimo-javamail_1.4_spec

  1. public String getDescription() throws MessagingException {
  2. String description = getSingleHeader("Content-Description");
  3. if (description != null) {
  4. try {
  5. // this could be both folded and encoded. Return this to usable form.
  6. return MimeUtility.decodeText(MimeUtility.unfold(description));
  7. } catch (UnsupportedEncodingException e) {
  8. // ignore
  9. }
  10. }
  11. // return the raw version for any errors.
  12. return description;
  13. }

代码示例来源:origin: org.apache.geronimo.specs/geronimo-javamail_1.3.1_spec

  1. public String getDescription() throws MessagingException {
  2. String description = getSingleHeader("Content-Description");
  3. if (description != null) {
  4. try {
  5. // this could be both folded and encoded. Return this to usable form.
  6. return MimeUtility.decodeText(ASCIIUtil.unfold(description));
  7. } catch (UnsupportedEncodingException e) {
  8. // ignore
  9. }
  10. }
  11. // return the raw version for any errors.
  12. return description;
  13. }

代码示例来源:origin: org.apache.geronimo.specs/geronimo-javamail_1.4_spec

  1. /**
  2. * Retrieve the message "Content-Disposition" header field.
  3. * This value represents how the part should be represented to
  4. * the user.
  5. *
  6. * @return The string value of the Content-Disposition field.
  7. * @exception MessagingException
  8. */
  9. public String getDisposition() throws MessagingException {
  10. String disp = getSingleHeader("Content-Disposition");
  11. if (disp != null) {
  12. return new ContentDisposition(disp).getDisposition();
  13. }
  14. return null;
  15. }

代码示例来源:origin: org.apache.geronimo.specs/geronimo-javamail_1.3.1_spec

  1. /**
  2. * Retrieve the message "Content-Disposition" header field.
  3. * This value represents how the part should be represented to
  4. * the user.
  5. *
  6. * @return The string value of the Content-Disposition field.
  7. * @exception MessagingException
  8. */
  9. public String getDisposition() throws MessagingException {
  10. String disp = getSingleHeader("Content-Disposition");
  11. if (disp != null) {
  12. return new ContentDisposition(disp).getDisposition();
  13. }
  14. return null;
  15. }

代码示例来源:origin: org.apache.geronimo.specs/geronimo-javamail_1.4_spec

  1. public String getFileName() throws MessagingException {
  2. // see if there is a disposition. If there is, parse off the filename parameter.
  3. String disposition = getSingleHeader("Content-Disposition");
  4. String filename = null;
  5. if (disposition != null) {
  6. filename = new ContentDisposition(disposition).getParameter("filename");
  7. }
  8. // if there's no filename on the disposition, there might be a name parameter on a
  9. // Content-Type header.
  10. if (filename == null) {
  11. String type = getSingleHeader("Content-Type");
  12. if (type != null) {
  13. try {
  14. filename = new ContentType(type).getParameter("name");
  15. } catch (ParseException e) {
  16. }
  17. }
  18. }
  19. // if we have a name, we might need to decode this if an additional property is set.
  20. if (filename != null && SessionUtil.getBooleanProperty(MIME_DECODEFILENAME, false)) {
  21. try {
  22. filename = MimeUtility.decodeText(filename);
  23. } catch (UnsupportedEncodingException e) {
  24. throw new MessagingException("Unable to decode filename", e);
  25. }
  26. }
  27. return filename;
  28. }

代码示例来源:origin: org.apache.geronimo.specs/geronimo-javamail_1.3.1_spec

  1. public String getFileName() throws MessagingException {
  2. // see if there is a disposition. If there is, parse off the filename parameter.
  3. String disposition = getSingleHeader("Content-Disposition");
  4. String filename = null;
  5. if (disposition != null) {
  6. filename = new ContentDisposition(disposition).getParameter("filename");
  7. }
  8. // if there's no filename on the disposition, there might be a name parameter on a
  9. // Content-Type header.
  10. if (filename == null) {
  11. String type = getSingleHeader("Content-Type");
  12. if (type != null) {
  13. try {
  14. filename = new ContentType(type).getParameter("name");
  15. } catch (ParseException e) {
  16. }
  17. }
  18. }
  19. // if we have a name, we might need to decode this if an additional property is set.
  20. if (filename != null && SessionUtil.getBooleanProperty(MIME_DECODEFILENAME, false)) {
  21. try {
  22. filename = MimeUtility.decodeText(filename);
  23. } catch (UnsupportedEncodingException e) {
  24. throw new MessagingException("Unable to decode filename", e);
  25. }
  26. }
  27. return filename;
  28. }

代码示例来源:origin: org.apache.geronimo.specs/geronimo-javamail_1.4_spec

  1. /**
  2. * Retrieves the current value of the "Content-Transfer-Encoding"
  3. * header. Returns null if the header does not exist.
  4. *
  5. * @return The current header value or null.
  6. * @exception MessagingException
  7. */
  8. public String getEncoding() throws MessagingException {
  9. // this might require some parsing to sort out.
  10. String encoding = getSingleHeader("Content-Transfer-Encoding");
  11. if (encoding != null) {
  12. // we need to parse this into ATOMs and other constituent parts. We want the first
  13. // ATOM token on the string.
  14. HeaderTokenizer tokenizer = new HeaderTokenizer(encoding, HeaderTokenizer.MIME);
  15. Token token = tokenizer.next();
  16. while (token.getType() != Token.EOF) {
  17. // if this is an ATOM type, return it.
  18. if (token.getType() == Token.ATOM) {
  19. return token.getValue();
  20. }
  21. }
  22. // not ATOMs found, just return the entire header value....somebody might be able to make sense of
  23. // this.
  24. return encoding;
  25. }
  26. // no header, nothing to return.
  27. return null;
  28. }

代码示例来源:origin: org.apache.geronimo.specs/geronimo-javamail_1.3.1_spec

  1. /**
  2. * Retrieves the current value of the "Content-Transfer-Encoding"
  3. * header. Returns null if the header does not exist.
  4. *
  5. * @return The current header value or null.
  6. * @exception MessagingException
  7. */
  8. public String getEncoding() throws MessagingException {
  9. // this might require some parsing to sort out.
  10. String encoding = getSingleHeader("Content-Transfer-Encoding");
  11. if (encoding != null) {
  12. // we need to parse this into ATOMs and other constituent parts. We want the first
  13. // ATOM token on the string.
  14. HeaderTokenizer tokenizer = new HeaderTokenizer(encoding, HeaderTokenizer.MIME);
  15. Token token = tokenizer.next();
  16. while (token.getType() != Token.EOF) {
  17. // if this is an ATOM type, return it.
  18. if (token.getType() == Token.ATOM) {
  19. return token.getValue();
  20. }
  21. }
  22. // not ATOMs found, just return the entire header value....somebody might be able to make sense of
  23. // this.
  24. return encoding;
  25. }
  26. // no header, nothing to return.
  27. return null;
  28. }

代码示例来源:origin: org.apache.geronimo.specs/geronimo-javamail_1.4_spec

  1. /**
  2. * Set a new dispostion value for the "Content-Disposition" field.
  3. * If the new value is null, the header is removed.
  4. *
  5. * @param disposition
  6. * The new disposition value.
  7. *
  8. * @exception MessagingException
  9. */
  10. public void setDisposition(String disposition) throws MessagingException {
  11. if (disposition == null) {
  12. removeHeader("Content-Disposition");
  13. }
  14. else {
  15. // the disposition has parameters, which we'll attempt to preserve in any existing header.
  16. String currentHeader = getSingleHeader("Content-Disposition");
  17. if (currentHeader != null) {
  18. ContentDisposition content = new ContentDisposition(currentHeader);
  19. content.setDisposition(disposition);
  20. setHeader("Content-Disposition", content.toString());
  21. }
  22. else {
  23. // set using the raw string.
  24. setHeader("Content-Disposition", disposition);
  25. }
  26. }
  27. }

代码示例来源:origin: org.apache.geronimo.specs/geronimo-javamail_1.3.1_spec

  1. /**
  2. * Set a new dispostion value for the "Content-Disposition" field.
  3. * If the new value is null, the header is removed.
  4. *
  5. * @param disposition
  6. * The new disposition value.
  7. *
  8. * @exception MessagingException
  9. */
  10. public void setDisposition(String disposition) throws MessagingException {
  11. if (disposition == null) {
  12. removeHeader("Content-Disposition");
  13. }
  14. else {
  15. // the disposition has parameters, which we'll attempt to preserve in any existing header.
  16. String currentHeader = getSingleHeader("Content-Disposition");
  17. if (currentHeader != null) {
  18. ContentDisposition content = new ContentDisposition(currentHeader);
  19. content.setDisposition(disposition);
  20. setHeader("Content-Disposition", content.toString());
  21. }
  22. else {
  23. // set using the raw string.
  24. setHeader("Content-Disposition", disposition);
  25. }
  26. }
  27. }

代码示例来源:origin: org.apache.geronimo.specs/geronimo-javamail_1.3.1_spec

  1. if (getSingleHeader("Content-Transfer-Encoding") == null) {
  2. setHeader("Content-Transfer-Encoding", MimeUtility.getEncoding(handler));
  3. if (getSingleHeader("Content-Type") == null) {

代码示例来源:origin: org.apache.geronimo.specs/geronimo-javamail_1.4_spec

  1. String explicitType = getSingleHeader("Content-Type");
  2. if (getSingleHeader("Content-Transfer-Encoding") == null) {
  3. setHeader("Content-Transfer-Encoding", MimeUtility.getEncoding(handler));

相关文章