Skip to content

Commit

Permalink
ZCS-16489 Created LDAP attribute zimbraFeatureExternalEmailWarningEna…
Browse files Browse the repository at this point in the history
…bled and modified condition to check for feature enabled

Unit tests added for EEW
Refactored code to store the flag and accounts to avoid multiple LDAP calls
  • Loading branch information
viditZim committed Feb 11, 2025
1 parent 71f313a commit f2680f2
Show file tree
Hide file tree
Showing 8 changed files with 368 additions and 9 deletions.
16 changes: 16 additions & 0 deletions common/src/java/com/zimbra/common/account/ZAttrProvisioning.java
Original file line number Diff line number Diff line change
Expand Up @@ -6503,6 +6503,14 @@ public static TwoFactorAuthSecretEncoding fromString(String s) throws ServiceExc
@ZAttr(id=1370)
public static final String A_zimbraExternalAccountStatusCheckInterval = "zimbraExternalAccountStatusCheckInterval";

/**
* Sets the base warning text for External Email Warning (EEW)
*
* @since ZCS 10.1.7
*/
@ZAttr(id=4137)
public static final String A_zimbraExternalEmailWarningMessage = "zimbraExternalEmailWarningMessage";

/**
* the handler class for getting all groups an account belongs to in the
* external directory
Expand Down Expand Up @@ -7046,6 +7054,14 @@ public static TwoFactorAuthSecretEncoding fromString(String s) throws ServiceExc
@ZAttr(id=1185)
public static final String A_zimbraFeatureExportFolderEnabled = "zimbraFeatureExportFolderEnabled";

/**
* Feature to enable/disable External Email Warning (EEW)
*
* @since ZCS 10.1.7
*/
@ZAttr(id=4136)
public static final String A_zimbraFeatureExternalEmailWarningEnabled = "zimbraFeatureExternalEmailWarningEnabled";

/**
* whether external feedback feature is enabled
*
Expand Down
10 changes: 10 additions & 0 deletions store/conf/attrs/zimbra-attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10560,4 +10560,14 @@ TODO: delete them permanently from here
<defaultCOSValue>FALSE</defaultCOSValue>
<desc>Feature to enable delivery status notification</desc>
</attr>

<attr id="4136" name="zimbraFeatureExternalEmailWarningEnabled" type="boolean" cardinality="single" optionalIn="cos,account" flags="accountInherited,accountInfo" since="10.1.7">
<defaultCOSValue>FALSE</defaultCOSValue>
<desc>Feature to enable/disable External Email Warning (EEW)</desc>
</attr>

<attr id="4137" name="zimbraExternalEmailWarningMessage" type="string" cardinality="single" optionalIn="globalConfig" since="10.1.7">
<desc>Sets the base warning text for External Email Warning (EEW)</desc>
<globalConfigValue>This message originated outside of your organization.</globalConfigValue>
</attr>
</attrs>
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
*
* * ***** BEGIN LICENSE BLOCK *****
* * Zimbra Collaboration Suite, Network Edition.
* * Copyright (C) 2025 Synacor, Inc. All Rights Reserved.
* * ***** END LICENSE BLOCK *****
*
*/

package com.zimbra.cs.service.mail;

