Drupal: klient nemusí posílat In-Reply-To hlavičku, ale jen References, kde je víc messageID – vezmeme to poslední.
authorFrantišek Kučera <franta-hg@frantovo.cz>
Tue, 25 Oct 2011 14:10:55 +0200
changeset 10903cc47e9daee
parent 108 fdc075324ef3
child 110 c81406884e16
Drupal: klient nemusí posílat In-Reply-To hlavičku, ale jen References, kde je víc messageID – vezmeme to poslední.
src/org/sonews/storage/DrupalMessage.java
     1.1 --- a/src/org/sonews/storage/DrupalMessage.java	Tue Oct 25 10:39:57 2011 +0200
     1.2 +++ b/src/org/sonews/storage/DrupalMessage.java	Tue Oct 25 14:10:55 2011 +0200
     1.3 @@ -30,10 +30,13 @@
     1.4  import java.sql.ResultSet;
     1.5  import java.sql.SQLException;
     1.6  import java.util.ArrayList;
     1.7 +import java.util.Arrays;
     1.8  import java.util.Date;
     1.9  import java.util.Enumeration;
    1.10  import java.util.logging.Level;
    1.11  import java.util.logging.Logger;
    1.12 +import java.util.regex.Matcher;
    1.13 +import java.util.regex.Pattern;
    1.14  import javax.mail.Header;
    1.15  import javax.mail.MessagingException;
    1.16  import javax.mail.Multipart;
    1.17 @@ -161,14 +164,26 @@
    1.18  		super(Session.getDefaultInstance(System.getProperties()), serializeArticle(article));
    1.19  		initFactories();
    1.20  
    1.21 -		String[] parentHeaders = getHeader("In-Reply-To");
    1.22 -		if (parentHeaders != null && parentHeaders.length == 1) {
    1.23 -			String parentMessageID = parentHeaders[0];
    1.24 -			parentID = parseArticleID(parentMessageID);
    1.25 -			groupID = parseGroupID(parentMessageID);
    1.26 +		String[] replyToHeaders = getHeader("In-Reply-To");
    1.27 +		String[] referencesHeaders = getHeader("References");
    1.28 +		String parentMessageID;
    1.29 +		if (replyToHeaders != null && replyToHeaders.length == 1) {
    1.30 +			parentMessageID = replyToHeaders[0];
    1.31 +		} else if (referencesHeaders != null && referencesHeaders.length == 1) {
    1.32 +			Pattern p = Pattern.compile("(\\s*<.*>)*\\s*(<.*>)");
    1.33 +			Matcher m = p.matcher(referencesHeaders[0]);
    1.34 +
    1.35 +			if (m.matches()) {
    1.36 +				parentMessageID = m.group(2);
    1.37 +			} else {
    1.38 +				throw new MessagingException("Message posted by user had invalid References header: " + referencesHeaders[0]);
    1.39 +			}
    1.40  		} else {
    1.41 -			throw new MessagingException("Message posted by user must have exactly one In-Reply-To header.");
    1.42 +			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));
    1.43  		}
    1.44 +
    1.45 +		parentID = parseArticleID(parentMessageID);
    1.46 +		groupID = parseGroupID(parentMessageID);
    1.47  	}
    1.48  
    1.49  	private static InputStream serializeArticle(Article a) {
    1.50 @@ -503,7 +518,7 @@
    1.51  			throw new StorageBackendException(e);
    1.52  		}
    1.53  	}
    1.54 -	
    1.55 +
    1.56  	public String getBodyPlainText() throws StorageBackendException {
    1.57  		/**
    1.58  		 * TODO: netransformovat XHTML 2x