本文整理汇总了Java中org.apache.mailet.Mail.getAttributeNames方法的典型用法代码示例。如果您正苦于以下问题:Java Mail.getAttributeNames方法的具体用法?Java Mail.getAttributeNames怎么用?Java Mail.getAttributeNames使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.mailet.Mail
的用法示例。
在下文中一共展示了Mail.getAttributeNames方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setAttributes
import org.apache.mailet.Mail; //导入方法依赖的package包/类
/**
* Writes the mail attributes to the <code>jamesattr:*</code> property.
*
* @param node
* mail node
* @param mail
* mail message
* @throws RepositoryException
* if a repository error occurs
* @throws IOException
* if an IO error occurs
*/
private void setAttributes(Node node, Mail mail) throws RepositoryException, IOException {
Iterator<String> iterator = mail.getAttributeNames();
while (iterator.hasNext()) {
String name = (String) iterator.next();
Object value = mail.getAttribute(name);
name = "jamesattr:" + Text.escapeIllegalJcrChars(name);
if (value instanceof String || value == null) {
node.setProperty(name, (String) value);
} else {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream output = new ObjectOutputStream(buffer);
output.writeObject(value);
output.close();
node.setProperty(name, new ByteArrayInputStream(buffer.toByteArray()));
}
}
}
示例2: checkMail
import org.apache.mailet.Mail; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
protected void checkMail(Mail enqueuedMail, Mail dequeuedMail) throws MessagingException, IOException {
assertEquals(enqueuedMail.getErrorMessage(), dequeuedMail.getErrorMessage());
assertEquals(enqueuedMail.getMessageSize(), dequeuedMail.getMessageSize());
assertEquals(enqueuedMail.getName(), dequeuedMail.getName());
assertEquals(enqueuedMail.getRemoteAddr(), dequeuedMail.getRemoteAddr());
assertEquals(enqueuedMail.getState(), dequeuedMail.getState());
assertEquals(enqueuedMail.getLastUpdated(), dequeuedMail.getLastUpdated());
assertEquals(enqueuedMail.getRemoteHost(), dequeuedMail.getRemoteHost());
assertEquals(enqueuedMail.getSender(), dequeuedMail.getSender());
assertEquals(enqueuedMail.getRecipients().size(), dequeuedMail.getRecipients().size());
Iterator<String> attributes = enqueuedMail.getAttributeNames();
while (attributes.hasNext()) {
String name = attributes.next();
assertNotNull(dequeuedMail.getAttribute(name));
}
MimeMessage enqueuedMsg = enqueuedMail.getMessage();
MimeMessage dequeuedMsg = dequeuedMail.getMessage();
Enumeration<String> enQueuedHeaders = enqueuedMsg.getAllHeaderLines();
Enumeration<String> deQueuedHeaders = dequeuedMsg.getAllHeaderLines();
while (enQueuedHeaders.hasMoreElements()) {
assertEquals(enQueuedHeaders.nextElement(), deQueuedHeaders.nextElement());
}
assertFalse(deQueuedHeaders.hasMoreElements());
assertEquals(enqueuedMsg.getContent(), dequeuedMsg.getContent());
}
示例3: getJMSProperties
import org.apache.mailet.Mail; //导入方法依赖的package包/类
/**
* Get JMS Message properties with values
*
* @param mail
* @param delayInMillis
* @throws JMSException
* @throws MessagingException
*/
@SuppressWarnings("unchecked")
protected Map<String, Object> getJMSProperties(Mail mail, long delayInMillis) throws JMSException, MessagingException {
Map<String, Object> props = new HashMap<String, Object>();
long nextDelivery = -1;
if (delayInMillis > 0) {
nextDelivery = System.currentTimeMillis() + delayInMillis;
}
props.put(JAMES_NEXT_DELIVERY, nextDelivery);
props.put(JAMES_MAIL_ERROR_MESSAGE, mail.getErrorMessage());
props.put(JAMES_MAIL_LAST_UPDATED, mail.getLastUpdated().getTime());
props.put(JAMES_MAIL_MESSAGE_SIZE, mail.getMessageSize());
props.put(JAMES_MAIL_NAME, mail.getName());
StringBuilder recipientsBuilder = new StringBuilder();
Iterator<MailAddress> recipients = mail.getRecipients().iterator();
while (recipients.hasNext()) {
String recipient = recipients.next().toString();
recipientsBuilder.append(recipient.trim());
if (recipients.hasNext()) {
recipientsBuilder.append(JAMES_MAIL_SEPARATOR);
}
}
props.put(JAMES_MAIL_RECIPIENTS, recipientsBuilder.toString());
props.put(JAMES_MAIL_REMOTEADDR, mail.getRemoteAddr());
props.put(JAMES_MAIL_REMOTEHOST, mail.getRemoteHost());
String sender;
MailAddress s = mail.getSender();
if (s == null) {
sender = "";
} else {
sender = mail.getSender().toString();
}
StringBuilder attrsBuilder = new StringBuilder();
Iterator<String> attrs = mail.getAttributeNames();
while (attrs.hasNext()) {
String attrName = attrs.next();
attrsBuilder.append(attrName);
Object value = convertAttributeValue(mail.getAttribute(attrName));
props.put(attrName, value);
if (attrs.hasNext()) {
attrsBuilder.append(JAMES_MAIL_SEPARATOR);
}
}
props.put(JAMES_MAIL_ATTRIBUTE_NAMES, attrsBuilder.toString());
props.put(JAMES_MAIL_SENDER, sender);
props.put(JAMES_MAIL_STATE, mail.getState());
return props;
}
示例4: browse
import org.apache.mailet.Mail; //导入方法依赖的package包/类
/**
* @see org.apache.james.queue.api.MailQueueManagementMBean#browse()
*/
@SuppressWarnings("unchecked")
public List<CompositeData> browse() throws Exception {
MailQueueIterator it = queue.browse();
List<CompositeData> data = new ArrayList<CompositeData>();
String[] names = new String[] { "name", "sender", "state", "recipients", "size", "lastUpdated", "remoteAddress", "remoteHost", "errorMessage", "attributes", "nextDelivery" };
String[] descs = new String[] { "Unique name", "Sender", "Current state", "Recipients", "Size in bytes", "Timestamp of last update", "IPAddress of the sender", "Hostname of the sender", "Errormessage if any", "Attributes stored", "Timestamp of when the next delivery attempt will be make" };
OpenType[] types = new OpenType[] { SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.LONG, SimpleType.LONG, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.STRING, SimpleType.LONG };
while (it.hasNext()) {
MailQueueItemView mView = it.next();
Mail m = mView.getMail();
long nextDelivery = mView.getNextDelivery();
Map<String, Object> map = new HashMap<String, Object>();
map.put(names[0], m.getName());
String sender = null;
MailAddress senderAddress = m.getSender();
if (senderAddress != null) {
sender = senderAddress.toString();
}
map.put(names[1], sender);
map.put(names[2], m.getState());
StringBuilder rcptsBuilder = new StringBuilder();
Collection<MailAddress> rcpts = m.getRecipients();
if (rcpts != null) {
Iterator<MailAddress> rcptsIt = rcpts.iterator();
while (rcptsIt.hasNext()) {
rcptsBuilder.append(rcptsIt.next().toString());
if (rcptsIt.hasNext()) {
rcptsBuilder.append(",");
}
}
}
map.put(names[3], rcptsBuilder.toString());
map.put(names[4], m.getMessageSize());
map.put(names[5], m.getLastUpdated().getTime());
map.put(names[6], m.getRemoteAddr());
map.put(names[7], m.getRemoteHost());
map.put(names[8], m.getErrorMessage());
Map<String, String> attrs = new HashMap<String, String>();
Iterator<String> attrNames = m.getAttributeNames();
while (attrNames.hasNext()) {
String attrName = attrNames.next();
String attrValueString = null;
Serializable attrValue = m.getAttribute(attrName);
if (attrValue != null) {
attrValueString = attrValue.toString();
}
attrs.put(attrName, attrValueString);
}
map.put(names[9], attrs.toString());
map.put(names[10], nextDelivery);
CompositeDataSupport c = new CompositeDataSupport(new CompositeType(Mail.class.getName(), "Queue Mail", names, descs, types), map);
data.add(c);
}
it.close();
return data;
}