|
63 | 63 | #define HC_FEXT "hcache" /* extension for hcache as POP lacks paths */ |
64 | 64 | #endif |
65 | 65 |
|
| 66 | +/** |
| 67 | + * cache_id - Make a message-cache-compatible id |
| 68 | + * @param id POP message id |
| 69 | + * @retval ptr Sanitised string |
| 70 | + * |
| 71 | + * The POP message id may contain '/' and other awkward characters. |
| 72 | + * |
| 73 | + * @note This function returns a pointer to a static buffer. |
| 74 | + */ |
| 75 | +static const char *cache_id(const char *id) |
| 76 | +{ |
| 77 | + static char clean[SHORT_STRING]; |
| 78 | + mutt_str_strfcpy(clean, id, sizeof(clean)); |
| 79 | + mutt_file_sanitize_filename(clean, true); |
| 80 | + return clean; |
| 81 | +} |
| 82 | + |
66 | 83 | /** |
67 | 84 | * fetch_message - write line to file |
68 | 85 | * @param line String to write |
@@ -242,7 +259,7 @@ static int msg_cache_check(const char *id, struct BodyCache *bcache, void *data) |
242 | 259 | /* message not found in context -> remove it from cache |
243 | 260 | * return the result of bcache, so we stop upon its first error |
244 | 261 | */ |
245 | | - return mutt_bcache_del(bcache, id); |
| 262 | + return mutt_bcache_del(bcache, cache_id(id)); |
246 | 263 | } |
247 | 264 |
|
248 | 265 | #ifdef USE_HCACHE |
@@ -407,7 +424,7 @@ static int pop_fetch_headers(struct Context *ctx) |
407 | 424 | * - if we don't have a body: new |
408 | 425 | */ |
409 | 426 | const bool bcached = |
410 | | - (mutt_bcache_exists(pop_data->bcache, ctx->hdrs[i]->data) == 0); |
| 427 | + (mutt_bcache_exists(pop_data->bcache, cache_id(ctx->hdrs[i]->data)) == 0); |
411 | 428 | ctx->hdrs[i]->old = false; |
412 | 429 | ctx->hdrs[i]->read = false; |
413 | 430 | if (hcached) |
@@ -597,7 +614,7 @@ static int pop_fetch_message(struct Context *ctx, struct Message *msg, int msgno |
597 | 614 | unsigned short bcache = 1; |
598 | 615 |
|
599 | 616 | /* see if we already have the message in body cache */ |
600 | | - msg->fp = mutt_bcache_get(pop_data->bcache, h->data); |
| 617 | + msg->fp = mutt_bcache_get(pop_data->bcache, cache_id(h->data)); |
601 | 618 | if (msg->fp) |
602 | 619 | return 0; |
603 | 620 |
|
@@ -644,7 +661,7 @@ static int pop_fetch_message(struct Context *ctx, struct Message *msg, int msgno |
644 | 661 | NetInc, h->content->length + h->content->offset - 1); |
645 | 662 |
|
646 | 663 | /* see if we can put in body cache; use our cache as fallback */ |
647 | | - msg->fp = mutt_bcache_put(pop_data->bcache, h->data); |
| 664 | + msg->fp = mutt_bcache_put(pop_data->bcache, cache_id(h->data)); |
648 | 665 | if (!msg->fp) |
649 | 666 | { |
650 | 667 | /* no */ |
@@ -689,7 +706,7 @@ static int pop_fetch_message(struct Context *ctx, struct Message *msg, int msgno |
689 | 706 | * portion of the headers, those required for the main display. |
690 | 707 | */ |
691 | 708 | if (bcache) |
692 | | - mutt_bcache_commit(pop_data->bcache, h->data); |
| 709 | + mutt_bcache_commit(pop_data->bcache, cache_id(h->data)); |
693 | 710 | else |
694 | 711 | { |
695 | 712 | cache->index = h->index; |
@@ -783,7 +800,7 @@ static int pop_sync_mailbox(struct Context *ctx, int *index_hint) |
783 | 800 | ret = pop_query(pop_data, buf, sizeof(buf)); |
784 | 801 | if (ret == 0) |
785 | 802 | { |
786 | | - mutt_bcache_del(pop_data->bcache, ctx->hdrs[i]->data); |
| 803 | + mutt_bcache_del(pop_data->bcache, cache_id(ctx->hdrs[i]->data)); |
787 | 804 | #ifdef USE_HCACHE |
788 | 805 | mutt_hcache_delete(hc, ctx->hdrs[i]->data, strlen(ctx->hdrs[i]->data)); |
789 | 806 | #endif |
|
0 commit comments