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

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

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

MimeBodyPart.getFileName介绍

[英]Get the filename associated with this body part.

Returns the value of the "filename" parameter from the "Content-Disposition" header field of this body part. If its not available, returns the value of the "name" parameter from the "Content-Type" header field of this body part. Returns null if both are absent.

If the mail.mime.decodefilename System property is set to true, the MimeUtility#decodeText method will be used to decode the filename. While such encoding is not supported by the MIME spec, many mailers use this technique to support non-ASCII characters in filenames. The default value of this property is false.
[中]获取与此身体部位关联的文件名。
从该正文部分的“内容处置”标题字段返回“filename”参数的值。如果不可用,则从该正文部分的“内容类型”标题字段返回“名称”参数的值。如果两者都不存在,则返回null
如果mail.mime.decodefilename系统属性设置为true,则将使用MimeUtility#decodeText方法对文件名进行解码。虽然MIME规范不支持这种编码,但许多邮件程序使用这种技术来支持文件名中的非ASCII字符。此属性的默认值为false。

代码示例

代码示例来源:origin: camunda/camunda-bpm-platform

  1. /**
  2. * DataSource method to return a name. <p>
  3. *
  4. * This implementation just returns an empty string.
  5. */
  6. public String getName() {
  7. try {
  8. if (part instanceof MimeBodyPart)
  9. return ((MimeBodyPart)part).getFileName();
  10. } catch (MessagingException mex) {
  11. // ignore it
  12. }
  13. return "";
  14. }

代码示例来源:origin: com.sun.mail/javax.mail

  1. /**
  2. * DataSource method to return a name. <p>
  3. *
  4. * This implementation just returns an empty string.
  5. */
  6. @Override
  7. public String getName() {
  8. try {
  9. if (part instanceof MimeBodyPart)
  10. return ((MimeBodyPart)part).getFileName();
  11. } catch (MessagingException mex) {
  12. // ignore it
  13. }
  14. return "";
  15. }

代码示例来源:origin: camunda/camunda-bpm-platform

  1. /**
  2. * Get the filename associated with this body part. <p>
  3. *
  4. * Returns the value of the "filename" parameter from the
  5. * "Content-Disposition" header field of this body part. If its
  6. * not available, returns the value of the "name" parameter from
  7. * the "Content-Type" header field of this body part.
  8. * Returns <code>null</code> if both are absent. <p>
  9. *
  10. * If the <code>mail.mime.decodefilename</code> System property
  11. * is set to true, the {@link MimeUtility#decodeText
  12. * MimeUtility.decodeText} method will be used to decode the
  13. * filename. While such encoding is not supported by the MIME
  14. * spec, many mailers use this technique to support non-ASCII
  15. * characters in filenames. The default value of this property
  16. * is false.
  17. *
  18. * @return filename
  19. */
  20. public String getFileName() throws MessagingException {
  21. return getFileName(this);
  22. }

代码示例来源:origin: camunda/camunda-bpm-platform

  1. /**
  2. * Get the filename associated with this Message. <p>
  3. *
  4. * Returns the value of the "filename" parameter from the
  5. * "Content-Disposition" header field of this message. If it's
  6. * not available, returns the value of the "name" parameter from
  7. * the "Content-Type" header field of this BodyPart.
  8. * Returns <code>null</code> if both are absent. <p>
  9. *
  10. * If the <code>mail.mime.encodefilename</code> System property
  11. * is set to true, the {@link MimeUtility#decodeText
  12. * MimeUtility.decodeText} method will be used to decode the
  13. * filename. While such encoding is not supported by the MIME
  14. * spec, many mailers use this technique to support non-ASCII
  15. * characters in filenames. The default value of this property
  16. * is false.
  17. *
  18. * @return filename
  19. * @exception MessagingException for failures
  20. */
  21. public String getFileName() throws MessagingException {
  22. return MimeBodyPart.getFileName(this);
  23. }

