*/
protected Page aggregate(Message message, Site site) throws IOException,
MessagingException, IllegalArgumentException {
ResourceURI uri = new PageURIImpl(site, UUID.randomUUID().toString());
Page page = new PageImpl(uri);
Language language = site.getDefaultLanguage();
// Extract title and subject. Without these two, creating a page is not
// feasible, therefore both messages throw an IllegalArgumentException if
// the fields are not present.
String title = getSubject(message);
String author = getAuthor(message);
// Collect default settings
PageTemplate template = site.getDefaultTemplate();
if (template == null)
throw new IllegalStateException("Missing default template in site '" + site + "'");
String stage = template.getStage();
if (StringUtils.isBlank(stage))
throw new IllegalStateException("Missing stage definition in template '" + template.getIdentifier() + "'");
// Standard fields
page.setTitle(title, language);
page.setTemplate(template.getIdentifier());
page.setPublished(new UserImpl(site.getAdministrator()), message.getReceivedDate(), null);
// TODO: Translate e-mail "from" into site user and throw if no such
// user can be found
page.setCreated(site.getAdministrator(), message.getSentDate());
// Start looking at the message body
String contentType = message.getContentType();
if (StringUtils.isBlank(contentType))
throw new IllegalArgumentException("Message content type is unspecified");