本文整理了Java中javax.mail.internet.MimeMessage.isMimeType()
方法的一些代码示例,展示了MimeMessage.isMimeType()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MimeMessage.isMimeType()
方法的具体详情如下:
包路径:javax.mail.internet.MimeMessage
类名称:MimeMessage
方法名:isMimeType
[英]Is this Part of the specified MIME type? This method compares only the primaryType
and subType
. The parameters of the content types are ignored.
For example, this method will return true
when comparing a Part of content type "text/plain" with "text/plain; charset=foobar".
If the subType
of mimeType
is the special character '', then the subtype is ignored during the comparison.
[中]这是指定MIME类型的一部分吗?此方法仅比较primaryType
和subType
。内容类型的参数将被忽略。
例如,当比较内容类型“text/plain”与“text/plain;charset=foobar”的一部分时,此方法将返回true
。
如果mimeType
的subType
是特殊字符“”,则在比较过程中忽略子类型。
代码示例来源:origin: TEAMMATES/teammates
/**
* Gets the email message body as text.
*/
private String getTextFromEmail(MimeMessage email) throws MessagingException, IOException {
if (email.isMimeType("text/*")) {
return (String) email.getContent();
} else {
return getTextFromPart(email);
}
}
代码示例来源:origin: org.apache.james/james-server-core-library
/**
* @see javax.mail.Part#isMimeType(java.lang.String)
*/
public boolean isMimeType(String mimeType) throws MessagingException {
return getWrappedMessage().isMimeType(mimeType);
}
代码示例来源:origin: org.apache.james/apache-mailet-crypto
@Override
public Collection<MailAddress> match(Mail mail) throws MessagingException {
if (mail == null) {
return null;
}
MimeMessage message = mail.getMessage();
if (message == null) {
return null;
}
if (message.isMimeType("multipart/signed")
|| message.isMimeType("application/pkcs7-signature")
|| message.isMimeType("application/x-pkcs7-signature")
|| ((message.isMimeType("application/pkcs7-mime") || message.isMimeType("application/x-pkcs7-mime"))
&& message.getContentType().contains("signed-data"))) {
return mail.getRecipients();
} else {
return null;
}
}
}
代码示例来源:origin: at.researchstudio.sat/won-bot
public static String getMailText(MimeMessage message) throws MessagingException, IOException {
if (message.isMimeType("text/plain")) {
return message.getContent().toString();
} else if (message.isMimeType("multipart/*")) {
return getMailTextFromMultiPart((MimeMultipart) message.getContent());
}
return null;
}
代码示例来源:origin: org.apache.james/apache-mailet-crypto
@Override
public Collection<MailAddress> match(Mail mail) throws MessagingException {
if (mail == null) {
return null;
}
MimeMessage message = mail.getMessage();
if (message == null) {
return null;
}
if ((message.isMimeType("application/x-pkcs7-mime")
|| message.isMimeType("application/pkcs7-mime")) && (message.getContentType().contains("smime-type=enveloped-data"))) {
return mail.getRecipients();
} else {
return null;
}
}
代码示例来源:origin: org.apache.james/james-server-jmap
@Override
public void service(Mail mail) throws MessagingException {
MimeMessage mimeMessage = mail.getMessage();
if (mimeMessage.isMimeType(TEXT_CALENDAR_TYPE)) {
processTextBodyAsAttachment(mimeMessage);
}
}
代码示例来源:origin: org.nhind/xdmail
/**
* {@inheritDoc}
*/
@Override
public Collection<MailAddress> match(Mail mail) throws MessagingException {
LOGGER.info("Attempting to match XD recipients");
Collection<MailAddress> recipients = new ArrayList<MailAddress>();
MimeMessage message = mail.getMessage();
if (message.isMimeType("application/x-pkcs7-mime") || message.isMimeType("application/pkcs7-mime")) {
LOGGER.info("MimeMessage is SMIME, skipping");
return Collections.<MailAddress>emptyList();
}
for (MailAddress addr : (Collection<MailAddress>) mail.getRecipients()) {
if (routingResolver.isXdEndpoint(addr.toString())) {
recipients.add(addr);
}
}
if (recipients.isEmpty()) {
LOGGER.info("Matched no recipients");
} else {
for (MailAddress addr : recipients) {
LOGGER.info("Matched recipient " + addr.toString());
}
}
return recipients;
}
代码示例来源:origin: org.apache.james/apache-standard-mailets
new ByteArrayInputStream(bytes));
MimeBodyPart p = new MimeBodyPart(is);
if (!(message.isMimeType("multipart/*") && (message
.getContent() instanceof MimeMultipart))) {
Object content = message.getContent();
代码示例来源:origin: org.apache.james/apache-mailet-crypto
boolean isAlreadySigned = mimeMessage.isMimeType("multipart/signed")
|| mimeMessage.isMimeType("application/pkcs7-mime");
if (isAlreadySigned) {
LOGGER.info("Can not sign a mail already signed");
代码示例来源:origin: org.apache.james/james-server-jmap
@Test
public void serviceShouldThrowWhenMessageCanNotGetContentType() throws Exception {
expectedException.expect(MessagingException.class);
MimeMessage message = mock(MimeMessage.class);
Mail mail = FakeMail.from(message);
when(message.isMimeType(anyString())).thenThrow(new MessagingException());
mailet.service(mail);
}
代码示例来源:origin: difi/oxalis
private SignedMessage(MimeMessage message) throws IOException, OxalisAs2Exception {
try {
// Verify content type
if (!message.isMimeType("multipart/signed"))
throw new OxalisAs2Exception("Received content is not 'multipart/signed'.");
micalg = extractMicalg(message);
// Extract headers
//noinspection unchecked
// headers = Collections.list((Enumeration<Header>) message.getAllHeaders());
// Create MimeMultitype
mimeMultipart = (MimeMultipart) message.getContent();
// Extracting signature
signature = ByteStreams.toByteArray(mimeMultipart.getBodyPart(1).getInputStream());
// Create signed message
smimeSigned = new SMIMESigned(mimeMultipart);
} catch (CMSException | MessagingException e) {
throw new OxalisAs2Exception("Unable to parse received content.", e);
}
}
代码示例来源:origin: no.difi.oxalis/oxalis-as2
private SignedMessage(MimeMessage message) throws IOException, OxalisAs2Exception {
try {
// Verify content type
if (!message.isMimeType("multipart/signed"))
throw new OxalisAs2Exception("Received content is not 'multipart/signed'.");
micalg = extractMicalg(message);
// Extract headers
//noinspection unchecked
// headers = Collections.list((Enumeration<Header>) message.getAllHeaders());
// Create MimeMultitype
mimeMultipart = (MimeMultipart) message.getContent();
// Extracting signature
signature = ByteStreams.toByteArray(mimeMultipart.getBodyPart(1).getInputStream());
// Create signed message
smimeSigned = new SMIMESigned(mimeMultipart);
} catch (CMSException | MessagingException e) {
throw new OxalisAs2Exception("Unable to parse received content.", e);
}
}
代码示例来源:origin: com.axway.ats.framework/ats-actionlibrary
/**
* Get the internal SMIMESigned message
*
* @return the SMIMESigned message instance
* @throws PackageException
*/
public SMIMESigned getSMIMESignedMessage() throws PackageException {
if (smimeSignedMessage == null && message != null) {
// smimeSignedMessage is not 'null' if the message is signed and already decrypted
final String notASignedMessage = "The Content-Type is '"
+ CONTENT_TYPE_MULTIPART_SIGNED
+ "' but could not create SMIMESigned message";
try {
if (message.isMimeType(CONTENT_TYPE_MULTIPART_SIGNED)) {
smimeSignedMessage = new SMIMESigned((MimeMultipart) message.getContent());
}
} catch (MessagingException me) {
throw new PackageException("Could not get message details", me);
} catch (CMSException e) {
throw new PackageException(notASignedMessage, e);
} catch (IOException e) {
throw new PackageException(notASignedMessage, e);
}
}
return smimeSignedMessage;
}
代码示例来源:origin: org.apache.james/apache-standard-mailets
/**
* Service the mail: scan it for attchemnts matching the pattern, store the
* content of a matchin attachment in the given directory.
*
* @param mail
* The mail to service
* @throws MailetException
* Thrown when an error situation is encountered.
*/
public void service(Mail mail) throws MailetException {
MimeMessage message = null;
try {
message = mail.getMessage();
} catch (MessagingException e) {
throw new MailetException(
"Could not retrieve message from Mail object", e);
}
// All MIME messages with an attachment are multipart, so we do nothing
// if it is not mutlipart
try {
if (message.isMimeType("multipart/*")) {
analyseMultipartPartMessage(message, mail);
}
} catch (MessagingException e) {
throw new MailetException(
"Could not retrieve contenttype of message.", e);
} catch (Exception e) {
throw new MailetException("Could not analyse message.", e);
}
}
代码示例来源:origin: org.apache.james/apache-mailet-crypto
Part strippedMessage = null;
LOGGER.info("Starting message decryption..");
if (message.isMimeType("application/x-pkcs7-mime") || message.isMimeType("application/pkcs7-mime")) {
try {
SMIMEEnveloped env = new SMIMEEnveloped(message);
代码示例来源:origin: org.apache.jmeter/ApacheJMeter_components
log.debug("Content-type: {}", msg.getContentType());
if (msg.isMimeType("multipart/signed")) { // $NON-NLS-1$
MimeMultipart multipart = (MimeMultipart) msg.getContent();
s = new SMIMESignedParser(new BcDigestCalculatorProvider(), multipart);
} else if (msg.isMimeType("application/pkcs7-mime") // $NON-NLS-1$
|| msg.isMimeType("application/x-pkcs7-mime")) { // $NON-NLS-1$
s = new SMIMESignedParser(new BcDigestCalculatorProvider(), msg);
代码示例来源:origin: org.apache.james/james-server-jmap
@Test
public void serviceShouldChangeMessageContentTypeToMultipartWhenTextCalendarMessage() throws Exception {
String messageContent = "Content-type: text/calendar; method=REPLY; charset=UTF-8\n" +
"Content-transfer-encoding: 8BIT\n" +
"\n" +
"BEGIN:VCALENDAR";
MimeMessage message = MimeMessageUtil.mimeMessageFromString(messageContent);
Mail mail = FakeMail.builder()
.mimeMessage(message)
.build();
mailet.service(mail);
assertThat(mail.getMessage().isMimeType("multipart/*")).isTrue();
}
代码示例来源:origin: org.apache.james/james-server-jmap
@Test
public void serviceShouldKeepMessageAsItIsWhenMessageIsNotTextCalendar() throws Exception {
String messageContent = "Content-type: text/html; method=REPLY; charset=UTF-8\n" +
"Content-transfer-encoding: 8BIT\n" +
"\n" +
"BEGIN:VCALENDAR";
MimeMessage message = MimeMessageUtil.mimeMessageFromString(messageContent);
Mail mail = FakeMail.builder()
.mimeMessage(message)
.build();
mailet.service(mail);
assertThat(mail.getMessage().isMimeType("text/html")).isTrue();
assertThat(mail.getMessage().getDisposition()).isNull();
}
代码示例来源:origin: org.apache.james/apache-standard-mailets
else if (mail.getMessage().isMimeType("text/html")) {
setContentFromPart(mail.getMessage(), mail.getMessage(), html2Text((String) mail.getMessage().getContent()), true);
内容来源于网络,如有侵权,请联系作者删除!