From: | "Cristian Prieto" <cristian(at)clickdiario(dot)com> |
---|---|
To: | <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Email Verfication Regular Expression |
Date: | 2005-09-08 18:16:36 |
Message-ID: | 039b01c5b4a1$74dde280$6500a8c0@gt.ClickDiario.local |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Well, I guess this could be a hard-expensive way to do it but I've done this
little Stored Function, it doesn't use a regular expresion (you could pass
your email first to one to check it out I guess).
#include "postgres.h"
#include "fmgr.h"
#include <netinet/in.h>
#include <arpa/nameser.h>
#include <resolv.h>
PG_FUNCTION_INFO_V1(digmx);
Datum
digmx(PG_FUNCTION_ARGS)
{
int res;
char *name;
char answer[1024];
text *arg;
arg = PG_GETARG_TEXT_P(0);
res = res_init();
if(res != 0) {
// Aki reporto un error
}
name = (char *) palloc(VARSIZE(arg)-VARHDRSZ);
strcpy(name, VARDATA(arg));
res = res_query(name, C_IN, T_MX, answer, sizeof(answer));
if(res == -1) {
PG_RETURN_BOOL(false);
} else {
// Aki imprimimos lo que debe escupir
PG_RETURN_BOOL(true);
}
}
You can pass the domain to that function and It would check using resolv if
the domains has an mx entry in the nameserver. I guess it is a little slow
(it was not thinking to use it for speed, but I accept suggestions for it!)
but I think it is enough easy and it could be usefull for somebody.
mydb# SELECT digmx('hotmail.com');
digmx
------
t
(1 row)
mydb# SELECT digmx('hotmail.co');
digmx
------
f
(1 row)
I know, it could be a very dumb to check the domain, but I consider myself
as a totally newbie database/unix/programmer.
Thanks a lot!
PD: Please, I accept suggestion to improve this function.
From | Date | Subject | |
---|---|---|---|
Next Message | Peter Fein | 2005-09-08 19:07:16 | Re: back references using regex |
Previous Message | Matthew Peter | 2005-09-08 18:03:10 | Re: back references using regex |