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.

email_addr.h 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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_EMAIL_ADDR_H_
  17. #define SRC_LIBMIME_EMAIL_ADDR_H_
  18. #include "config.h"
  19. #include "libutil/mem_pool.h"
  20. #include "libutil/ref.h"
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. struct rspamd_mime_header;
  25. enum rspamd_email_address_flags {
  26. RSPAMD_EMAIL_ADDR_VALID = (1 << 0),
  27. RSPAMD_EMAIL_ADDR_IP = (1 << 1),
  28. RSPAMD_EMAIL_ADDR_BRACED = (1 << 2),
  29. RSPAMD_EMAIL_ADDR_QUOTED = (1 << 3),
  30. RSPAMD_EMAIL_ADDR_EMPTY = (1 << 4),
  31. RSPAMD_EMAIL_ADDR_HAS_BACKSLASH = (1 << 5),
  32. RSPAMD_EMAIL_ADDR_ADDR_ALLOCATED = (1 << 6),
  33. RSPAMD_EMAIL_ADDR_USER_ALLOCATED = (1 << 7),
  34. RSPAMD_EMAIL_ADDR_HAS_8BIT = (1 << 8),
  35. RSPAMD_EMAIL_ADDR_ALIASED = (1 << 9),
  36. RSPAMD_EMAIL_ADDR_ORIGINAL = (1 << 10),
  37. };
  38. /*
  39. * Structure that represents email address in a convenient way
  40. */
  41. struct rspamd_email_address {
  42. const char *raw;
  43. const char *addr;
  44. const char *user;
  45. const char *domain;
  46. const char *name;
  47. unsigned int raw_len;
  48. unsigned int addr_len;
  49. unsigned int domain_len;
  50. unsigned int user_len;
  51. unsigned int flags;
  52. };
  53. struct rspamd_task;
  54. /**
  55. * Create email address from a single rfc822 address (e.g. from mail from:)
  56. * @param str string to use
  57. * @param len length of string
  58. * @return
  59. */
  60. struct rspamd_email_address *rspamd_email_address_from_smtp(const char *str, unsigned int len);
  61. /**
  62. * Parses email address from the mime header, decodes names and return the array
  63. * of `rspamd_email_address`. If `src` is NULL, then this function creates a new
  64. * array and adds a destructor to remove elements when `pool` is destroyed.
  65. * Otherwise, addresses are appended to `src`.
  66. * @param hdr
  67. * @param len
  68. * @return
  69. */
  70. GPtrArray *
  71. rspamd_email_address_from_mime(rspamd_mempool_t *pool, const char *hdr, unsigned int len,
  72. GPtrArray *src, int max_elements);
  73. /**
  74. * Destroys list of email addresses
  75. * @param ptr
  76. */
  77. void rspamd_email_address_list_destroy(gpointer ptr);
  78. void rspamd_email_address_free(struct rspamd_email_address *addr);
  79. #ifdef __cplusplus
  80. }
  81. #endif
  82. #endif /* SRC_LIBMIME_EMAIL_ADDR_H_ */