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

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

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

MimeBodyPart.getContentID介绍

[英]Returns the value of the "Content-ID" header field. Returns null if the field is unavailable or its value is absent.

This implementation uses getHeader(name) to obtain the requisite header field.
[中]返回“内容ID”标题字段的值。如果字段不可用或其值不存在,则返回null
此实现使用getHeader(name)来获取必需的头字段。

代码示例

代码示例来源:origin: spring-projects/spring-integration-samples

filename = ((MimeBodyPart) bp).getContentID();

代码示例来源:origin: oblac/jodd

/**
 * Correctly resolves file name from the message part.
 * Thanx to: Flavio Pompermaier
 *
 * @param part {@link Part} to decode file name from.
 * @return String containing file name.
 */
public static String resolveFileName(final Part part) throws MessagingException {
  if (!(part instanceof MimeBodyPart)) {
    return part.getFileName();
  }
  final String contentType = part.getContentType();
  String ret;
  try {
    ret = MimeUtility.decodeText(part.getFileName());
  } catch (final Exception ex) {
    // String[] contentId = part.getHeader("Content-ID");
    // if (contentId != null && contentId.length > 0) {
    final String contentId = ((MimeBodyPart) part).getContentID();
    if (contentId != null) {
      ret = contentId + contentTypeForFileName(contentType);
    } else {
      ret = defaultFileName(contentType);
    }
  }
  return ret;
}

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

/**
 * Get the MimeBodyPart referred to by the given ContentID (CID). 
 * Returns null if the part is not found.
 *
 * @param  CID     the ContentID of the desired part
 * @return          the Part
 * @exception    MessagingException for failures
 */
public synchronized BodyPart getBodyPart(String CID) 
    throws MessagingException {
parse();
int count = getCount();
for (int i = 0; i < count; i++) {
  MimeBodyPart part = (MimeBodyPart)getBodyPart(i);
  String s = part.getContentID();
  if (s != null && s.equals(CID))
  return part;    
}
return null;
}

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

/**
 * Get the MimeBodyPart referred to by the given ContentID (CID). 
 * Returns null if the part is not found.
 *
 * @param  CID     the ContentID of the desired part
 * @return          the Part
 * @exception    MessagingException for failures
 */
public synchronized BodyPart getBodyPart(String CID) 
    throws MessagingException {
parse();
int count = getCount();
for (int i = 0; i < count; i++) {
  MimeBodyPart part = (MimeBodyPart)getBodyPart(i);
  String s = part.getContentID();
  if (s != null && s.equals(CID))
  return part;    
}
return null;
}

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

public BodyPart getBodyPart(String cid) throws MessagingException {
  parse();
  for (int i = 0; i < parts.size(); i++) {
    MimeBodyPart bodyPart = (MimeBodyPart) parts.get(i);
    if (cid.equals(bodyPart.getContentID())) {
      return bodyPart;
    }
  }
  return null;
}

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

public BodyPart getBodyPart(String cid) throws MessagingException {
  parse();
  for (int i = 0; i < parts.size(); i++) {
    MimeBodyPart bodyPart = (MimeBodyPart) parts.get(i);
    if (cid.equals(bodyPart.getContentID())) {
      return bodyPart;
    }
  }
  return null;
}

代码示例来源:origin: org.apache.camel/camel-mail

private String getAttachmentKey(BodyPart bp) throws MessagingException, UnsupportedEncodingException {
    // use the filename as key for the map
    String key = bp.getFileName();
    // if there is no file name we use the Content-ID header
    if (key == null && bp instanceof MimeBodyPart) {
      key = ((MimeBodyPart) bp).getContentID();
      if (key != null && key.startsWith("<") && key.length() > 2) {
        // strip <>
        key = key.substring(1, key.length() - 1);
      }
    }
    // or a generated content id
    if (key == null) {
      key = UUID.randomUUID().toString() + "@camel.apache.org";
    }
    return MimeUtility.decodeText(key);
  }
}

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

/**
 * Get the MimeBodyPart referred to by the given ContentID (CID). 
 * Returns null if the part is not found.
 *
 * @param  CID     the ContentID of the desired part
 * @return          the Part
 * @exception    MessagingException for failures
 */
public synchronized BodyPart getBodyPart(String CID) 
    throws MessagingException {
parse();
int count = getCount();
for (int i = 0; i < count; i++) {
  MimeBodyPart part = (MimeBodyPart)getBodyPart(i);
  String s = part.getContentID();
  if (s != null && s.equals(CID))
  return part;    
}
return null;
}

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

/**
 * Get the MimeBodyPart referred to by the given ContentID (CID). 
 * Returns null if the part is not found.
 *
 * @param  CID     the ContentID of the desired part
 * @return          the Part
 */
public synchronized BodyPart getBodyPart(String CID) 
    throws MessagingException {
parse();
int count = getCount();
for (int i = 0; i < count; i++) {
  MimeBodyPart part = (MimeBodyPart)getBodyPart(i);
  String s = part.getContentID();
  if (s != null && s.equals(CID))
  return part;    
}
return null;
}

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

/**
 * Get the MimeBodyPart referred to by the given ContentID (CID). 
 * Returns null if the part is not found.
 *
 * @param  CID     the ContentID of the desired part
 * @return          the Part
 * @exception    MessagingException for failures
 */
public synchronized BodyPart getBodyPart(String CID) 
    throws MessagingException {
parse();
int count = getCount();
for (int i = 0; i < count; i++) {
  MimeBodyPart part = (MimeBodyPart)getBodyPart(i);
  String s = part.getContentID();
  if (s != null && s.equals(CID))
  return part;    
}
return null;
}

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

