about summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--archive.c3
-rw-r--r--archive.h1
-rw-r--r--bubger.112
-rw-r--r--concat.c15
4 files changed, 25 insertions, 6 deletions
diff --git a/archive.c b/archive.c
index f55146f..3c5f12b 100644
--- a/archive.c
+++ b/archive.c
@@ -96,9 +96,10 @@ int main(int argc, char *argv[]) {
 
 	for (
 		int opt;
-		0 < (opt = getopt(argc, argv, "C:H:S:T:a:h:im:p:qs:tu:vw:y:"));
+		0 < (opt = getopt(argc, argv, "A:C:H:S:T:a:h:im:p:qs:tu:vw:y:"));
 	) {
 		switch (opt) {
+			break; case 'A': concatIndexEntries = strtoul(optarg, NULL, 10);
 			break; case 'C': {
 				int error = chdir(optarg);
 				if (error) err(EX_NOINPUT, "%s", optarg);
diff --git a/archive.h b/archive.h
index 5c7dfcf..1a94744 100644
--- a/archive.h
+++ b/archive.h
@@ -214,6 +214,7 @@ bool exportFetch(FILE *imap, enum Atom tag, struct List threads);
 bool exportData(FILE *imap, enum Atom tag, struct List items);
 
 extern const char *concatHead;
+extern size_t concatIndexEntries;
 void concatFetch(FILE *imap, enum Atom tag, struct List threads);
 void concatData(
 	struct List threads, struct Envelope *envelopes, struct List items
diff --git a/bubger.1 b/bubger.1
index fb349e7..6f0c4d7 100644
--- a/bubger.1
+++ b/bubger.1
@@ -1,4 +1,4 @@
-.Dd March  3, 2021
+.Dd June  9, 2021
 .Dt BUBGER 1
 .Os
 .
@@ -9,6 +9,7 @@
 .Sh SYNOPSIS
 .Nm
 .Op Fl iqtv
+.Op Fl A Ar entries
 .Op Fl C Ar path
 .Op Fl H Ar head
 .Op Fl S Ar search
@@ -40,6 +41,13 @@ is written to standard output.
 The arguments are as follows:
 .
 .Bl -tag -width Ds
+.It Fl A Ar entries
+Limit the number of entries
+in the index Atom feed.
+The default limit is 20.
+Thread Atom feeds
+always contain all entries.
+.
 .It Fl C Ar path
 Change directory to
 .Ar path
@@ -160,7 +168,7 @@ The IMAP password.
 .Sh FILES
 .Bl -tag -width Ds
 .It Pa index.atom
-Rendered Atom feed of all messages.
+Rendered Atom feed of recent messages.
 .It Pa index.html
 Rendered HTML index of all threads.
 .It Pa thread/*.atom , Pa thread/*.html , Pa thread/*.mbox
diff --git a/concat.c b/concat.c
index 64e543f..3e03f3b 100644
--- a/concat.c
+++ b/concat.c
@@ -230,13 +230,19 @@ void concatThreads(struct List threads, const struct Envelope *envelopes) {
 	}
 }
 
+static int numberCompare(const void *_a, const void *_b) {
+	const struct Data *a = _a;
+	const struct Data *b = _b;
+	return (b->number > a->number) - (b->number < a->number);
+}
+
 struct Sort {
 	size_t index;
 	time_t updated;
 	time_t created;
 };
 
-static int compar(const void *_a, const void *_b) {
+static int sortCompare(const void *_a, const void *_b) {
 	const struct Sort *a = _a;
 	const struct Sort *b = _b;
 	if (a->updated == b->updated) {
@@ -246,6 +252,8 @@ static int compar(const void *_a, const void *_b) {
 	}
 }
 
+size_t concatIndexEntries = 20;
+
 void concatIndex(struct List threads, const struct Envelope *envelopes) {
 	const char *path = "index.atom";
 	FILE *file = fopen(path, "w");
@@ -256,7 +264,8 @@ void concatIndex(struct List threads, const struct Envelope *envelopes) {
 
 	struct List flat = {0};
 	listFlatten(&flat, threads);
-	for (size_t i = flat.len - 1; i < flat.len; --i) {
+	qsort(flat.ptr, flat.len, sizeof(*flat.ptr), numberCompare);
+	for (size_t i = 0; i < flat.len && i < concatIndexEntries; ++i) {
 		uint32_t uid = dataCheck(flat.ptr[i], Number).number;
 		char *src = uidPath(uid, "atom");
 		error = concatFile(file, src);
@@ -283,7 +292,7 @@ void concatIndex(struct List threads, const struct Envelope *envelopes) {
 		order[i].created = envelopes[i].time;
 		order[i].updated = status.st_mtime;
 	}
-	qsort(order, threads.len, sizeof(*order), compar);
+	qsort(order, threads.len, sizeof(*order), sortCompare);
 
 	path = "index.html";
 	file = fopen(path, "w");