jcs
/subtext
/amendments
/473
board: Strip out Renegade-style pipe colors from FTN messages
When deleting FTN posts, if there are no messages left in the map,
delete it otherwise bile will balk at a 0-length write.
jcs made amendment 473 about 1 year ago
--- board.c Sat Apr 8 17:41:21 2023
+++ board.c Mon Apr 10 16:30:58 2023
@@ -892,10 +892,10 @@ board_post_read(struct session *s, struct board *board
struct board_ftn_post fpost;
struct username_cache *sender;
struct session_menu_option *dopts = NULL;
- size_t size;
+ size_t size, plain_post_size, j;
short ret = POST_READ_RETURN_DONE;
char c;
- char *data, *subject;
+ char *data, *subject, *plain_post, *tplain_post;
short cc, bcret;
bool done = false, show_help = false;
@@ -936,7 +936,28 @@ board_post_read(struct session *s, struct board *board
"Re: " : ""), fpost.subject);
session_printf(s, "\r\n");
session_flush(s);
- session_paginate(s, fpost.body, fpost.body_size, 6);
+
+ plain_post_size = 0;
+ plain_post = xmalloc(fpost.body_size);
+ if (plain_post == NULL)
+ session_paginate(s, fpost.body, fpost.body_size, 6);
+ else {
+ /* strip out renegade-style pipe color codes ("abc|01def") */
+ for (j = 0; j < fpost.body_size; j++) {
+ if (fpost.body[j] == '|' &&
+ fpost.body[j + 1] >= '0' && fpost.body[j + 1] <= '9' &&
+ fpost.body[j + 2] >= '0' && fpost.body[j + 2] <= '9') {
+ j += 2;
+ continue;
+ }
+ plain_post[plain_post_size++] = fpost.body[j];
+ }
+ tplain_post = xrealloc(plain_post, plain_post_size);
+ if (tplain_post != NULL)
+ plain_post = tplain_post;
+ session_paginate(s, plain_post, plain_post_size, 6);
+ xfree(&plain_post);
+ }
} else {
size = bile_read_alloc(board->bile, BOARD_POST_RTYPE, id, &data);
if (size == 0)
@@ -1482,8 +1503,11 @@ board_delete_ftn_post(struct board *board, struct boar
}
}
- bile_write(board->bile, BOARD_SORTED_ID_MAP_RTYPE, 1, id_map,
- sizeof(struct board_id_time_map) * npost_ids);
+ if (npost_ids == 0)
+ board_delete_cached_index(board);
+ else
+ bile_write(board->bile, BOARD_SORTED_ID_MAP_RTYPE, 1, id_map,
+ sizeof(struct board_id_time_map) * npost_ids);
}
size_t