import com.zimbra.common.account.Key;
import com.zimbra.common.service.ServiceException;
import com.zimbra.cs.account.Account;
import com.zimbra.cs.account.Provisioning;
import com.zimbra.cs.lmtpserver.ExternalEmailWarning;
import com.zimbra.cs.lmtpserver.LmtpAddress;
import com.zimbra.cs.mailbox.MailboxTestUtil;
import junit.framework.TestCase;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.modules.junit4.PowerMockRunner;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RunWith(PowerMockRunner.class)
@PowerMockIgnore("javax.management.*")
public class ExternalEmailWarningTest extends TestCase{

Provisioning prov = Provisioning.getInstance();
List<LmtpAddress> recipients = new ArrayList<>();
ExternalEmailWarning externalEmailWarning = ExternalEmailWarning.getInstance();
String rcptEmail1;
String rcptEmail2;

@BeforeClass
public static void init() throws Exception {
MailboxTestUtil.initServer();

}

protected void setUp() throws Exception {
String recipient1 = "<\"test1.\"@domain.com>";
String recipient2 = "<\"test2.\"@domain.com>";
recipients.add(new LmtpAddress(recipient1, null, null));
recipients.add(new LmtpAddress(recipient2, null, null));
Map<String, Object> attrs1 = new HashMap<String, Object>();
attrs1.put(Provisioning.A_zimbraFeatureExternalEmailWarningEnabled, "TRUE");
rcptEmail1 = recipients.get(0).getEmailAddress();
Map<String, Object> attrs2 = new HashMap<String, Object>();
attrs2.put(Provisioning.A_zimbraFeatureExternalEmailWarningEnabled, "FALSE");
rcptEmail2 = recipients.get(1).getEmailAddress();
prov.createAccount(rcptEmail1, "test123", attrs1);
prov.createAccount(rcptEmail2, "test123", attrs2);
}

public void testIsEnabled_AccountTrue() throws ServiceException {
Account account = Provisioning.getInstance().get(Key.AccountBy.name, rcptEmail1);
Assert.assertTrue(externalEmailWarning.isEnabled(account));
}

public void testIsEnabled_AccountFalse() throws ServiceException {
Account account = Provisioning.getInstance().get(Key.AccountBy.name, rcptEmail2);
Assert.assertFalse(externalEmailWarning.isEnabled(account));
}

public void testIsEnabled_RecipientsTrue() {
Assert.assertTrue(externalEmailWarning.isEnabled(recipients));
}

public void testIsEnabled_RecipientsFalse() throws ServiceException {
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put(Provisioning.A_zimbraFeatureExternalEmailWarningEnabled, "FALSE");
Account account = Provisioning.getInstance().get(Key.AccountBy.name, rcptEmail1);
account.deleteAccount();
prov.createAccount(rcptEmail1, "test123", attrs);
Assert.assertFalse(externalEmailWarning.isEnabled(recipients));
}
}
72 changes: 72 additions & 0 deletions store/src/java/com/zimbra/cs/account/ZAttrAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -16668,6 +16668,78 @@ public Map<String,Object> unsetFeatureExportFolderEnabled(Map<String,Object> att
return attrs;
}

/**
* Feature to enable/disable External Email Warning (EEW)
*
* @return zimbraFeatureExternalEmailWarningEnabled, or false if unset
*
* @since ZCS 10.1.7
*/
@ZAttr(id=4136)
public boolean isFeatureExternalEmailWarningEnabled() {
return getBooleanAttr(Provisioning.A_zimbraFeatureExternalEmailWarningEnabled, false, true);
}

/**
* Feature to enable/disable External Email Warning (EEW)
*
* @param zimbraFeatureExternalEmailWarningEnabled new value
* @throws com.zimbra.common.service.ServiceException if error during update
*
* @since ZCS 10.1.7
*/
@ZAttr(id=4136)
public void setFeatureExternalEmailWarningEnabled(boolean zimbraFeatureExternalEmailWarningEnabled) throws com.zimbra.common.service.ServiceException {
HashMap<String,Object> attrs = new HashMap<String,Object>();
attrs.put(Provisioning.A_zimbraFeatureExternalEmailWarningEnabled, zimbraFeatureExternalEmailWarningEnabled ? TRUE : FALSE);
getProvisioning().modifyAttrs(this, attrs);
}

/**
* Feature to enable/disable External Email Warning (EEW)
*
* @param zimbraFeatureExternalEmailWarningEnabled new value
* @param attrs existing map to populate, or null to create a new map
* @return populated map to pass into Provisioning.modifyAttrs
*
* @since ZCS 10.1.7
*/
@ZAttr(id=4136)
public Map<String,Object> setFeatureExternalEmailWarningEnabled(boolean zimbraFeatureExternalEmailWarningEnabled, Map<String,Object> attrs) {
if (attrs == null) attrs = new HashMap<String,Object>();
attrs.put(Provisioning.A_zimbraFeatureExternalEmailWarningEnabled, zimbraFeatureExternalEmailWarningEnabled ? TRUE : FALSE);
return attrs;
}

