use of javax.mail.internet.InternetAddress in project zm-mailbox by Zimbra.
the class MailSenderTest method sendExternalMessage.
//@Test
public void sendExternalMessage() throws Exception {
Provisioning prov = Provisioning.getInstance();
Server server = prov.getLocalServer();
server.setSmtpHostname(new String[] { "bogusname.test" });
server.setSmtpPort(25);
server.setSmtpTimeout(60);
server.setSmtpSendPartial(true);
server.setShareNotificationMtaHostname("mta02.zimbra.com");
server.setShareNotificationMtaPort(25);
server.setShareNotificationMtaAuthRequired(true);
server.setShareNotificationMtaConnectionType(ShareNotificationMtaConnectionType.STARTTLS);
server.setShareNotificationMtaAuthAccount("test-jylee");
server.setShareNotificationMtaAuthPassword("test123");
MimeMessage mm = new MimeMessage(JMSession.getSmtpSession());
InternetAddress address = new JavaMailInternetAddress("test-jylee@zimbra.com");
mm.setFrom(address);
address = new JavaMailInternetAddress("test-jylee@zimbra.com");
mm.setRecipient(javax.mail.Message.RecipientType.TO, address);
mm.setSubject("test mail");
mm.setText("hello world");
mm.saveChanges();
ZimbraLog.smtp.setLevel(Level.trace);
MailSender.relayMessage(mm);
}
use of javax.mail.internet.InternetAddress in project zm-mailbox by Zimbra.
the class MailSenderTest method getSenderHeadersDelegatedAuth.
@Test
public void getSenderHeadersDelegatedAuth() throws Exception {
Provisioning prov = Provisioning.getInstance();
Account account = prov.getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put(Provisioning.A_zimbraId, UUID.randomUUID().toString());
Account account2 = prov.createAccount("test2@zimbra.com", "secret", attrs);
MailSender mailSender = new MailSender();
Pair<InternetAddress, InternetAddress> pair;
String target = "test@zimbra.com";
String mail = "test2@zimbra.com";
String alias = "test-alias@zimbra.com";
String invalid1 = "foo@zimbra.com";
String invalid2 = "bar@zimbra.com";
Right right = RightManager.getInstance().getUserRight("sendOnBehalfOf");
ZimbraACE ace = new ZimbraACE(account2.getId(), GranteeType.GT_USER, right, null, null);
Set<ZimbraACE> aces = new HashSet<ZimbraACE>();
aces.add(ace);
ACLUtil.grantRight(Provisioning.getInstance(), account, aces);
pair = mailSender.getSenderHeaders(null, null, account, account2, false);
Assert.assertEquals(mail, pair.getFirst().toString());
Assert.assertNull(pair.getSecond());
pair = mailSender.getSenderHeaders(new InternetAddress(mail), null, account, account2, false);
Assert.assertEquals(mail, pair.getFirst().toString());
Assert.assertNull(pair.getSecond());
pair = mailSender.getSenderHeaders(null, new InternetAddress(mail), account, account2, false);
Assert.assertEquals(mail, pair.getFirst().toString());
Assert.assertNull(pair.getSecond());
pair = mailSender.getSenderHeaders(new InternetAddress(mail), new InternetAddress(mail), account, account2, false);
Assert.assertEquals(mail, pair.getFirst().toString());
Assert.assertNull(pair.getSecond());
pair = mailSender.getSenderHeaders(new InternetAddress(alias), null, account, account2, false);
Assert.assertEquals(alias, pair.getFirst().toString());
Assert.assertEquals(mail, pair.getSecond().toString());
pair = mailSender.getSenderHeaders(null, new InternetAddress(alias), account, account2, false);
Assert.assertEquals(alias, pair.getFirst().toString());
Assert.assertEquals(mail, pair.getSecond().toString());
pair = mailSender.getSenderHeaders(new InternetAddress(alias), new InternetAddress(alias), account, account2, false);
Assert.assertEquals(alias, pair.getFirst().toString());
Assert.assertEquals(mail, pair.getSecond().toString());
pair = mailSender.getSenderHeaders(new InternetAddress(invalid1), null, account, account2, false);
Assert.assertEquals(mail, pair.getFirst().toString());
Assert.assertNull(pair.getSecond());
pair = mailSender.getSenderHeaders(null, new InternetAddress(invalid1), account, account2, false);
Assert.assertEquals(mail, pair.getFirst().toString());
Assert.assertNull(pair.getSecond());
pair = mailSender.getSenderHeaders(new InternetAddress(invalid1), new InternetAddress(invalid2), account, account2, false);
Assert.assertEquals(mail, pair.getFirst().toString());
Assert.assertNull(pair.getSecond());
pair = mailSender.getSenderHeaders(new InternetAddress(alias), new InternetAddress(mail), account, account2, false);
Assert.assertEquals(alias, pair.getFirst().toString());
Assert.assertEquals(mail, pair.getSecond().toString());
pair = mailSender.getSenderHeaders(new InternetAddress(mail), new InternetAddress(alias), account, account2, false);
Assert.assertEquals(mail, pair.getFirst().toString());
Assert.assertNull(pair.getSecond());
pair = mailSender.getSenderHeaders(new InternetAddress(alias), new InternetAddress(invalid1), account, account2, false);
Assert.assertEquals(alias, pair.getFirst().toString());
Assert.assertEquals(mail, pair.getSecond().toString());
pair = mailSender.getSenderHeaders(new InternetAddress(invalid1), new InternetAddress(alias), account, account2, false);
Assert.assertEquals(mail, pair.getFirst().toString());
Assert.assertNull(pair.getSecond());
pair = mailSender.getSenderHeaders(new InternetAddress(mail), new InternetAddress(invalid1), account, account2, false);
Assert.assertEquals(mail, pair.getFirst().toString());
Assert.assertNull(pair.getSecond());
pair = mailSender.getSenderHeaders(new InternetAddress(invalid1), new InternetAddress(mail), account, account2, false);
Assert.assertEquals(mail, pair.getFirst().toString());
Assert.assertNull(pair.getSecond());
}
use of javax.mail.internet.InternetAddress in project zm-mailbox by Zimbra.
the class MailSenderTest method getSenderHeadersSimpleAuth.
@Test
public void getSenderHeadersSimpleAuth() throws Exception {
Provisioning prov = Provisioning.getInstance();
Account account = prov.getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
MailSender mailSender = new MailSender();
Pair<InternetAddress, InternetAddress> pair;
String mail = "test@zimbra.com";
String alias = "test-alias@zimbra.com";
String invalid1 = "foo@zimbra.com";
String invalid2 = "bar@zimbra.com";
pair = mailSender.getSenderHeaders(null, null, account, account, false);
Assert.assertEquals(mail, pair.getFirst().toString());
Assert.assertNull(pair.getSecond());
pair = mailSender.getSenderHeaders(new InternetAddress(mail), null, account, account, false);
Assert.assertEquals(mail, pair.getFirst().toString());
Assert.assertNull(pair.getSecond());
pair = mailSender.getSenderHeaders(null, new InternetAddress(mail), account, account, false);
Assert.assertEquals(mail, pair.getFirst().toString());
Assert.assertNull(pair.getSecond());
pair = mailSender.getSenderHeaders(new InternetAddress(mail), new InternetAddress(mail), account, account, false);
Assert.assertEquals(mail, pair.getFirst().toString());
Assert.assertNull(pair.getSecond());
pair = mailSender.getSenderHeaders(new InternetAddress(alias), null, account, account, false);
Assert.assertEquals(alias, pair.getFirst().toString());
Assert.assertNull(pair.getSecond());
pair = mailSender.getSenderHeaders(null, new InternetAddress(alias), account, account, false);
Assert.assertEquals(alias, pair.getFirst().toString());
Assert.assertNull(pair.getSecond());
pair = mailSender.getSenderHeaders(new InternetAddress(alias), new InternetAddress(alias), account, account, false);
Assert.assertEquals(alias, pair.getFirst().toString());
Assert.assertNull(pair.getSecond());
pair = mailSender.getSenderHeaders(new InternetAddress(invalid1), null, account, account, false);
Assert.assertEquals(mail, pair.getFirst().toString());
Assert.assertNull(pair.getSecond());
pair = mailSender.getSenderHeaders(null, new InternetAddress(invalid1), account, account, false);
Assert.assertEquals(mail, pair.getFirst().toString());
Assert.assertNull(pair.getSecond());
pair = mailSender.getSenderHeaders(new InternetAddress(invalid1), new InternetAddress(invalid2), account, account, false);
Assert.assertEquals(mail, pair.getFirst().toString());
Assert.assertNull(pair.getSecond());
pair = mailSender.getSenderHeaders(new InternetAddress(alias), new InternetAddress(mail), account, account, false);
Assert.assertEquals(alias, pair.getFirst().toString());
Assert.assertEquals(mail, pair.getSecond().toString());
pair = mailSender.getSenderHeaders(new InternetAddress(mail), new InternetAddress(alias), account, account, false);
Assert.assertEquals(mail, pair.getFirst().toString());
Assert.assertNull(pair.getSecond());
pair = mailSender.getSenderHeaders(new InternetAddress(alias), new InternetAddress(invalid1), account, account, false);
Assert.assertEquals(alias, pair.getFirst().toString());
Assert.assertEquals(mail, pair.getSecond().toString());
pair = mailSender.getSenderHeaders(new InternetAddress(invalid1), new InternetAddress(alias), account, account, false);
Assert.assertEquals(mail, pair.getFirst().toString());
Assert.assertNull(pair.getSecond());
pair = mailSender.getSenderHeaders(new InternetAddress(mail), new InternetAddress(invalid1), account, account, false);
Assert.assertEquals(mail, pair.getFirst().toString());
Assert.assertNull(pair.getSecond());
pair = mailSender.getSenderHeaders(new InternetAddress(invalid1), new InternetAddress(mail), account, account, false);
Assert.assertEquals(mail, pair.getFirst().toString());
Assert.assertNull(pair.getSecond());
}
use of javax.mail.internet.InternetAddress in project zm-mailbox by Zimbra.
the class AttributeInfo method validEmailAddress.
public static void validEmailAddress(String addr, boolean personal) throws ServiceException {
if (addr.indexOf('@') == -1)
throw AccountServiceException.INVALID_ATTR_VALUE("address '" + addr + "' does not include domain", null);
try {
InternetAddress ia = new JavaMailInternetAddress(addr, true);
// is this even needed?
ia.validate();
if (!personal && ia.getPersonal() != null && !ia.getPersonal().equals(""))
throw AccountServiceException.INVALID_ATTR_VALUE("invalid email address: " + addr, null);
} catch (AddressException e) {
throw AccountServiceException.INVALID_ATTR_VALUE("invalid email address: " + addr, e);
}
}
use of javax.mail.internet.InternetAddress in project zm-mailbox by Zimbra.
the class Provisioning method getDefaultIdentity.
public Identity getDefaultIdentity(Account account) throws ServiceException {
Map<String, Object> attrs = new HashMap<String, Object>();
Set<String> identityAttrs = AttributeManager.getInstance().getAttrsInClass(AttributeClass.identity);
for (String name : identityAttrs) {
String value = account.getAttr(name, null);
if (value != null)
attrs.put(name, value);
}
if (attrs.get(A_zimbraPrefIdentityName) == null)
attrs.put(A_zimbraPrefIdentityName, ProvisioningConstants.DEFAULT_IDENTITY_NAME);
String fromAddress = (String) attrs.get(A_zimbraPrefFromAddress);
String fromDisplay = (String) attrs.get(A_zimbraPrefFromDisplay);
if (fromAddress == null || fromDisplay == null) {
InternetAddress ia = AccountUtil.getFriendlyEmailAddress(account);
if (fromAddress == null)
attrs.put(A_zimbraPrefFromAddress, ia.getAddress());
if (fromDisplay == null)
attrs.put(A_zimbraPrefFromDisplay, ia.getPersonal());
}
attrs.put(A_zimbraPrefIdentityId, account.getId());
/*
* In 4.0 we had a boolean setting zimbraPrefForwardReplyInOriginalFormat, In 4.5,
* that has been obsoleted in favor of zimbraPrefForwardReplyFormat which is an
* enum whose values are text/html/same. The default identity needs to correctly
* initialize the new value, and it should probably take into account the value of
* zimbraPrefComposeFormat.
*/
if (attrs.get(A_zimbraPrefForwardReplyFormat) == null) {
boolean forwardReplyInOriginalFormat = account.getBooleanAttr(Provisioning.A_zimbraPrefForwardReplyInOriginalFormat, false);
if (forwardReplyInOriginalFormat) {
attrs.put(A_zimbraPrefForwardReplyFormat, MAIL_FORWARDREPLY_FORMAT_SAME);
} else {
String composeFormat = account.getAttr(Provisioning.A_zimbraPrefComposeFormat, null);
if (composeFormat == null)
attrs.put(A_zimbraPrefForwardReplyFormat, MAIL_FORMAT_TEXT);
else
attrs.put(A_zimbraPrefForwardReplyFormat, composeFormat);
}
}
return new Identity(account, ProvisioningConstants.DEFAULT_IDENTITY_NAME, account.getId(), attrs, this);
}
Aggregations