代码示例来源:origin: com.sun.mail/javax.mail

  1. /**
  2. * Get the filename associated with this body part. <p>
  3. *
  4. * Returns the value of the "filename" parameter from the
  5. * "Content-Disposition" header field of this body part. If its
  6. * not available, returns the value of the "name" parameter from
  7. * the "Content-Type" header field of this body part.
  8. * Returns <code>null</code> if both are absent. <p>
  9. *
  10. * If the <code>mail.mime.decodefilename</code> System property
  11. * is set to true, the {@link MimeUtility#decodeText
  12. * MimeUtility.decodeText} method will be used to decode the
  13. * filename. While such encoding is not supported by the MIME
  14. * spec, many mailers use this technique to support non-ASCII
  15. * characters in filenames. The default value of this property
  16. * is false.
  17. *
  18. * @return filename
  19. */
  20. @Override
  21. public String getFileName() throws MessagingException {
  22. return getFileName(this);
  23. }

代码示例来源:origin: com.sun.mail/javax.mail

  1. /**
  2. * Get the filename associated with this Message. <p>
  3. *
  4. * Returns the value of the "filename" parameter from the
  5. * "Content-Disposition" header field of this message. If it's
  6. * not available, returns the value of the "name" parameter from
  7. * the "Content-Type" header field of this BodyPart.
  8. * Returns <code>null</code> if both are absent. <p>
  9. *
  10. * If the <code>mail.mime.encodefilename</code> System property
  11. * is set to true, the {@link MimeUtility#decodeText
  12. * MimeUtility.decodeText} method will be used to decode the
  13. * filename. While such encoding is not supported by the MIME
  14. * spec, many mailers use this technique to support non-ASCII
  15. * characters in filenames. The default value of this property
  16. * is false.
  17. *
  18. * @return filename
  19. * @exception MessagingException for failures
  20. */
  21. @Override
  22. public String getFileName() throws MessagingException {
  23. return MimeBodyPart.getFileName(this);
  24. }

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

  1. public String getName() {
  2. try {
  3. if (part instanceof MimeBodyPart) {
  4. return ((MimeBodyPart) part).getFileName();
  5. }
  6. } catch (MessagingException mex) {
  7. // ignore it
  8. }
  9. return "";
  10. }

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.javax.mail

  1. /**
  2. * DataSource method to return a name. <p>
  3. *
  4. * This implementation just returns an empty string.
  5. */
  6. public String getName() {
  7. try {
  8. if (part instanceof MimeBodyPart)
  9. return ((MimeBodyPart)part).getFileName();
  10. } catch (MessagingException mex) {
  11. // ignore it
  12. }
  13. return "";
  14. }

代码示例来源:origin: javax.mail/com.springsource.javax.mail

  1. /**
  2. * DataSource method to return a name. <p>
  3. *
  4. * This implementation just returns an empty string.
  5. */
  6. public String getName() {
  7. try {
  8. if (part instanceof MimeBodyPart)
  9. return ((MimeBodyPart)part).getFileName();
  10. } catch (MessagingException mex) {
  11. // ignore it
  12. }
  13. return "";
  14. }

代码示例来源:origin: javax.mail/javax.mail-api

  1. /**
  2. * DataSource method to return a name. <p>
  3. *
  4. * This implementation just returns an empty string.
  5. */
  6. @Override
  7. public String getName() {
  8. try {
  9. if (part instanceof MimeBodyPart)
  10. return ((MimeBodyPart)part).getFileName();
  11. } catch (MessagingException mex) {
  12. // ignore it
  13. }
  14. return "";
  15. }

代码示例来源:origin: com.sun.mail/android-mail

  1. /**
  2. * DataSource method to return a name. <p>
  3. *
  4. * This implementation just returns an empty string.
  5. */
  6. @Override
  7. public String getName() {
  8. try {
  9. if (part instanceof MimeBodyPart)
  10. return ((MimeBodyPart)part).getFileName();
  11. } catch (MessagingException mex) {
  12. // ignore it
  13. }
  14. return "";
  15. }

