(mh_quote,mh_expand_aliases): New functions
Showing
1 changed file
with
70 additions
and
0 deletions
... | @@ -825,3 +825,73 @@ mh_decode_2047 (char *text, char **decoded_text) | ... | @@ -825,3 +825,73 @@ mh_decode_2047 (char *text, char **decoded_text) |
825 | 825 | ||
826 | return mu_rfc2047_decode (charset, text, decoded_text); | 826 | return mu_rfc2047_decode (charset, text, decoded_text); |
827 | } | 827 | } |
828 | |||
829 | void | ||
830 | mh_quote (const char *in, char **out) | ||
831 | { | ||
832 | size_t len = strlen (in); | ||
833 | if (len && in[0] == '"' && in[len - 1] == '"') | ||
834 | { | ||
835 | const char *p; | ||
836 | char *q; | ||
837 | |||
838 | for (p = in + 1; p < in + len - 1; p++) | ||
839 | if (*p == '\\' || *p == '"') | ||
840 | len++; | ||
841 | |||
842 | *out = xmalloc (len + 1); | ||
843 | q = *out; | ||
844 | p = in; | ||
845 | *q++ = *p++; | ||
846 | while (p[1]) | ||
847 | { | ||
848 | if (*p == '\\' || *p == '"') | ||
849 | *q++ = '\\'; | ||
850 | *q++ = *p++; | ||
851 | } | ||
852 | *q++ = *p++; | ||
853 | *q = 0; | ||
854 | } | ||
855 | else | ||
856 | *out = xstrdup (in); | ||
857 | } | ||
858 | |||
859 | void | ||
860 | mh_expand_aliases (mu_message_t msg, | ||
861 | mu_address_t *addr_to, | ||
862 | mu_address_t *addr_cc, | ||
863 | mu_address_t *addr_bcc) | ||
864 | { | ||
865 | mu_header_t hdr; | ||
866 | size_t i, num; | ||
867 | char *buf; | ||
868 | |||
869 | mu_message_get_header (msg, &hdr); | ||
870 | mu_header_get_field_count (hdr, &num); | ||
871 | for (i = 1; i <= num; i++) | ||
872 | { | ||
873 | if (mu_header_aget_field_name (hdr, i, &buf) == 0) | ||
874 | { | ||
875 | if (strcasecmp (buf, MU_HEADER_TO) == 0 | ||
876 | || strcasecmp (buf, MU_HEADER_CC) == 0 | ||
877 | || strcasecmp (buf, MU_HEADER_BCC) == 0) | ||
878 | { | ||
879 | char *value; | ||
880 | mu_address_t addr = NULL; | ||
881 | int incl; | ||
882 | |||
883 | mu_header_aget_field_value_unfold (hdr, i, &value); | ||
884 | |||
885 | mh_alias_expand (value, &addr, &incl); | ||
886 | free (value); | ||
887 | if (strcasecmp (buf, MU_HEADER_TO) == 0) | ||
888 | mu_address_union (addr_to, addr); | ||
889 | else if (strcasecmp (buf, MU_HEADER_CC) == 0) | ||
890 | mu_address_union (addr_cc ? addr_cc : addr_to, addr); | ||
891 | else if (strcasecmp (buf, MU_HEADER_BCC) == 0) | ||
892 | mu_address_union (addr_bcc ? addr_bcc : addr_to, addr); | ||
893 | } | ||
894 | free (buf); | ||
895 | } | ||
896 | } | ||
897 | } | ... | ... |
-
Please register or sign in to post a comment