本文整理匯總了Java中javax.mail.internet.MimeMultipart.getBodyPart方法的典型用法代碼示例。如果您正苦於以下問題:Java MimeMultipart.getBodyPart方法的具體用法?Java MimeMultipart.getBodyPart怎麽用?Java MimeMultipart.getBodyPart使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.mail.internet.MimeMultipart
的用法示例。
在下文中一共展示了MimeMultipart.getBodyPart方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getTextFromMimeMultipart
import javax.mail.internet.MimeMultipart; //導入方法依賴的package包/類
/**
* Extracts the text content of a multipart email message
*/
private String getTextFromMimeMultipart(MimeMultipart mimeMultipart) throws Exception {
String result = "";
int partCount = mimeMultipart.getCount();
for (int i = 0; i < partCount; i++) {
BodyPart bodyPart = mimeMultipart.getBodyPart(i);
if (bodyPart.isMimeType("text/plain")) {
result = result + "\n" + bodyPart.getContent();
break; // without break same text appears twice in my tests
} else if (bodyPart.isMimeType("text/html")) {
String html = (String) bodyPart.getContent();
// result = result + "\n" + org.jsoup.Jsoup.parse(html).text();
result = html;
} else if (bodyPart.getContent() instanceof MimeMultipart) {
result = result + getTextFromMimeMultipart((MimeMultipart) bodyPart.getContent());
}
}
return result;
}
示例2: toString
import javax.mail.internet.MimeMultipart; //導入方法依賴的package包/類
/**
* Converts the given JavaMail message to a String body.
* Can return null.
*/
@Converter
public static String toString(Message message) throws MessagingException, IOException {
Object content = message.getContent();
if (content instanceof MimeMultipart) {
MimeMultipart multipart = (MimeMultipart) content;
if (multipart.getCount() > 0) {
BodyPart part = multipart.getBodyPart(0);
content = part.getContent();
}
}
if (content != null) {
return content.toString();
}
return null;
}
示例3: isContainAttachment
import javax.mail.internet.MimeMultipart; //導入方法依賴的package包/類
/**
* �ж��ʼ����Ƿ��������
* @param msg �ʼ�����
* @return �ʼ��д��ڸ�������true�������ڷ���false
*/
public static boolean isContainAttachment(Part part) throws MessagingException, IOException {
boolean flag = false;
if (part.isMimeType("multipart/*")) {
MimeMultipart multipart = (MimeMultipart) part.getContent();
int partCount = multipart.getCount();
for (int i = 0; i < partCount; i++) {
BodyPart bodyPart = multipart.getBodyPart(i);
String disp = bodyPart.getDisposition();
if (disp != null && (disp.equalsIgnoreCase(Part.ATTACHMENT) || disp.equalsIgnoreCase(Part.INLINE))) {
flag = true;
} else if (bodyPart.isMimeType("multipart/*")) {
flag = isContainAttachment(bodyPart);
} else {
String contentType = bodyPart.getContentType();
if (contentType.indexOf("application") != -1) {
flag = true;
}
if (contentType.indexOf("name") != -1) {
flag = true;
}
}
if (flag) break;
}
} else if (part.isMimeType("message/rfc822")) {
flag = isContainAttachment((Part)part.getContent());
}
return flag;
}
示例4: isContainAttachment
import javax.mail.internet.MimeMultipart; //導入方法依賴的package包/類
/**
* 判斷郵件中是否包含附件
* @param msg 郵件內容
* @return 郵件中存在附件返回true,不存在返回false
* @throws MessagingException
* @throws IOException
*/
public static boolean isContainAttachment(Part part) throws MessagingException, IOException {
boolean flag = false;
if (part.isMimeType("multipart/*")) {
MimeMultipart multipart = (MimeMultipart) part.getContent();
int partCount = multipart.getCount();
for (int i = 0; i < partCount; i++) {
BodyPart bodyPart = multipart.getBodyPart(i);
String disp = bodyPart.getDisposition();
if (disp != null && (disp.equalsIgnoreCase(Part.ATTACHMENT) || disp.equalsIgnoreCase(Part.INLINE))) {
flag = true;
} else if (bodyPart.isMimeType("multipart/*")) {
flag = isContainAttachment(bodyPart);
} else {
String contentType = bodyPart.getContentType();
if (contentType.indexOf("application") != -1) {
flag = true;
}
if (contentType.indexOf("name") != -1) {
flag = true;
}
}
if (flag) break;
}
} else if (part.isMimeType("message/rfc822")) {
flag = isContainAttachment((Part)part.getContent());
}
return flag;
}
示例5: getTextFromMimeMultipart
import javax.mail.internet.MimeMultipart; //導入方法依賴的package包/類
private String getTextFromMimeMultipart(MimeMultipart mimeMultipart)
throws MessagingException, IOException {
StringBuilder result = new StringBuilder();
int count = mimeMultipart.getCount();
for (int i = 0; i < count; i++) {
BodyPart bodyPart = mimeMultipart.getBodyPart(i);
if (bodyPart.isMimeType("text/plain")) {
result.append("\n").append(bodyPart.getContent());
} else if (bodyPart.isMimeType("text/html")) {
result.append("\n").append((String) bodyPart.getContent());
} else if (bodyPart.getContent() instanceof MimeMultipart) {
result.append(getTextFromMimeMultipart((MimeMultipart) bodyPart.getContent()));
}
}
return result.toString();
}
示例6: hasNonTextAttachments
import javax.mail.internet.MimeMultipart; //導入方法依賴的package包/類
public static boolean hasNonTextAttachments(Part m) {
try {
Object content = m.getContent();
if (content instanceof MimeMultipart) {
MimeMultipart mm = (MimeMultipart) content;
for (int i=0;i<mm.getCount();i++) {
BodyPart p = mm.getBodyPart(i);
if (hasNonTextAttachments(p)) {
return true;
}
}
return false;
} else {
return !m.getContentType().trim().toLowerCase().startsWith("text");
}
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
示例7: getTextFromMimeMultipart
import javax.mail.internet.MimeMultipart; //導入方法依賴的package包/類
private String getTextFromMimeMultipart( MimeMultipart mimeMultipart ) throws IOException, MessagingException
{
int count = mimeMultipart.getCount();
if ( count == 0 )
throw new MessagingException( "Multipart with no body parts not supported." );
boolean multipartAlt = new ContentType( mimeMultipart.getContentType() ).match( "multipart/alternative" );
if ( multipartAlt )
return getTextFromBodyPart( mimeMultipart.getBodyPart( count - 1 ) );
String result = "";
for ( int i = 0; i < count; i++ )
{
BodyPart bodyPart = mimeMultipart.getBodyPart( i );
result += getTextFromBodyPart( bodyPart );
}
return result;
}
示例8: appendMultiPart
import javax.mail.internet.MimeMultipart; //導入方法依賴的package包/類
private void appendMultiPart(SampleResult child, StringBuilder cdata,
MimeMultipart mmp) throws MessagingException, IOException {
String preamble = mmp.getPreamble();
if (preamble != null ){
cdata.append(preamble);
}
child.setResponseData(cdata.toString(),child.getDataEncodingNoDefault());
int count = mmp.getCount();
for (int j=0; j<count;j++){
BodyPart bodyPart = mmp.getBodyPart(j);
final Object bodyPartContent = bodyPart.getContent();
final String contentType = bodyPart.getContentType();
SampleResult sr = new SampleResult();
sr.setSampleLabel("Part: "+j);
sr.setContentType(contentType);
sr.setDataEncoding(RFC_822_DEFAULT_ENCODING);
sr.setEncodingAndType(contentType);
sr.sampleStart();
if (bodyPartContent instanceof InputStream){
sr.setResponseData(IOUtils.toByteArray((InputStream) bodyPartContent));
} else if (bodyPartContent instanceof MimeMultipart){
appendMultiPart(sr, cdata, (MimeMultipart) bodyPartContent);
} else {
sr.setResponseData(bodyPartContent.toString(),sr.getDataEncodingNoDefault());
}
sr.setResponseOK();
if (sr.getEndTime()==0){// not been set by any child samples
sr.sampleEnd();
}
child.addSubResult(sr);
}
}
示例9: parseMDN
import javax.mail.internet.MimeMultipart; //導入方法依賴的package包/類
private void parseMDN(MimeMultipart report) throws AS2MessageException {
try {
int reportCount = report.getCount();
for (int i = 0; i < reportCount; i++) {
MimeBodyPart reportsPart = (MimeBodyPart) report.getBodyPart(i);
if (reportsPart.isMimeType("text/plain")) {
setText(reportsPart.getContent().toString());
}
else if (reportsPart.isMimeType(AS2Header.CONTENT_TYPE_MESSAGE_DISPOSITION_NOTIFICATION)) {
InternetHeaders rptValues = new InternetHeaders(reportsPart
.getInputStream());
setReportValue(REPORTING_UA, rptValues.getHeader(
REPORTING_UA, ", "));
setOriginalMessageID(rptValues.getHeader(
ORIG_RECIPIENT, ", "));
setReportValue(FINAL_RECIPIENT, rptValues.getHeader(
FINAL_RECIPIENT, ", "));
setReportValue(ORIG_MESSAGE_ID, rptValues.getHeader(
ORIG_MESSAGE_ID, ", "));
setReportValue(DISPOSITION, rptValues.getHeader(
DISPOSITION, ", "));
setReportValue(RECEIVED_CONTENT_MIC, rptValues
.getHeader(RECEIVED_CONTENT_MIC, ", "));
}
}
}
catch (Exception e) {
throw new AS2MessageException("Error in parsing MDN", e);
}
}
示例10: getTextPart
import javax.mail.internet.MimeMultipart; //導入方法依賴的package包/類
private MimeBodyPart getTextPart(MimeMessage msg) throws IOException, MessagingException {
assertTrue(msg.getContent() instanceof MimeMultipart);
MimeMultipart mimeMultipart = (MimeMultipart) msg.getContent();
Object content2 = mimeMultipart.getBodyPart(0).getContent();
assertTrue(content2 instanceof MimeMultipart);
MimeMultipart textBodyPart = (MimeMultipart) content2;
return (MimeBodyPart) textBodyPart.getBodyPart(0);
}
示例11: getInlineAttachment
import javax.mail.internet.MimeMultipart; //導入方法依賴的package包/類
private MimeBodyPart getInlineAttachment(MimeMessage msg) throws IOException, MessagingException {
assertTrue(msg.getContent() instanceof MimeMultipart);
MimeMultipart mimeMultipart = (MimeMultipart) msg.getContent();
Object content2 = mimeMultipart.getBodyPart(0).getContent();
assertTrue(content2 instanceof MimeMultipart);
MimeMultipart textBodyPart = (MimeMultipart) content2;
return (MimeBodyPart) textBodyPart.getBodyPart(1);
}
示例12: postAdminUploadmultipart
import javax.mail.internet.MimeMultipart; //導入方法依賴的package包/類
@Validate
@Override
public void postAdminUploadmultipart(PersistMethod persistMethod, String busAddress,
String fileName, MimeMultipart entity, Map<String, String> okapiHeaders,
Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) throws Exception {
if(entity != null){
int parts = entity.getCount();
for (int i = 0; i < parts; i++) {
BodyPart bp = entity.getBodyPart(i);
System.out.println(bp.getFileName());
//System.out.println(bp.getContent());
//System.out.println("-----------------------------------------");
}
String name = "";
try{
if(fileName == null){
name = entity.getBodyPart(0).getFileName();
}
else{
name = fileName;
}
}
catch(Exception e){
log.error(e.getMessage(), e);
}
}
asyncResultHandler.handle(io.vertx.core.Future.succeededFuture(PostAdminUploadmultipartResponse.withOK("TODO"
)));
}
示例13: createMessage
import javax.mail.internet.MimeMultipart; //導入方法依賴的package包/類
/**
* Creates a MIME message from a SOAP message.
*
* @param from the 'from' mail address.
* @param to the 'to' mail address(es).
* @param cc the 'cc' mail address(es).
* @param subject the mail subject.
* @param soapMessage the SOAP message.
* @param session the mail session.
* @return a new MIME message.
* @throws ConnectionException if error occurred in constructing the mail
* message.
* @see hk.hku.cecid.piazza.commons.net.MailSender#createMessage(java.lang.String, java.lang.String, java.lang.String, java.lang.String, javax.mail.Session)
*/
public MimeMessage createMessage(String from, String to, String cc,
String subject, SOAPMessage soapMessage, Session session) throws ConnectionException {
try {
MimeMessage message = super.createMessage(from, to, cc, subject, session);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
soapMessage.writeTo(bos);
String contentType = getContentType(soapMessage);
ByteArrayDataSource content = new ByteArrayDataSource(bos.toByteArray(), contentType);
soapMessage.getAttachments();
boolean hasAttachments = soapMessage.countAttachments() > 0;
if (hasAttachments) {
putHeaders(soapMessage.getMimeHeaders(), message);
MimeMultipart mmp = new MimeMultipart(content);
for (int i=0; i<mmp.getCount(); i++) {
BodyPart bp = mmp.getBodyPart(i);
// encoding all parts in base64 to overcome length of character line limitation in SMTP
InputStreamDataSource isds = new InputStreamDataSource(
bp.getInputStream(), bp.getContentType(), bp.getFileName());
bp.setDataHandler(new DataHandler(isds));
bp.setHeader("Content-Transfer-Encoding", "base64");
}
message.setContent(mmp);
}
else {
DataHandler dh = new DataHandler(content);
message.setDataHandler(dh);
message.setHeader("Content-Transfer-Encoding", "base64");
}
message.saveChanges();
return message;
}
catch (Exception e) {
throw new ConnectionException("Unable to construct mail message from SOAP message", e);
}
}
示例14: getFirstAttachment
import javax.mail.internet.MimeMultipart; //導入方法依賴的package包/類
private MimeBodyPart getFirstAttachment(MimeMessage msg) throws IOException, MessagingException {
assertTrue(msg.getContent() instanceof MimeMultipart);
MimeMultipart mimeMultipart = (MimeMultipart) msg.getContent();
return (MimeBodyPart) mimeMultipart.getBodyPart(1);
}