#!/usr/bin/perl use strict; $^W = 1; use Test::More tests => 25; BEGIN { use_ok('Qpsmtpd::Address'); } my $as; my $ao; $as = '<>'; $ao = Qpsmtpd::Address->parse($as); ok ($ao, "parse $as"); is ($ao->format, $as, "format $as"); $as = ''; $ao = Qpsmtpd::Address->parse($as); ok ($ao, "parse $as"); is ($ao->format, $as, "format $as"); is ($ao->user, 'foo', 'user'); is ($ao->host, 'example.com', 'host'); # the \ before the @ in the local part is not required, but # allowed. For simplicity we add a backslash before all characters # which are not allowed in a dot-string. $as = '<"musa_ibrah@caramail.comandrea.luger"@wifo.ac.at>'; $ao = Qpsmtpd::Address->parse($as); ok ($ao, "parse $as"); is ($ao->format, '<"musa_ibrah\@caramail.comandrea.luger"@wifo.ac.at>', "format $as"); # email addresses with spaces $as = ''; $ao = Qpsmtpd::Address->parse($as); ok ($ao, "parse $as"); is ($ao->format, '<"foo\ bar"@example.com>', "format $as"); $as = 'foo@example.com'; $ao = Qpsmtpd::Address->new($as); ok ($ao, "new $as"); is ($ao->address, $as, "address $as"); $as = ''; $ao = Qpsmtpd::Address->new($as); ok ($ao, "new $as"); is ($ao->address, 'foo@example.com', "address $as"); $as = ''; $ao = Qpsmtpd::Address->new($as); ok ($ao, "new $as"); is ($ao->format, $as, "format $as"); $as = 'foo@foo.x.example.com'; ok ($ao = Qpsmtpd::Address->parse('<'.$as.'>'), "parse $as"); is ($ao && $ao->address, $as, "address $as"); # Not sure why we can change the address like this, but we can so test it ... is ($ao && $ao->address('test@example.com'), 'test@example.com', 'address(test@example.com)'); $as = ''; $ao = Qpsmtpd::Address->new($as); ok ($ao, "new $as"); is ($ao->format, $as, "format $as"); is ("$ao", $as, "overloaded stringify $as"); $as = 'foo@foo.x.example.com'; ok ($ao = Qpsmtpd::Address->parse("<$as>"), "parse <$as>"); is ($ao && $ao->address, $as, "address $as");