/**
 * Get the MimeBodyPart referred to by the given ContentID (CID). 
 * Returns null if the part is not found.
 *
 * @param  CID     the ContentID of the desired part
 * @return          the Part
 * @exception    MessagingException for failures
 */
public synchronized BodyPart getBodyPart(String CID) 
    throws MessagingException {
parse();
int count = getCount();
for (int i = 0; i < count; i++) {
  MimeBodyPart part = (MimeBodyPart)getBodyPart(i);
  String s = part.getContentID();
  if (s != null && s.equals(CID))
  return part;    
}
return null;
}

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

/**
 * Get the MimeBodyPart referred to by the given ContentID (CID). 
 * Returns null if the part is not found.
 *
 * @param  CID     the ContentID of the desired part
 * @return          the Part
 */
public synchronized BodyPart getBodyPart(String CID) 
    throws MessagingException {
parse();
int count = getCount();
for (int i = 0; i < count; i++) {
  MimeBodyPart part = (MimeBodyPart)getBodyPart(i);
  String s = part.getContentID();
  if (s != null && s.equals(CID))
  return part;    
}
return null;
}

代码示例来源:origin: org.apache.eagle/eagle-common

mimeBodyPart.setDisposition(MimeBodyPart.ATTACHMENT);
  mimeBodyPart.setContentID(attachment);
  cid.put(attachment,mimeBodyPart.getContentID());
  mimeBodyParts.add(mimeBodyPart);
} catch (MessagingException e) {

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

/**
 * Get the MimeBodyPart referred to by the given ContentID (CID). 
 * Returns null if the part is not found.
 *
 * @param  CID     the ContentID of the desired part
 * @return          the Part
 * @exception    MessagingException for failures
 */
public synchronized BodyPart getBodyPart(String CID) 
    throws MessagingException {
parse();
int count = getCount();
for (int i = 0; i < count; i++) {
  MimeBodyPart part = (MimeBodyPart)getBodyPart(i);
  String s = part.getContentID();
  if (s != null && s.equals(CID))
  return part;    
}
return null;
}

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

/**
 * Get the MimeBodyPart referred to by the given ContentID (CID). 
 * Returns null if the part is not found.
 *
 * @param  CID     the ContentID of the desired part
 * @return          the Part
 * @exception    MessagingException for failures
 */
public synchronized BodyPart getBodyPart(String CID) 
    throws MessagingException {
parse();
int count = getCount();
for (int i = 0; i < count; i++) {
  MimeBodyPart part = (MimeBodyPart)getBodyPart(i);
  String s = part.getContentID();
  if (s != null && s.equals(CID))
  return part;    
}
return null;
}

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

/**
 * Get the MimeBodyPart referred to by the given ContentID (CID). 
 * Returns null if the part is not found.
 *
 * @param  CID     the ContentID of the desired part
 * @return          the Part
 * @exception    MessagingException for failures
 */
public synchronized BodyPart getBodyPart(String CID) 
    throws MessagingException {
parse();
int count = getCount();
for (int i = 0; i < count; i++) {
  MimeBodyPart part = (MimeBodyPart)getBodyPart(i);
  String s = part.getContentID();
  if (s != null && s.equals(CID))
  return part;    
}
return null;
}

代码示例来源:origin: org.codehaus.xfire/xfire-core

private void initMultipart(MimeMultipart multipart) throws MessagingException
{
  this.mimeMP = multipart;
  
  MimeBodyPart part = (MimeBodyPart) multipart.getBodyPart(0);
  setSoapMessage(new SimpleAttachment(part.getContentID(), part.getDataHandler()));
  
  for ( int i = 1; i < multipart.getCount(); i++ )
  {
    part = (MimeBodyPart) multipart.getBodyPart(i);
    String id = part.getContentID();
    if (id.startsWith("<"))
    {
      id = id.substring(1, id.length() - 1);
    }
    
    addPart(new SimpleAttachment(id, part.getDataHandler()));
  }
}

代码示例来源:origin: org.apache.servicemix/servicemix-soap2

MimeBodyPart part = (MimeBodyPart) multipart.getBodyPart(i);
if (part != contentPart) {
  String id = part.getContentID();
  if (id == null) {
    id = "Part" + i;

代码示例来源:origin: org.jodd/jodd-mail

/**
 * Correctly resolves file name from the message part.
 * Thanx to: Flavio Pompermaier
 *
 * @param part {@link Part} to decode file name from.
 * @return String containing file name.
 */
public static String resolveFileName(final Part part) throws MessagingException {
  if (!(part instanceof MimeBodyPart)) {
    return part.getFileName();
  }
  final String contentType = part.getContentType();
  String ret;
  try {
    ret = MimeUtility.decodeText(part.getFileName());
  } catch (final Exception ex) {
    // String[] contentId = part.getHeader("Content-ID");
    // if (contentId != null && contentId.length > 0) {
    final String contentId = ((MimeBodyPart) part).getContentID();
    if (contentId != null) {
      ret = contentId + contentTypeForFileName(contentType);
    } else {
      ret = defaultFileName(contentType);
    }
  }
  return ret;
}

代码示例来源:origin: com.helger/ph-as4-lib

final String sRealContentID = StringHelper.trimStartAndEnd (aBodyPart.getContentID (), '<', '>');
ret.setId (sRealContentID);

相关文章