You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mime_headers.h 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*-
  2. * Copyright 2016 Vsevolod Stakhov
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef SRC_LIBMIME_MIME_HEADERS_H_
  17. #define SRC_LIBMIME_MIME_HEADERS_H_
  18. #include "config.h"
  19. #include "libutil/mem_pool.h"
  20. struct rspamd_task;
  21. enum rspamd_rfc2047_encoding {
  22. RSPAMD_RFC2047_QP = 0,
  23. RSPAMD_RFC2047_BASE64,
  24. };
  25. enum rspamd_mime_header_special_type {
  26. RSPAMD_HEADER_GENERIC = 0,
  27. RSPAMD_HEADER_RECEIVED = 1 << 0,
  28. RSPAMD_HEADER_TO = 1 << 2,
  29. RSPAMD_HEADER_CC = 1 << 3,
  30. RSPAMD_HEADER_BCC = 1 << 4,
  31. RSPAMD_HEADER_FROM = 1 << 5,
  32. RSPAMD_HEADER_MESSAGE_ID = 1 << 6,
  33. RSPAMD_HEADER_SUBJECT = 1 << 7,
  34. RSPAMD_HEADER_RETURN_PATH = 1 << 8,
  35. RSPAMD_HEADER_DELIVERED_TO = 1 << 9,
  36. RSPAMD_HEADER_SENDER = 1 << 10,
  37. RSPAMD_HEADER_RCPT = 1 << 11,
  38. RSPAMD_HEADER_UNIQUE = 1 << 12
  39. };
  40. struct rspamd_mime_header {
  41. gchar *name;
  42. gchar *value;
  43. const gchar *raw_value; /* As it is in the message (unfolded and unparsed) */
  44. gsize raw_len;
  45. gboolean tab_separated;
  46. gboolean empty_separator;
  47. guint order;
  48. enum rspamd_mime_header_special_type type;
  49. gchar *separator;
  50. gchar *decoded;
  51. };
  52. /**
  53. * Process headers and store them in `target`
  54. * @param task
  55. * @param target
  56. * @param in
  57. * @param len
  58. * @param check_newlines
  59. */
  60. void rspamd_mime_headers_process (struct rspamd_task *task, GHashTable *target,
  61. GQueue *order,
  62. const gchar *in, gsize len,
  63. gboolean check_newlines);
  64. /**
  65. * Perform rfc2047 decoding of a header
  66. * @param pool
  67. * @param in
  68. * @param inlen
  69. * @return
  70. */
  71. gchar * rspamd_mime_header_decode (rspamd_mempool_t *pool, const gchar *in,
  72. gsize inlen, gboolean *invalid_utf);
  73. /**
  74. * Encode mime header if needed
  75. * @param in
  76. * @param len
  77. * @return newly allocated encoded header
  78. */
  79. gchar * rspamd_mime_header_encode (const gchar *in, gsize len);
  80. /**
  81. * Generate new unique message id
  82. * @param fqdn
  83. * @return
  84. */
  85. gchar * rspamd_mime_message_id_generate (const gchar *fqdn);
  86. #endif /* SRC_LIBMIME_MIME_HEADERS_H_ */