diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-04-23 11:33:48 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2016-04-23 14:45:27 +0100 |
commit | 6d57fbfa112799366447775d5a52974e29bf887d (patch) | |
tree | b022cdecf9cb27a39508cb9d6db43a016e8912ac /src/libmime/email_addr.c | |
parent | 6832271dbc2771c7e3b2512fef2dcc054ab55c49 (diff) | |
download | rspamd-6d57fbfa112799366447775d5a52974e29bf887d.tar.gz rspamd-6d57fbfa112799366447775d5a52974e29bf887d.zip |
[Feature] Add new representation of email address
Diffstat (limited to 'src/libmime/email_addr.c')
-rw-r--r-- | src/libmime/email_addr.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/libmime/email_addr.c b/src/libmime/email_addr.c new file mode 100644 index 000000000..afb92b183 --- /dev/null +++ b/src/libmime/email_addr.c @@ -0,0 +1,64 @@ +/*- + * Copyright 2016 Vsevolod Stakhov + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "config.h" +#include "email_addr.h" +#include "message.h" + +#include "./parsers/smtp_addr_parser.c" + +static void +rspamd_email_addr_dtor (struct rspamd_email_address *addr) +{ + g_slice_free1 (sizeof (*addr), addr); +} + +struct rspamd_email_address * +rspamd_email_address_from_smtp (const gchar *str, guint len) +{ + struct rspamd_email_address addr, *ret; + + if (str == NULL || len == 0) { + return NULL; + } + + rspamd_smtp_addr_parse (str, len, &addr); + + if (addr.flags & RSPAMD_EMAIL_ADDR_VALID) { + ret = g_slice_alloc (sizeof (*ret)); + memcpy (ret, &addr, sizeof (addr)); + + REF_INIT_RETAIN (ret, rspamd_email_addr_dtor); + + return ret; + } + + return NULL; +} + +struct rspamd_email_address * +rspamd_email_address_ref (struct rspamd_email_address *addr) +{ + REF_RETAIN (addr); + + return addr; +} + +void +rspamd_email_address_unref (struct rspamd_email_address *addr) +{ + REF_RELEASE (addr); +} |