1 /* sievedir.h -- functions for managing scripts in a sievedir
2  *
3  * Copyright (c) 1994-2020 Carnegie Mellon University.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  *
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in
14  *    the documentation and/or other materials provided with the
15  *    distribution.
16  *
17  * 3. The name "Carnegie Mellon University" must not be used to
18  *    endorse or promote products derived from this software without
19  *    prior written permission. For permission or any legal
20  *    details, please contact
21  *      Carnegie Mellon University
22  *      Center for Technology Transfer and Enterprise Creation
23  *      4615 Forbes Avenue
24  *      Suite 302
25  *      Pittsburgh, PA  15213
26  *      (412) 268-7393, fax: (412) 268-7395
27  *      innovation@andrew.cmu.edu
28  *
29  * 4. Redistributions of any form whatsoever must retain the following
30  *    acknowledgment:
31  *    "This product includes software developed by Computing Services
32  *     at Carnegie Mellon University (http://www.cmu.edu/computing/)."
33  *
34  * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
35  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
36  * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
37  * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
38  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
39  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
40  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
41  */
42 
43 #ifndef INCLUDED_SIEVEDIR_H
44 #define INCLUDED_SIEVEDIR_H
45 
46 #include "util.h"
47 
48 /* error codes */
49 #define SIEVEDIR_DONE      1  /* for short-circuiting sievedir_foreach() */
50 #define SIEVEDIR_OK        0
51 #define SIEVEDIR_IOERROR  -1
52 #define SIEVEDIR_NOTFOUND -2
53 #define SIEVEDIR_INVALID  -3
54 #define SIEVEDIR_FAIL     -4
55 
56 #define BYTECODE_SUFFIX        ".bc"
57 #define BYTECODE_SUFFIX_LEN    3
58 #define SCRIPT_SUFFIX          ".script"
59 #define SCRIPT_SUFFIX_LEN      7
60 #define DEFAULTBC_NAME         "defaultbc"
61 
62 #define SIEVEDIR_MAX_NAME_LEN  1024 - SCRIPT_SUFFIX_LEN - 4 /* for ".NEW" */
63 
64 #define SIEVEDIR_SCRIPTS_ONLY  (1<<0)
65 #define SIEVEDIR_IGNORE_JUNK   (1<<1)
66 
67 int sievedir_foreach(const char *sievedir, unsigned flags,
68                      int (*func)(const char *sievedir,
69                                  const char *name, struct stat *sbuf,
70                                  const char *link_target, void *rock),
71                      void *rock);
72 
73 int sievedir_num_scripts(const char *sievedir, const char *name);
74 
75 int sievedir_valid_name(const struct buf *name);
76 
77 int sievedir_script_exists(const char *sievedir, const char *name);
78 int sievedir_script_isactive(const char *sievedir, const char *name);
79 const char *sievedir_get_active(const char *sievedir);
80 
81 int sievedir_activate_script(const char *sievedir, const char *name);
82 int sievedir_deactivate_script(const char *sievedir);
83 
84 struct buf *sievedir_get_script(const char *sievedir, const char *script);
85 int sievedir_put_script(const char *sievedir, const char *name,
86                         const char *content, char **errors);
87 int sievedir_delete_script(const char *sievedir, const char *name);
88 int sievedir_rename_script(const char *sievedir,
89                            const char *oldname, const char *newname);
90 
91 #endif /* INCLUDED_SIEVEDIR_H */
92