/**
* Feature to enable/disable External Email Warning (EEW)
*
* @throws com.zimbra.common.service.ServiceException if error during update
*
* @since ZCS 10.1.7
*/
@ZAttr(id=4136)
public void unsetFeatureExternalEmailWarningEnabled() throws com.zimbra.common.service.ServiceException {
HashMap<String,Object> attrs = new HashMap<String,Object>();
attrs.put(Provisioning.A_zimbraFeatureExternalEmailWarningEnabled, "");
getProvisioning().modifyAttrs(this, attrs);
}

/**
* Feature to enable/disable External Email Warning (EEW)
*
* @param attrs existing map to populate, or null to create a new map
* @return populated map to pass into Provisioning.modifyAttrs
*
* @since ZCS 10.1.7
*/
@ZAttr(id=4136)
public Map<String,Object> unsetFeatureExternalEmailWarningEnabled(Map<String,Object> attrs) {
if (attrs == null) attrs = new HashMap<String,Object>();
attrs.put(Provisioning.A_zimbraFeatureExternalEmailWarningEnabled, "");
return attrs;
}

/**
* whether external feedback feature is enabled
*
Expand Down
72 changes: 72 additions & 0 deletions store/src/java/com/zimbra/cs/account/ZAttrConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -18259,6 +18259,78 @@ public Map<String,Object> unsetExternalAccountStatusCheckInterval(Map<String,Obj
return attrs;
}

/**
* Sets the base warning text for External Email Warning (EEW)
*
* @return zimbraExternalEmailWarningMessage, or "This message originated outside of your organization." if unset
*
* @since ZCS 10.1.7
*/
@ZAttr(id=4137)
public String getExternalEmailWarningMessage() {
return getAttr(Provisioning.A_zimbraExternalEmailWarningMessage, "This message originated outside of your organization.", true);
}

/**
* Sets the base warning text for External Email Warning (EEW)
*
* @param zimbraExternalEmailWarningMessage new value
* @throws com.zimbra.common.service.ServiceException if error during update
*
* @since ZCS 10.1.7
*/
@ZAttr(id=4137)
public void setExternalEmailWarningMessage(String zimbraExternalEmailWarningMessage) throws com.zimbra.common.service.ServiceException {
HashMap<String,Object> attrs = new HashMap<String,Object>();
attrs.put(Provisioning.A_zimbraExternalEmailWarningMessage, zimbraExternalEmailWarningMessage);
getProvisioning().modifyAttrs(this, attrs);
}

/**
* Sets the base warning text for External Email Warning (EEW)
*
* @param zimbraExternalEmailWarningMessage new value
* @param attrs existing map to populate, or null to create a new map
* @return populated map to pass into Provisioning.modifyAttrs
*
* @since ZCS 10.1.7
*/
@ZAttr(id=4137)
public Map<String,Object> setExternalEmailWarningMessage(String zimbraExternalEmailWarningMessage, Map<String,Object> attrs) {
if (attrs == null) attrs = new HashMap<String,Object>();
attrs.put(Provisioning.A_zimbraExternalEmailWarningMessage, zimbraExternalEmailWarningMessage);
return attrs;
}

/**
* Sets the base warning text for External Email Warning (EEW)
*
* @throws com.zimbra.common.service.ServiceException if error during update
*
* @since ZCS 10.1.7
*/
@ZAttr(id=4137)
public void unsetExternalEmailWarningMessage() throws com.zimbra.common.service.ServiceException {
HashMap<String,Object> attrs = new HashMap<String,Object>();
attrs.put(Provisioning.A_zimbraExternalEmailWarningMessage, "");
getProvisioning().modifyAttrs(this, attrs);
}

