diff -r fdc075324ef3 -r 03cc47e9daee src/org/sonews/storage/DrupalMessage.java --- a/src/org/sonews/storage/DrupalMessage.java Tue Oct 25 10:39:57 2011 +0200 +++ b/src/org/sonews/storage/DrupalMessage.java Tue Oct 25 14:10:55 2011 +0200 @@ -30,10 +30,13 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Date; import java.util.Enumeration; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.mail.Header; import javax.mail.MessagingException; import javax.mail.Multipart; @@ -161,14 +164,26 @@ super(Session.getDefaultInstance(System.getProperties()), serializeArticle(article)); initFactories(); - String[] parentHeaders = getHeader("In-Reply-To"); - if (parentHeaders != null && parentHeaders.length == 1) { - String parentMessageID = parentHeaders[0]; - parentID = parseArticleID(parentMessageID); - groupID = parseGroupID(parentMessageID); + String[] replyToHeaders = getHeader("In-Reply-To"); + String[] referencesHeaders = getHeader("References"); + String parentMessageID; + if (replyToHeaders != null && replyToHeaders.length == 1) { + parentMessageID = replyToHeaders[0]; + } else if (referencesHeaders != null && referencesHeaders.length == 1) { + Pattern p = Pattern.compile("(\\s*<.*>)*\\s*(<.*>)"); + Matcher m = p.matcher(referencesHeaders[0]); + + if (m.matches()) { + parentMessageID = m.group(2); + } else { + throw new MessagingException("Message posted by user had invalid References header: " + referencesHeaders[0]); + } } else { - throw new MessagingException("Message posted by user must have exactly one In-Reply-To header."); + throw new MessagingException("Message posted by user must have exactly one In-Reply-To header. Reply-To headers: " + Arrays.toString(replyToHeaders) + " Referemces headers: " + Arrays.toString(referencesHeaders)); } + + parentID = parseArticleID(parentMessageID); + groupID = parseGroupID(parentMessageID); } private static InputStream serializeArticle(Article a) { @@ -503,7 +518,7 @@ throw new StorageBackendException(e); } } - + public String getBodyPlainText() throws StorageBackendException { /** * TODO: netransformovat XHTML 2x