#endif
}
+const gchar *
+rspamd_task_get_principal_recipient (struct rspamd_task *task)
+{
+ InternetAddress *iaelt = NULL;
+
+ if (task->deliver_to) {
+ return task->deliver_to;
+ }
+
+#ifdef GMIME24
+ InternetAddressMailbox *imb;
+
+ if (task->rcpt_envelope != NULL) {
+ iaelt = internet_address_list_get_address (task->rcpt_envelope, 0);
+ }
+ else if (task->rcpt_mime != NULL) {
+ iaelt = internet_address_list_get_address (task->rcpt_mime, 0);
+ }
+ imb = INTERNET_ADDRESS_IS_MAILBOX(iaelt) ?
+ INTERNET_ADDRESS_MAILBOX (iaelt) : NULL;
+
+ return (imb ? internet_address_mailbox_get_addr (imb) : NULL);
+#else
+ if (task->rcpt_envelope != NULL) {
+ iaelt = internet_address_list_get_address (task->rcpt_envelope);
+ }
+ else if (task->rcpt_mime != NULL) {
+ iaelt = internet_address_list_get_address (task->rcpt_mime);
+ }
+
+ return (iaelt != NULL ? internet_address_get_addr (iaelt) : NULL);
+#endif
+}
+
gboolean
rspamd_task_add_recipient (struct rspamd_task *task, const gchar *rcpt)
{
*/
const gchar *rspamd_task_get_sender (struct rspamd_task *task);
+/**
+ * Return addresses in the following precendence:
+ * - deliver to
+ * - the first smtp recipient
+ * - the first mime recipient
+ * @param task
+ * @return
+ */
+const gchar *rspamd_task_get_principal_recipient (struct rspamd_task *task);
+
/**
* Add a recipient for a task
* @param task task object
{
gsize tlen = 0;
const gchar *p = pattern, *elt;
- InternetAddressList *ia;
- InternetAddress *iaelt;
- InternetAddressMailbox *imb;
gchar *d, *end;
enum {
just_char,
}
break;
case 'r':
- ia = GET_TASK_ELT (task, rcpt_envelope);
- if (ia != NULL) {
- iaelt = internet_address_list_get_address (ia, 0);
- imb = INTERNET_ADDRESS_IS_MAILBOX (iaelt) ?
- INTERNET_ADDRESS_MAILBOX (iaelt) : NULL;
+ elt = rspamd_task_get_principal_recipient (task);
- elt = (imb ? internet_address_mailbox_get_addr (imb) : NULL);
-
- if (elt) {
- tlen += strlen (elt);
- }
+ if (elt) {
+ tlen += strlen (elt);
}
break;
case 'l':
}
break;
case 'r':
- ia = GET_TASK_ELT (task, rcpt_envelope);
- if (ia != NULL) {
- iaelt = internet_address_list_get_address (ia, 0);
- imb = INTERNET_ADDRESS_IS_MAILBOX (iaelt) ?
- INTERNET_ADDRESS_MAILBOX (iaelt) : NULL;
+ elt = rspamd_task_get_principal_recipient (task);
- elt = (imb ? internet_address_mailbox_get_addr (imb) : NULL);
-
- if (elt) {
- d += rspamd_strlcpy (d, elt, end - d);
- }
+ if (elt) {
+ d += rspamd_strlcpy (d, elt, end - d);
}
break;
case 'l':
gint64 id = 0; /* Default user is 0 */
gint rc, err_idx;
const gchar *user = NULL;
- const InternetAddress *ia;
struct rspamd_task **ptask;
lua_State *L = db->L;
GString *tb;
if (db->cbref_user == -1) {
- if (task->deliver_to != NULL) {
- /* Use deliver-to value if presented */
- user = task->deliver_to;
- }
- if (task->user != NULL) {
- /* Use user value if presented */
- user = task->user;
- }
- else if (task->rcpt_envelope != NULL) {
- /* Check envelope recipients */
- if (internet_address_list_length (task->rcpt_envelope) == 1) {
- /* XXX: we support now merely single recipient statistics */
- ia = internet_address_list_get_address (task->rcpt_envelope, 0);
-
- if (ia != NULL) {
- user = internet_address_mailbox_get_addr (
- INTERNET_ADDRESS_MAILBOX (ia));
- }
- }
- }
- /* XXX: We ignore now mime recipients as they could be easily forged */
+ user = rspamd_task_get_principal_recipient (task);
}
else {
/* Execute lua function to get userdata */