Improve some sieve-related translations
[claws.git] / src / plugins / pgpcore / pgp_utils.c
blob0489ec820ad60d0c70270361a1d78225620f7892
1 /*
2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2013 Colin Leroy <colin@colino.net> and
4 * the Claws Mail team
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/>.
21 #ifdef HAVE_CONFIG_H
22 # include "config.h"
23 #include "claws-features.h"
24 #endif
26 #ifdef USE_GPGME
28 #include <glib.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
35 * of the line. */
36 gchar *pgp_locate_armor_header(const gchar *haystack, const gchar *needle)
38 gchar *txt, *x, *i;
39 gint ok;
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);
51 if (x == NULL)
52 break;
54 /* Make sure that what we found is at the beginning of line */
55 if (x != haystack && *(x - 1) != '\n') {
56 txt = x + 1;
57 continue;
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);
63 ok = 1;
64 while (*i != '\0' && *i != '\r' && *i != '\n') {
65 if (!g_ascii_isspace(*i)) {
66 ok = 0;
67 break;
69 i++;
72 if (ok)
73 return x;
75 /* We are at the end of haystack */
76 if (*i == '\0')
77 return NULL;
79 txt = i + 1;
82 return NULL;
85 #endif /* USE_GPGME */