/**
* Sets the base warning text for External Email Warning (EEW)
*
* @param attrs existing map to populate, or null to create a new map
* @return populated map to pass into Provisioning.modifyAttrs
*
* @since ZCS 10.1.7
*/
@ZAttr(id=4137)
public Map<String,Object> unsetExternalEmailWarningMessage(Map<String,Object> attrs) {
if (attrs == null) attrs = new HashMap<String,Object>();
attrs.put(Provisioning.A_zimbraExternalEmailWarningMessage, "");
return attrs;
}

/**
* Duration for which the URL sent in the share invitation email to an
* external user is valid. A value of 0 indicates that the URL never
Expand Down
72 changes: 72 additions & 0 deletions store/src/java/com/zimbra/cs/account/ZAttrCos.java
Original file line number Diff line number Diff line change
Expand Up @@ -11057,6 +11057,78 @@ public Map<String,Object> unsetFeatureExportFolderEnabled(Map<String,Object> att
return attrs;
}

/**
* Feature to enable/disable External Email Warning (EEW)
*
* @return zimbraFeatureExternalEmailWarningEnabled, or false if unset
*
* @since ZCS 10.1.7
*/
@ZAttr(id=4136)
public boolean isFeatureExternalEmailWarningEnabled() {
return getBooleanAttr(Provisioning.A_zimbraFeatureExternalEmailWarningEnabled, false, true);
}

/**
* Feature to enable/disable External Email Warning (EEW)
*
* @param zimbraFeatureExternalEmailWarningEnabled new value
* @throws com.zimbra.common.service.ServiceException if error during update
*
* @since ZCS 10.1.7
*/
@ZAttr(id=4136)
public void setFeatureExternalEmailWarningEnabled(boolean zimbraFeatureExternalEmailWarningEnabled) throws com.zimbra.common.service.ServiceException {
HashMap<String,Object> attrs = new HashMap<String,Object>();
attrs.put(Provisioning.A_zimbraFeatureExternalEmailWarningEnabled, zimbraFeatureExternalEmailWarningEnabled ? TRUE : FALSE);
getProvisioning().modifyAttrs(this, attrs);
}

/**
* Feature to enable/disable External Email Warning (EEW)
*
* @param zimbraFeatureExternalEmailWarningEnabled new value
* @param attrs existing map to populate, or null to create a new map
* @return populated map to pass into Provisioning.modifyAttrs
*
* @since ZCS 10.1.7
*/
@ZAttr(id=4136)
public Map<String,Object> setFeatureExternalEmailWarningEnabled(boolean zimbraFeatureExternalEmailWarningEnabled, Map<String,Object> attrs) {
if (attrs == null) attrs = new HashMap<String,Object>();
attrs.put(Provisioning.A_zimbraFeatureExternalEmailWarningEnabled, zimbraFeatureExternalEmailWarningEnabled ? TRUE : FALSE);
return attrs;
}

/**
* Feature to enable/disable External Email Warning (EEW)
*
* @throws com.zimbra.common.service.ServiceException if error during update
*
* @since ZCS 10.1.7
*/
@ZAttr(id=4136)
public void unsetFeatureExternalEmailWarningEnabled() throws com.zimbra.common.service.ServiceException {
HashMap<String,Object> attrs = new HashMap<String,Object>();
attrs.put(Provisioning.A_zimbraFeatureExternalEmailWarningEnabled, "");
getProvisioning().modifyAttrs(this, attrs);
}

/**
* Feature to enable/disable External Email Warning (EEW)
*
* @param attrs existing map to populate, or null to create a new map
* @return populated map to pass into Provisioning.modifyAttrs
*
* @since ZCS 10.1.7
*/
@ZAttr(id=4136)
public Map<String,Object> unsetFeatureExternalEmailWarningEnabled(Map<String,Object> attrs) {
if (attrs == null) attrs = new HashMap<String,Object>();
attrs.put(Provisioning.A_zimbraFeatureExternalEmailWarningEnabled, "");
return attrs;
}

/**
* whether external feedback feature is enabled
*
Expand Down
Loading

0 comments on commit f2680f2

Please sign in to comment.