summaryrefslogtreecommitdiff
path: root/libmailutils/filter/decode.c
blob: 3910d7d8f521f2310169751b50f1400c3008f3fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* GNU Mailutils -- a suite of utilities for electronic mail
   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2009,
   2010, 2011 Free Software Foundation, Inc.

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
   License as published by the Free Software Foundation; either
   version 3 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Lesser General Public License for more details.

   You should have received a copy of the GNU Lesser General
   Public License along with this library.  If not, see 
   <http://www.gnu.org/licenses/>. */

#if HAVE_CONFIG_H
# include <config.h>
#endif

#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <mailutils/stream.h>
#include <mailutils/filter.h>
#include <mailutils/cstr.h>

enum mu_iconv_fallback_mode mu_default_fallback_mode = mu_fallback_copy_octal;

int
mu_set_default_fallback (const char *str)
{
  if (strcmp (str, "none") == 0)
    mu_default_fallback_mode = mu_fallback_none;
  else if (strcmp (str, "copy-pass") == 0)
    mu_default_fallback_mode = mu_fallback_copy_pass;
  else if (strcmp (str, "copy-octal") == 0)
    mu_default_fallback_mode = mu_fallback_copy_octal;
  else
    return EINVAL;
  return 0;
}

int
mu_decode_filter_args (mu_stream_t *pfilter, mu_stream_t input,
		       const char *filter_name, int argc, const char **argv,
		       const char *fromcode, const char *tocode)
{
  int xargc, i;
  char **xargv;
  int rc;
  
  xargc = argc + 5;
  xargv = calloc (xargc + 1, sizeof (xargv[0]));
  if (!xargv)
    return ENOMEM;

  i = 0;
  if (filter_name)
    xargv[i++] = (char*) filter_name;
  for (; i < argc; i++)
    xargv[i] = (char*) argv[i];

  if (i)
    xargv[i++] = "+";
  xargv[i++] = "ICONV";
  xargv[i++] = (char*) fromcode;
  xargv[i++] = (char*) tocode;
  xargv[i] = NULL;

  rc = mu_filter_chain_create (pfilter, input,
			       MU_FILTER_DECODE, MU_STREAM_READ,
			       i, xargv);
  free (xargv);
  return rc;
}


int
mu_decode_filter (mu_stream_t *pfilter, mu_stream_t input,
		  const char *filter_name,
		  const char *fromcode, const char *tocode)
{
  return mu_decode_filter_args (pfilter, input, filter_name, 0, NULL,
				fromcode, tocode);
}

Return to:

Send suggestions and report system problems to the System administrator.