2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2013 Colin Leroy <colin@colino.net> and
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "claws-features.h"
29 #include <string.h> /* for strlen */
30 #include <stdio.h> /* for strstr */
32 /* It's only a valid armor header if it's at the
33 * beginning of the buffer or a new line, and if
34 * there is only whitespace after it on the rest
36 gchar
*pgp_locate_armor_header(const gchar
*haystack
, const gchar
*needle
)
41 g_return_val_if_fail(haystack
!= NULL
, NULL
);
42 g_return_val_if_fail(needle
!= NULL
, NULL
);
44 /* Start at the beginning */
45 txt
= (gchar
*)haystack
;
46 while (*txt
!= '\0') {
48 /* Find next occurrence */
49 x
= strstr(txt
, needle
);
54 /* Make sure that what we found is at the beginning of line */
55 if (x
!= haystack
&& *(x
- 1) != '\n') {
60 /* Now look at what's between end of needle and end of that line.
61 * If there is anything else than whitespace, stop looking. */
62 i
= x
+ strlen(needle
);
64 while (*i
!= '\0' && *i
!= '\r' && *i
!= '\n') {
65 if (!g_ascii_isspace(*i
)) {
75 /* We are at the end of haystack */
85 #endif /* USE_GPGME */