aboutsummaryrefslogtreecommitdiff
path: root/format.c
diff options
context:
space:
mode:
authorshtrophic <christoph@liebender.dev>2024-12-23 13:42:45 +0100
committershtrophic <christoph@liebender.dev>2024-12-23 13:42:45 +0100
commita7ca4007f2a55a8becab1e4595d2696dd6e7bfd1 (patch)
tree3128196bd7eb298be5a37edac5922009ec5fcac1 /format.c
parentaf98f4ed4d0f4f9bebc392eca9dae1eaaa7e77c1 (diff)
parent89a8c2e0cc4fcd1f9450dfeb13bf5d83730c52ae (diff)
Merge tag '2.67'
Version 2.67 RELEASED.
Diffstat (limited to 'format.c')
-rw-r--r--format.c48
1 files changed, 36 insertions, 12 deletions
diff --git a/format.c b/format.c
index d0b535d..12783ae 100644
--- a/format.c
+++ b/format.c
@@ -163,14 +163,26 @@ static xs_str *format_line(const char *line, xs_list **attach)
const char *mime = xs_mime_by_ext(img_url);
if (attach != NULL && xs_startswith(mime, "image/")) {
- xs *d = xs_dict_new();
+ const xs_dict *ad;
+ int add = 1;
- d = xs_dict_append(d, "mediaType", mime);
- d = xs_dict_append(d, "url", img_url);
- d = xs_dict_append(d, "name", alt_text);
- d = xs_dict_append(d, "type", "Image");
+ xs_list_foreach(*attach, ad) {
+ if (strcmp(xs_dict_get_def(ad, "url", ""), img_url) == 0) {
+ add = 0;
+ break;
+ }
+ }
- *attach = xs_list_append(*attach, d);
+ if (add) {
+ xs *d = xs_dict_new();
+
+ d = xs_dict_append(d, "mediaType", mime);
+ d = xs_dict_append(d, "url", img_url);
+ d = xs_dict_append(d, "name", alt_text);
+ d = xs_dict_append(d, "type", "Image");
+
+ *attach = xs_list_append(*attach, d);
+ }
}
else {
xs *link = xs_fmt("<a href=\"%s\">%s</a>", img_url, alt_text);
@@ -191,14 +203,26 @@ static xs_str *format_line(const char *line, xs_list **attach)
if (attach != NULL && xs_startswith(mime, "image/")) {
/* if it's a link to an image, insert it as an attachment */
- xs *d = xs_dict_new();
+ const xs_dict *ad;
+ int add = 1;
+
+ xs_list_foreach(*attach, ad) {
+ if (strcmp(xs_dict_get_def(ad, "url", ""), v2) == 0) {
+ add = 0;
+ break;
+ }
+ }
- d = xs_dict_append(d, "mediaType", mime);
- d = xs_dict_append(d, "url", v2);
- d = xs_dict_append(d, "name", "");
- d = xs_dict_append(d, "type", "Image");
+ if (add) {
+ xs *d = xs_dict_new();
- *attach = xs_list_append(*attach, d);
+ d = xs_dict_append(d, "mediaType", mime);
+ d = xs_dict_append(d, "url", v2);
+ d = xs_dict_append(d, "name", "");
+ d = xs_dict_append(d, "type", "Image");
+
+ *attach = xs_list_append(*attach, d);
+ }
}
else {
xs *s1 = xs_fmt("<a href=\"%s\" target=\"_blank\">%s</a>", v2, u);