代码示例来源:origin: jboss/jboss-javaee-specs

  1. /**
  2. * DataSource method to return a name. <p>
  3. *
  4. * This implementation just returns an empty string.
  5. */
  6. @Override
  7. public String getName() {
  8. try {
  9. if (part instanceof MimeBodyPart)
  10. return ((MimeBodyPart)part).getFileName();
  11. } catch (MessagingException mex) {
  12. // ignore it
  13. }
  14. return "";
  15. }

代码示例来源:origin: com.sun.mail/mailapi

  1. /**
  2. * DataSource method to return a name. <p>
  3. *
  4. * This implementation just returns an empty string.
  5. */
  6. @Override
  7. public String getName() {
  8. try {
  9. if (part instanceof MimeBodyPart)
  10. return ((MimeBodyPart)part).getFileName();
  11. } catch (MessagingException mex) {
  12. // ignore it
  13. }
  14. return "";
  15. }

代码示例来源:origin: com.sun.mail/jakarta.mail

  1. /**
  2. * DataSource method to return a name. <p>
  3. *
  4. * This implementation just returns an empty string.
  5. */
  6. @Override
  7. public String getName() {
  8. try {
  9. if (part instanceof MimeBodyPart)
  10. return ((MimeBodyPart)part).getFileName();
  11. } catch (MessagingException mex) {
  12. // ignore it
  13. }
  14. return "";
  15. }

代码示例来源:origin: org.glassfish.metro/webservices-extra

  1. /**
  2. * DataSource method to return a name. <p>
  3. *
  4. * This implementation just returns an empty string.
  5. */
  6. @Override
  7. public String getName() {
  8. try {
  9. if (part instanceof MimeBodyPart)
  10. return ((MimeBodyPart)part).getFileName();
  11. } catch (MessagingException mex) {
  12. // ignore it
  13. }
  14. return "";
  15. }

代码示例来源:origin: camunda/camunda-bpm-platform

  1. String name = parts[i].getFileName();
  2. if (isEmpty(name)) { //Exceptional case.
  3. name = toString(attachmentFormatters[i]);

代码示例来源:origin: com.sun.mail/javax.mail

  1. String name = parts[i].getFileName();
  2. if (isEmpty(name)) { //Exceptional case.
  3. name = toString(attachmentFormatters[i]);

代码示例来源:origin: org.apache.james/apache-mailet-icalendar

  1. private void setFileNameIfNeeded(MimeBodyPart mimeBodyPart) throws MessagingException {
  2. if (mimeBodyPart.getFileName() == null) {
  3. mimeBodyPart.setFileName(DEFAULT_FILENAME);
  4. }
  5. }

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.javax.mail

  1. /**
  2. * Get the filename associated with this BodyPart. <p>
  3. *
  4. * Returns the value of the "filename" parameter from the
  5. * "Content-Disposition" header field of this BodyPart. If its
  6. * not available, returns the value of the "name" parameter from
  7. * the "Content-Type" header field of this BodyPart.
  8. * Returns <code>null</code> if both are absent.
  9. *
  10. * @return filename
  11. */
  12. public String getFileName() throws MessagingException {
  13. String name = super.getFileName();
  14. if (name == null)
  15. name = getHeader("X-Sun-Data-Name", null);
  16. return name;
  17. }

代码示例来源:origin: stackoverflow.com

  1. MimeMultipart multipart = (MimeMultipart) message.getContent();
  2. System.out.println("This message consists of " + multipart.getCount() + " parts");
  3. for (int i = 0; i < multipart.getCount(); i++) {
  4. // Note we're downcasting here, MimeBodyPart is the only subclass
  5. // of BodyPart available in the Java EE spec.
  6. MimeBodyPart bodyPart = (MimeBodyPart) multipart.getBodyPart(i);
  7. System.out.println("Part " + i + " has type " + bodyPart.getContentType());
  8. System.out.println("Part " + i " + has filename " + bodyPart.getFileName()); // if it was an attachment
  9. // So on, so forth.
  10. }

相关文章