summary refs log tree commit diff
path: root/archive.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--archive.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/archive.c b/archive.c
index 497b5a6..889f253 100644
--- a/archive.c
+++ b/archive.c
@@ -115,6 +115,15 @@ static struct AddressList parseAddressList(struct List list) {
 	return (struct AddressList) { list.len, addrs };
 }
 
+static char *parseID(char *id) {
+	size_t len = strlen(id);
+	if (id[0] != '<' || !len || id[len - 1] != '>') {
+		errx(EX_PROTOCOL, "invalid message ID");
+	}
+	id[len - 1] = '\0';
+	return &id[1];
+}
+
 static struct Envelope parseEnvelope(struct List list) {
 	enum {
 		Date, Subject, From, Sender, ReplyTo,
@@ -162,12 +171,12 @@ static struct Envelope parseEnvelope(struct List list) {
 	envelope.bcc = parseAddressList(list.ptr[Bcc].list);
 
 	if (list.ptr[InReplyTo].type == String) {
-		envelope.inReplyTo = list.ptr[InReplyTo].string;
+		envelope.inReplyTo = parseID(list.ptr[InReplyTo].string);
 	}
 	if (list.ptr[MessageID].type != String) {
 		errx(EX_PROTOCOL, "invalid envelope message-id field");
 	}
-	envelope.messageID = list.ptr[MessageID].string;
+	envelope.messageID = parseID(list.ptr[MessageID].string);
 
 	return envelope;
 }