use of com.zimbra.common.mime.MimeAddressHeader in project zm-mailbox by Zimbra.
the class MilterHandlerTest method testGetToCcAddressHeaderAscii.
@Test
public void testGetToCcAddressHeaderAscii() throws IOException {
String to = "To" + '\0' + "admin@example.com; admin2@example.com";
List<String> expctedEmails = new ArrayList<String>();
expctedEmails.add("admin@example.com");
expctedEmails.add("admin2@example.com");
MimeAddressHeader mh = MilterHandler.getToCcAddressHeader(to.getBytes("iso-8859-1"));
Assert.assertEquals(2, mh.getAddresses().size());
for (InternetAddress addrs : mh.getAddresses()) {
expctedEmails.contains(addrs.getAddress());
}
to = "To" + '\0';
mh = MilterHandler.getToCcAddressHeader(to.getBytes("iso-8859-1"));
Assert.assertNull(mh);
}
use of com.zimbra.common.mime.MimeAddressHeader in project zm-mailbox by Zimbra.
the class MilterHandler method getToCcAddressHeader.
static MimeAddressHeader getToCcAddressHeader(byte[] bytes) {
MimeAddressHeader mHeader = null;
try {
int i = 0;
String key = null;
if (bytes.length > 0) {
while (i < bytes.length && bytes[i] != 0x00) {
i++;
}
}
key = new String(Arrays.copyOfRange(bytes, 0, i));
if (!StringUtil.isNullOrEmpty(key) && (key.toLowerCase().equals(TO_HEADER) || key.toLowerCase().equals(CC_HEADER))) {
if (bytes.length > i + 1) {
byte[] values = Arrays.copyOfRange(bytes, i + 1, bytes.length);
mHeader = new MimeAddressHeader(key, values);
}
}
} catch (Exception e) {
ZimbraLog.milter.warn("Error parsing header.", e);
}
return mHeader;
}
use of com.zimbra.common.mime.MimeAddressHeader in project zm-mailbox by Zimbra.
the class MilterHandler method getAddrListsFromHeaders.
private void getAddrListsFromHeaders(MilterPacket command) {
MimeAddressHeader mHeader = getToCcAddressHeader(command.getData());
if (mHeader != null) {
for (InternetAddress address : mHeader.getAddresses()) {
if (address.getAddress() != null) {
visibleAddresses.add(address.getAddress().toLowerCase());
ZimbraLog.milter.debug("Visible value %s", address.getAddress());
}
}
}
}
use of com.zimbra.common.mime.MimeAddressHeader in project zm-mailbox by Zimbra.
the class MilterHandlerTest method testGetToCcAddressHeaderNonAscii.
@Test
public void testGetToCcAddressHeaderNonAscii() throws IOException {
String to = "To" + '\0' + "Ré你好 < toadmin@example.com>";
String cc = "CC" + '\0' + "𝔘𝔫𝔦𝔠𝔬𝔡你好 <ccadmin@example.com>";
String from = "from" + '\0' + "é̦世界 <admin@example.com>";
MimeAddressHeader mh = MilterHandler.getToCcAddressHeader(to.getBytes("utf-8"));
Assert.assertNotNull(mh);
Assert.assertEquals("toadmin@example.com", mh.getAddresses().get(0).getAddress());
mh = MilterHandler.getToCcAddressHeader(cc.getBytes("utf-8"));
Assert.assertNotNull(mh);
Assert.assertEquals(1, mh.getAddresses().size());
Assert.assertEquals("ccadmin@example.com", mh.getAddresses().get(0).getAddress());
mh = MilterHandler.getToCcAddressHeader(from.getBytes("utf-8"));
Assert.assertNull(mh);
}
use of com.zimbra.common.mime.MimeAddressHeader in project zm-mailbox by Zimbra.
the class MilterHandlerTest method testGetToCcAddressHeaderNonAscii1.
@Test
public void testGetToCcAddressHeaderNonAscii1() throws IOException {
List<String> expctedEmails = new ArrayList<String>();
expctedEmails.add("toadmin@example.com");
expctedEmails.add("test@example.com");
expctedEmails.add("test2@example.com");
String to = "To" + '\0' + "Ré你好 <toadmin@example.com>,test@example.com,<test2@example.com>";
MimeAddressHeader mh = MilterHandler.getToCcAddressHeader(to.getBytes("iso-8859-1"));
Assert.assertEquals(3, mh.getAddresses().size());
for (InternetAddress addrs : mh.getAddresses()) {
expctedEmails.contains(addrs.getAddress());
}
}
Aggregations