mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
ALF-6772 - IMAP: User metadata viewed in Outlook
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@28848 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -25,7 +25,9 @@ import java.util.Map;
|
||||
import javax.mail.Address;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.Multipart;
|
||||
import javax.mail.internet.AddressException;
|
||||
import javax.mail.internet.ContentType;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
import javax.mail.internet.MimeBodyPart;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import javax.mail.internet.MimeMultipart;
|
||||
@@ -33,12 +35,20 @@ import javax.mail.internet.MimeUtility;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.imap.ImapService.EmailBodyFormat;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.service.ServiceRegistry;
|
||||
import org.alfresco.service.cmr.model.FileInfo;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
public class ContentModelMessage extends AbstractMimeMessage
|
||||
{
|
||||
private Log logger = LogFactory.getLog(ContentModelMessage.class);
|
||||
|
||||
protected static final String DEFAULT_EMAIL_FROM = "alfresco@alfresco.org";
|
||||
protected static final String DEFAULT_EMAIL_TO = "alfresco@alfresco.org";
|
||||
|
||||
public ContentModelMessage(FileInfo fileInfo, ServiceRegistry serviceRegistry, boolean generateBody) throws MessagingException
|
||||
{
|
||||
@@ -143,6 +153,163 @@ public class ContentModelMessage extends AbstractMimeMessage
|
||||
return s.toString();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the "to" address.
|
||||
*
|
||||
* Step 1: Use PROP_ADDRESSEE
|
||||
*
|
||||
* Last Step: Use the default address
|
||||
*
|
||||
* @return Generated TO address {@code <user>@<current.domain>}
|
||||
* @throws AddressException
|
||||
*/
|
||||
private InternetAddress[] buildRecipientToAddress() throws AddressException
|
||||
{
|
||||
InternetAddress[] result = null;
|
||||
|
||||
|
||||
Map<QName, Serializable> properties = messageFileInfo.getProperties();
|
||||
|
||||
/**
|
||||
* Step 1 : Get the ADDRESSEE if it exists
|
||||
*/
|
||||
if(properties.containsKey(ContentModel.PROP_ADDRESSEE))
|
||||
{
|
||||
String addressee = (String)properties.get(ContentModel.PROP_ADDRESSEE);
|
||||
try
|
||||
{
|
||||
result = InternetAddress.parse(addressee);
|
||||
return result;
|
||||
}
|
||||
catch (AddressException e)
|
||||
{
|
||||
// try next step
|
||||
}
|
||||
}
|
||||
|
||||
// final String escapedUserName = AuthenticationUtil.getFullyAuthenticatedUser().replaceAll("[/,\\,@]", ".");
|
||||
// final String userDomain = DEFAULT_EMAIL_TO.split("@")[1];
|
||||
// String userName = escapedUserName + "@" + userDomain;
|
||||
// try
|
||||
// {
|
||||
// result = InternetAddress.parse(userName);
|
||||
// return result;
|
||||
// }
|
||||
// catch (AddressException e)
|
||||
// {
|
||||
// }
|
||||
|
||||
/**
|
||||
* Last Step : Get the Default address
|
||||
*/
|
||||
String defaultToAddress = imapService.getDefaultToAddress();
|
||||
|
||||
try
|
||||
{
|
||||
result = InternetAddress.parse(defaultToAddress);
|
||||
return result;
|
||||
}
|
||||
catch (AddressException e)
|
||||
{
|
||||
logger.warn(String.format("Wrong email address '%s'.", defaultToAddress), e);
|
||||
}
|
||||
result = InternetAddress.parse(DEFAULT_EMAIL_TO);
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the InternetAddress for the sender (from)
|
||||
*
|
||||
* Step 1: use PROP_ORIGINATOR
|
||||
*
|
||||
* Last Step : Use the default address.
|
||||
*
|
||||
* Content Author name if provided. If name not specified, it takes Content Creator name.
|
||||
* If content creator does not exists, the default from address will be returned.
|
||||
*
|
||||
* @param contentAuthor The content author full name.
|
||||
* @return Generated InternetAddress[] array.
|
||||
* @throws AddressException
|
||||
*/
|
||||
private InternetAddress[] buildSenderFromAddress() throws AddressException
|
||||
{
|
||||
// Generate FROM address (Content author)
|
||||
InternetAddress[] result = null;
|
||||
Map<QName, Serializable> properties = messageFileInfo.getProperties();
|
||||
String defaultFromAddress = imapService.getDefaultFromAddress();
|
||||
|
||||
/**
|
||||
* Step 1 : Get the ORIGINATOR if it exists
|
||||
*/
|
||||
if(properties.containsKey(ContentModel.PROP_ORIGINATOR))
|
||||
{
|
||||
String addressee = (String)properties.get(ContentModel.PROP_ORIGINATOR);
|
||||
try
|
||||
{
|
||||
result = InternetAddress.parse(addressee);
|
||||
return result;
|
||||
}
|
||||
catch (AddressException e)
|
||||
{
|
||||
// try next step
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Go for the author property
|
||||
*/
|
||||
if(properties.containsKey(ContentModel.PROP_AUTHOR))
|
||||
{
|
||||
String author = (String) properties.get(ContentModel.PROP_AUTHOR);
|
||||
try
|
||||
{
|
||||
|
||||
StringBuilder contentAuthor = new StringBuilder();
|
||||
contentAuthor.append("\"").append(author).append("\" <").append(defaultFromAddress).append(">");
|
||||
result = InternetAddress.parse(contentAuthor.toString());
|
||||
return result;
|
||||
|
||||
}
|
||||
catch (AddressException e)
|
||||
{
|
||||
// try next step
|
||||
}
|
||||
}
|
||||
|
||||
if(properties.containsKey(ContentModel.PROP_CREATOR))
|
||||
{
|
||||
String author = (String) properties.get(ContentModel.PROP_CREATOR);
|
||||
try
|
||||
{
|
||||
|
||||
StringBuilder contentAuthor = new StringBuilder();
|
||||
contentAuthor.append("\"").append(author).append("\" <").append(defaultFromAddress).append(">");
|
||||
result = InternetAddress.parse(contentAuthor.toString());
|
||||
return result;
|
||||
|
||||
}
|
||||
catch (AddressException e)
|
||||
{
|
||||
// try next step
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Last Step : Get the Default address
|
||||
*/
|
||||
try
|
||||
{
|
||||
result = InternetAddress.parse(defaultFromAddress);
|
||||
return result;
|
||||
}
|
||||
catch (AddressException e)
|
||||
{
|
||||
logger.warn(String.format("Wrong email address '%s'.", defaultFromAddress), e);
|
||||
}
|
||||
result = InternetAddress.parse(DEFAULT_EMAIL_FROM);
|
||||
return result;
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user