talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit 0578ee72394db30e451d7eaf638cc5cbdbfa3fd9
parent 4b26e5875785e87b994d5d81f6f15582726abd5f
Author: Ricardo Mones <ricardo@mones.org>
Date:   Sat,  6 Nov 2021 15:04:58 +0100

Refactor CRLF-truncation into a function

Diffstat:
Msrc/common/utils.c | 15+++++++++++++++
Msrc/common/utils.h | 1+
Msrc/mainwindow.c | 8++------
Msrc/plugins/vcalendar/vcal_folder.c | 11+----------
4 files changed, 19 insertions(+), 16 deletions(-)

diff --git a/src/common/utils.c b/src/common/utils.c @@ -284,6 +284,21 @@ gchar *strcrchomp(gchar *str) return str; } +/* truncates string at first CR (carriage return) or LF (line feed) */ +gchar *strcrlftrunc(gchar *str) +{ + gchar *p = NULL; + + if ((str == NULL) || (!*str)) return str; + + if ((p = strstr(str, "\r")) != NULL) + *p = '\0'; + if ((p = strstr(str, "\n")) != NULL) + *p = '\0'; + + return str; +} + #ifndef HAVE_STRCASESTR /* Similar to `strstr' but this function ignores the case of both strings. */ gchar *strcasestr(const gchar *haystack, const gchar *needle) diff --git a/src/common/utils.h b/src/common/utils.h @@ -273,6 +273,7 @@ gchar *strretchomp (gchar *str); gchar *strtailchomp (gchar *str, gchar tail_char); gchar *strcrchomp (gchar *str); +gchar *strcrlftrunc (gchar *str); #ifndef HAVE_STRCASESTR gchar *strcasestr (const gchar *haystack, const gchar *needle); diff --git a/src/mainwindow.c b/src/mainwindow.c @@ -5480,7 +5480,6 @@ void mainwindow_learn (MainWindow *mainwin, gboolean is_spam) void mainwindow_jump_to(const gchar *target, gboolean popup) { gchar *tmp = NULL; - gchar *p = NULL; FolderItem *item = NULL; gchar *msg = NULL; MainWindow *mainwin = mainwindow_get_mainwindow(); @@ -5497,11 +5496,8 @@ void mainwindow_jump_to(const gchar *target, gboolean popup) tmp = from_uri; else tmp = g_strdup(target); - - if ((p = strstr(tmp, "\r")) != NULL) - *p = '\0'; - if ((p = strstr(tmp, "\n")) != NULL) - *p = '\0'; + + strcrlftrunc(tmp); if ((item = folder_find_item_from_identifier(tmp))) { g_print("selecting folder '%s'\n", tmp); diff --git a/src/plugins/vcalendar/vcal_folder.c b/src/plugins/vcalendar/vcal_folder.c @@ -1789,19 +1789,10 @@ static gchar *feed_get_title(const gchar *str) gchar *title = NULL; if (strstr(str, "X-WR-CALNAME:")) { title = g_strdup(strstr(str, "X-WR-CALNAME:")+strlen("X-WR-CALNAME:")); - if (strstr(title, "\n")) - *(strstr(title, "\n")) = '\0'; - if (strstr(title, "\r")) - *(strstr(title, "\r")) = '\0'; } else if (strstr(str, "X-WR-CALDESC:")) { title = g_strdup(strstr(str, "X-WR-CALDESC:")+strlen("X-WR-CALDESC:")); - if (strstr(title, "\n")) - *(strstr(title, "\n")) = '\0'; - if (strstr(title, "\r")) - *(strstr(title, "\r")) = '\0'; } - - return title; + return strcrlftrunc(title); } static void update_subscription_finish(const gchar *uri, gchar *feed, gboolean verbose, gchar *error)