c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#ifndef MESSAGE_ADDRESS_H
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen#define MESSAGE_ADDRESS_H
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen
cc77c1cfe8d072765f793474f49fecd897525466Stephan Boschstruct smtp_address;
cc77c1cfe8d072765f793474f49fecd897525466Stephan Bosch
5ce2084ada06ade9f44fc2914c34658e9a842dc1Timo Sirainen/* group: ... ; will be stored like:
a24665de9d5c773115a5918e60ed587aafe67d5cTimo Sirainen {name = NULL, NULL, "group", NULL}, ..., {NULL, NULL, NULL, NULL}
5ce2084ada06ade9f44fc2914c34658e9a842dc1Timo Sirainen*/
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainenstruct message_address {
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen struct message_address *next;
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen
a1973d0f171b027f9a7c642bc1c2134293731e1cTimo Sirainen /* display-name */
a1973d0f171b027f9a7c642bc1c2134293731e1cTimo Sirainen const char *name;
a1973d0f171b027f9a7c642bc1c2134293731e1cTimo Sirainen /* route string contains the @ prefix */
a1973d0f171b027f9a7c642bc1c2134293731e1cTimo Sirainen const char *route;
a1973d0f171b027f9a7c642bc1c2134293731e1cTimo Sirainen /* local-part */
a1973d0f171b027f9a7c642bc1c2134293731e1cTimo Sirainen const char *mailbox;
a1973d0f171b027f9a7c642bc1c2134293731e1cTimo Sirainen const char *domain;
a1973d0f171b027f9a7c642bc1c2134293731e1cTimo Sirainen /* there were errors when parsing this address */
88b8c5db9f66bdbb70d274d8592947716f364c36Timo Sirainen bool invalid_syntax;
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen};
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen
f40e6ef5190f68c2fd0e94c0b001bdf7d160236aTimo Sirainen/* Parse message addresses from given data. If fill_missing is TRUE, missing
f40e6ef5190f68c2fd0e94c0b001bdf7d160236aTimo Sirainen mailbox and domain are set to MISSING_MAILBOX and MISSING_DOMAIN strings.
f86c599ead3602dc2d63a473cc13c1119978f538Timo Sirainen Otherwise they're set to "".
f86c599ead3602dc2d63a473cc13c1119978f538Timo Sirainen
f86c599ead3602dc2d63a473cc13c1119978f538Timo Sirainen Note that giving an empty string will return NULL since there are no
f86c599ead3602dc2d63a473cc13c1119978f538Timo Sirainen addresses. */
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainenstruct message_address *
5ce2084ada06ade9f44fc2914c34658e9a842dc1Timo Sirainenmessage_address_parse(pool_t pool, const unsigned char *data, size_t size,
f40e6ef5190f68c2fd0e94c0b001bdf7d160236aTimo Sirainen unsigned int max_addresses, bool fill_missing);
5ce2084ada06ade9f44fc2914c34658e9a842dc1Timo Sirainen
15581297511b658a29c707c6031a258bab7bf1a5Stephan Bosch/* Parse RFC 5322 "path" (Return-Path header) from given data. Returns -1 if
15581297511b658a29c707c6031a258bab7bf1a5Stephan Bosch the path is invalid and 0 otherwise.
15581297511b658a29c707c6031a258bab7bf1a5Stephan Bosch */
15581297511b658a29c707c6031a258bab7bf1a5Stephan Boschint message_address_parse_path(pool_t pool, const unsigned char *data,
15581297511b658a29c707c6031a258bab7bf1a5Stephan Bosch size_t size, struct message_address **addr_r);
15581297511b658a29c707c6031a258bab7bf1a5Stephan Bosch
cc77c1cfe8d072765f793474f49fecd897525466Stephan Boschvoid message_address_init(struct message_address *addr,
cc77c1cfe8d072765f793474f49fecd897525466Stephan Bosch const char *name, const char *mailbox, const char *domain)
cc77c1cfe8d072765f793474f49fecd897525466Stephan Bosch ATTR_NULL(1);
cc77c1cfe8d072765f793474f49fecd897525466Stephan Boschvoid message_address_init_from_smtp(struct message_address *addr,
cc77c1cfe8d072765f793474f49fecd897525466Stephan Bosch const char *name, const struct smtp_address *smtp_addr)
cc77c1cfe8d072765f793474f49fecd897525466Stephan Bosch ATTR_NULL(1);
cc77c1cfe8d072765f793474f49fecd897525466Stephan Bosch
5ce2084ada06ade9f44fc2914c34658e9a842dc1Timo Sirainenvoid message_address_write(string_t *str, const struct message_address *addr);
fbad2d10747ac76a29b3a9dcfb4e7e67236ab872Stephan Boschconst char *message_address_to_string(const struct message_address *addr);
fbad2d10747ac76a29b3a9dcfb4e7e67236ab872Stephan Boschconst char *message_address_first_to_string(const struct message_address *addr);
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen
c10706d231f0690e934affdf18daa9b9a41814c6Timo Sirainen/* Returns TRUE if header is known to be an address */
c10706d231f0690e934affdf18daa9b9a41814c6Timo Sirainenbool message_header_is_address(const char *hdr_name);
c10706d231f0690e934affdf18daa9b9a41814c6Timo Sirainen
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen#endif