PageRenderTime 37ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/dovecot-2.1.8/dovecot-2.1-pigeonhole-0.3.1/src/lib-sieve/sieve-actions.h

#
C Header | 267 lines | 157 code | 66 blank | 44 comment | 1 complexity | 8d4fc3f0e58ae274376f097ff2dd126d MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  1. /* Copyright (c) 2002-2012 Pigeonhole authors, see the included COPYING file
  2. */
  3. #ifndef __SIEVE_ACTIONS_H
  4. #define __SIEVE_ACTIONS_H
  5. #include "lib.h"
  6. #include "mail-storage.h"
  7. #include "sieve-common.h"
  8. #include "sieve-objects.h"
  9. #include "sieve-extensions.h"
  10. /*
  11. * Action execution environment
  12. */
  13. struct sieve_action_exec_env {
  14. struct sieve_instance *svinst;
  15. struct sieve_result *result;
  16. struct sieve_error_handler *ehandler;
  17. const struct sieve_message_data *msgdata;
  18. struct sieve_message_context *msgctx;
  19. const struct sieve_script_env *scriptenv;
  20. struct sieve_exec_status *exec_status;
  21. };
  22. const char *sieve_action_get_location(const struct sieve_action_exec_env *aenv);
  23. /*
  24. * Action flags
  25. */
  26. enum sieve_action_flags {
  27. SIEVE_ACTFLAG_TRIES_DELIVER = (1 << 0),
  28. SIEVE_ACTFLAG_SENDS_RESPONSE = (1 << 1)
  29. };
  30. /*
  31. * Action definition
  32. */
  33. struct sieve_action_def {
  34. const char *name;
  35. unsigned int flags;
  36. bool (*equals)
  37. (const struct sieve_script_env *senv, const struct sieve_action *act1,
  38. const struct sieve_action *act2);
  39. /* Result verification */
  40. int (*check_duplicate)
  41. (const struct sieve_runtime_env *renv,
  42. const struct sieve_action *act,
  43. const struct sieve_action *act_other);
  44. int (*check_conflict)
  45. (const struct sieve_runtime_env *renv,
  46. const struct sieve_action *act,
  47. const struct sieve_action *act_other);
  48. /* Result printing */
  49. void (*print)
  50. (const struct sieve_action *action,
  51. const struct sieve_result_print_env *penv, bool *keep);
  52. /* Result execution */
  53. bool (*start)
  54. (const struct sieve_action *action,
  55. const struct sieve_action_exec_env *aenv, void **tr_context);
  56. bool (*execute)
  57. (const struct sieve_action *action,
  58. const struct sieve_action_exec_env *aenv, void *tr_context);
  59. bool (*commit)
  60. (const struct sieve_action *action,
  61. const struct sieve_action_exec_env *aenv, void *tr_context, bool *keep);
  62. void (*rollback)
  63. (const struct sieve_action *action,
  64. const struct sieve_action_exec_env *aenv, void *tr_context, bool success);
  65. };
  66. /*
  67. * Action instance
  68. */
  69. struct sieve_action {
  70. const struct sieve_action_def *def;
  71. const struct sieve_extension *ext;
  72. const char *location;
  73. void *context;
  74. struct mail *mail;
  75. bool executed;
  76. };
  77. #define sieve_action_is(act, definition) \
  78. ( (act)->def == &(definition) )
  79. /*
  80. * Action side effects
  81. */
  82. /* Side effect object */
  83. struct sieve_side_effect_def {
  84. struct sieve_object_def obj_def;
  85. /* The action it is supposed to link to */
  86. const struct sieve_action_def *to_action;
  87. /* Context coding */
  88. bool (*dump_context)
  89. (const struct sieve_side_effect *seffect,
  90. const struct sieve_dumptime_env *renv, sieve_size_t *address);
  91. int (*read_context)
  92. (const struct sieve_side_effect *seffect,
  93. const struct sieve_runtime_env *renv, sieve_size_t *address,
  94. void **se_context);
  95. /* Result verification */
  96. int (*merge)
  97. (const struct sieve_runtime_env *renv, const struct sieve_action *action,
  98. const struct sieve_side_effect *old_seffect,
  99. const struct sieve_side_effect *new_seffect, void **old_context);
  100. /* Result printing */
  101. void (*print)
  102. (const struct sieve_side_effect *seffect, const struct sieve_action *action,
  103. const struct sieve_result_print_env *penv, bool *keep);
  104. /* Result execution */
  105. bool (*pre_execute)
  106. (const struct sieve_side_effect *seffect, const struct sieve_action *action,
  107. const struct sieve_action_exec_env *aenv, void **context,
  108. void *tr_context);
  109. bool (*post_execute)
  110. (const struct sieve_side_effect *seffect, const struct sieve_action *action,
  111. const struct sieve_action_exec_env *aenv, void *tr_context);
  112. void (*post_commit)
  113. (const struct sieve_side_effect *seffect, const struct sieve_action *action,
  114. const struct sieve_action_exec_env *aenv, void *tr_context, bool *keep);
  115. void (*rollback)
  116. (const struct sieve_side_effect *seffect, const struct sieve_action *action,
  117. const struct sieve_action_exec_env *aenv, void *tr_context, bool success);
  118. };
  119. struct sieve_side_effect {
  120. struct sieve_object object;
  121. const struct sieve_side_effect_def *def;
  122. void *context;
  123. };
  124. /*
  125. * Side effect operand
  126. */
  127. #define SIEVE_EXT_DEFINE_SIDE_EFFECT(SEF) SIEVE_EXT_DEFINE_OBJECT(SEF)
  128. #define SIEVE_EXT_DEFINE_SIDE_EFFECTS(SEFS) SIEVE_EXT_DEFINE_OBJECTS(SEFS)
  129. #define SIEVE_OPT_SIDE_EFFECT (-1)
  130. extern const struct sieve_operand_class sieve_side_effect_operand_class;
  131. static inline void sieve_opr_side_effect_emit
  132. (struct sieve_binary_block *sblock, const struct sieve_extension *ext,
  133. const struct sieve_side_effect_def *seff)
  134. {
  135. sieve_opr_object_emit(sblock, ext, &seff->obj_def);
  136. }
  137. bool sieve_opr_side_effect_read
  138. (const struct sieve_runtime_env *renv, sieve_size_t *address,
  139. struct sieve_side_effect *seffect);
  140. bool sieve_opr_side_effect_dump
  141. (const struct sieve_dumptime_env *denv, sieve_size_t *address);
  142. /*
  143. * Optional operands
  144. */
  145. int sieve_action_opr_optional_dump
  146. (const struct sieve_dumptime_env *denv, sieve_size_t *address,
  147. signed int *opt_code);
  148. int sieve_action_opr_optional_read
  149. (const struct sieve_runtime_env *renv, sieve_size_t *address,
  150. signed int *opt_code, int *exec_status,
  151. struct sieve_side_effects_list **list);
  152. /*
  153. * Core actions
  154. */
  155. extern const struct sieve_action_def act_redirect;
  156. extern const struct sieve_action_def act_store;
  157. extern const struct sieve_action_def act_discard;
  158. /*
  159. * Store action
  160. */
  161. struct act_store_context {
  162. /* Folder name represented in utf-8 */
  163. const char *mailbox;
  164. };
  165. struct act_store_transaction {
  166. struct act_store_context *context;
  167. struct mailbox *box;
  168. struct mailbox_transaction_context *mail_trans;
  169. struct mail *dest_mail;
  170. const char *error;
  171. enum mail_error error_code;
  172. enum mail_flags flags;
  173. ARRAY_TYPE(const_string) keywords;
  174. unsigned int flags_altered:1;
  175. unsigned int disabled:1;
  176. unsigned int redundant:1;
  177. };
  178. int sieve_act_store_add_to_result
  179. (const struct sieve_runtime_env *renv,
  180. struct sieve_side_effects_list *seffects, const char *folder);
  181. void sieve_act_store_add_flags
  182. (const struct sieve_action_exec_env *aenv, void *tr_context,
  183. const char *const *keywords, enum mail_flags flags);
  184. void sieve_act_store_get_storage_error
  185. (const struct sieve_action_exec_env *aenv, struct act_store_transaction *trans);
  186. /*
  187. * Action utility functions
  188. */
  189. /* Checking for duplicates */
  190. bool sieve_action_duplicate_check_available
  191. (const struct sieve_script_env *senv);
  192. int sieve_action_duplicate_check
  193. (const struct sieve_script_env *senv, const void *id, size_t id_size);
  194. void sieve_action_duplicate_mark
  195. (const struct sieve_script_env *senv, const void *id, size_t id_size,
  196. time_t time);
  197. /* Rejecting mail */
  198. bool sieve_action_reject_mail
  199. (const struct sieve_action_exec_env *aenv,
  200. const char *sender, const char *recipient, const char *reason);
  201. #endif /* __SIEVE_ACTIONS_H */