/ViaThinkSoft Java Utils/test/emailSayersTests.xml |
---|
0,0 → 1,1746 |
<?xml version="1.0" encoding="utf-8"?> |
<!-- |
Source: http://isemail.googlecode.com/svn/trunk/tests/tests.xml |
--> |
<tests version="1.10"> |
<test> |
<address>first.last@example.com</address> |
<valid>true</valid> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>1</id> |
</test> |
<test> |
<address>1234567890123456789012345678901234567890123456789012345678901234@example.com</address> |
<valid>true</valid> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>2</id> |
</test> |
<test> |
<address>first.last@sub.do,com</address> |
<valid>false</valid> |
<comment>Mistyped comma instead of dot (replaces old #3 which was the same as #57)</comment> |
<source>Rob <bob@bob.com></source> |
<id>3</id> |
</test> |
<test> |
<address>"first\"last"@example.com</address> |
<valid>true</valid> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>4</id> |
</test> |
<test> |
<address>first\@last@example.com</address> |
<valid>false</valid> |
<comment>Escaping can only happen within a quoted string</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>5</id> |
</test> |
<test> |
<address>"first@last"@example.com</address> |
<valid>true</valid> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>6</id> |
</test> |
<test> |
<address>"first\\last"@example.com</address> |
<valid>true</valid> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>7</id> |
</test> |
<test> |
<address>x@x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x2</address> |
<valid>true</valid> |
<comment>Total length reduced to 254 characters so it's still valid</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>8</id> |
</test> |
<test> |
<address>1234567890123456789012345678901234567890123456789012345678@12345678901234567890123456789012345678901234567890123456789.12345678901234567890123456789012345678901234567890123456789.123456789012345678901234567890123456789012345678901234567890123.example.com</address> |
<valid>true</valid> |
<comment>Total length reduced to 254 characters so it's still valid</comment> |
<source>RFC 3696 erratum 1690</source> |
<sourcelink>http://www.rfc-editor.org/errata_search.php?rfc=3696&eid=1690</sourcelink> |
<id>9</id> |
</test> |
<test> |
<address>first.last@[12.34.56.78]</address> |
<valid>true</valid> |
<source>RFC 3696 erratum 1690</source> |
<sourcelink>http://www.rfc-editor.org/errata_search.php?rfc=3696&eid=1690</sourcelink> |
<id>10</id> |
</test> |
<test> |
<address>first.last@[IPv6:::12.34.56.78]</address> |
<valid>true</valid> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>11</id> |
</test> |
<test> |
<address>first.last@[IPv6:1111:2222:3333::4444:12.34.56.78]</address> |
<valid>true</valid> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>12</id> |
</test> |
<test> |
<address>first.last@[IPv6:1111:2222:3333:4444:5555:6666:12.34.56.78]</address> |
<valid>true</valid> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>13</id> |
</test> |
<test> |
<address>first.last@[IPv6:::1111:2222:3333:4444:5555:6666]</address> |
<valid>true</valid> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>14</id> |
</test> |
<test> |
<address>first.last@[IPv6:1111:2222:3333::4444:5555:6666]</address> |
<valid>true</valid> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>15</id> |
</test> |
<test> |
<address>first.last@[IPv6:1111:2222:3333:4444:5555:6666::]</address> |
<valid>true</valid> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>16</id> |
</test> |
<test> |
<address>first.last@[IPv6:1111:2222:3333:4444:5555:6666:7777:8888]</address> |
<valid>true</valid> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>17</id> |
</test> |
<test> |
<address>first.last@x23456789012345678901234567890123456789012345678901234567890123.example.com</address> |
<valid>true</valid> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>18</id> |
</test> |
<test> |
<address>first.last@1xample.com</address> |
<valid>true</valid> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>19</id> |
</test> |
<test> |
<address>first.last@123.example.com</address> |
<valid>true</valid> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>20</id> |
</test> |
<test> |
<address>123456789012345678901234567890123456789012345678901234567890@12345678901234567890123456789012345678901234567890123456789.12345678901234567890123456789012345678901234567890123456789.12345678901234567890123456789012345678901234567890123456789.12.example.com</address> |
<valid>false</valid> |
<comment>Entire address is longer than 254 characters</comment> |
<source>RFC 3696 erratum 1690</source> |
<sourcelink>http://www.rfc-editor.org/errata_search.php?rfc=3696&eid=1690</sourcelink> |
<id>21</id> |
</test> |
<test> |
<address>first.last</address> |
<valid>false</valid> |
<comment>No @</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>22</id> |
</test> |
<test> |
<address>12345678901234567890123456789012345678901234567890123456789012345@example.com</address> |
<valid>false</valid> |
<comment>Local part more than 64 characters</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>23</id> |
</test> |
<test> |
<address>.first.last@example.com</address> |
<valid>false</valid> |
<comment>Local part starts with a dot</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>24</id> |
</test> |
<test> |
<address>first.last.@example.com</address> |
<valid>false</valid> |
<comment>Local part ends with a dot</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>25</id> |
</test> |
<test> |
<address>first..last@example.com</address> |
<valid>false</valid> |
<comment>Local part has consecutive dots</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>26</id> |
</test> |
<test> |
<address>"first"last"@example.com</address> |
<valid>false</valid> |
<comment>Local part contains unescaped excluded characters</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>27</id> |
</test> |
<test> |
<address>"first\last"@example.com</address> |
<valid>true</valid> |
<comment>Any character can be escaped in a quoted string</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>28</id> |
</test> |
<test> |
<address>"""@example.com</address> |
<valid>false</valid> |
<comment>Local part contains unescaped excluded characters</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>29</id> |
</test> |
<test> |
<address>"\"@example.com</address> |
<valid>false</valid> |
<comment>Local part cannot end with a backslash</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>30</id> |
</test> |
<test> |
<address>""@example.com</address> |
<valid>false</valid> |
<comment>Local part is effectively empty</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>31</id> |
</test> |
<test> |
<address>first\\@last@example.com</address> |
<valid>false</valid> |
<comment>Local part contains unescaped excluded characters</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>32</id> |
</test> |
<test> |
<address>first.last@</address> |
<valid>false</valid> |
<comment>No domain</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>33</id> |
</test> |
<test> |
<address>x@x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456789.x23456</address> |
<valid>false</valid> |
<comment>Domain exceeds 255 chars</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>34</id> |
</test> |
<test> |
<address>first.last@[.12.34.56.78]</address> |
<valid>false</valid> |
<comment>Only char that can precede IPv4 address is ':'</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>35</id> |
</test> |
<test> |
<address>first.last@[12.34.56.789]</address> |
<valid>false</valid> |
<comment>Can't be interpreted as IPv4 so IPv6 tag is missing</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>36</id> |
</test> |
<test> |
<address>first.last@[::12.34.56.78]</address> |
<valid>false</valid> |
<comment>IPv6 tag is missing</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>37</id> |
</test> |
<test> |
<address>first.last@[IPv5:::12.34.56.78]</address> |
<valid>false</valid> |
<comment>IPv6 tag is wrong</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>38</id> |
</test> |
<test> |
<address>first.last@[IPv6:1111:2222:3333::4444:5555:12.34.56.78]</address> |
<valid>false</valid> |
<comment>Too many IPv6 groups (4 max)</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>39</id> |
</test> |
<test> |
<address>first.last@[IPv6:1111:2222:3333:4444:5555:12.34.56.78]</address> |
<valid>false</valid> |
<comment>Not enough IPv6 groups</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>40</id> |
</test> |
<test> |
<address>first.last@[IPv6:1111:2222:3333:4444:5555:6666:7777:12.34.56.78]</address> |
<valid>false</valid> |
<comment>Too many IPv6 groups (6 max)</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>41</id> |
</test> |
<test> |
<address>first.last@[IPv6:1111:2222:3333:4444:5555:6666:7777]</address> |
<valid>false</valid> |
<comment>Not enough IPv6 groups</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>42</id> |
</test> |
<test> |
<address>first.last@[IPv6:1111:2222:3333:4444:5555:6666:7777:8888:9999]</address> |
<valid>false</valid> |
<comment>Too many IPv6 groups (8 max)</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>43</id> |
</test> |
<test> |
<address>first.last@[IPv6:1111:2222::3333::4444:5555:6666]</address> |
<valid>false</valid> |
<comment>Too many '::' (can be none or one)</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>44</id> |
</test> |
<test> |
<address>first.last@[IPv6:1111:2222:3333::4444:5555:6666:7777]</address> |
<valid>false</valid> |
<comment>Too many IPv6 groups (6 max)</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>45</id> |
</test> |
<test> |
<address>first.last@[IPv6:1111:2222:333x::4444:5555]</address> |
<valid>false</valid> |
<comment>x is not valid in an IPv6 address</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>46</id> |
</test> |
<test> |
<address>first.last@[IPv6:1111:2222:33333::4444:5555]</address> |
<valid>false</valid> |
<comment>33333 is not a valid group in an IPv6 address</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>47</id> |
</test> |
<test> |
<address>first.last@example.123</address> |
<valid>false</valid> |
<comment>TLD can't be all digits</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>48</id> |
</test> |
<test> |
<address>first.last@com</address> |
<valid>false</valid> |
<comment>Mail host must be second- or lower level</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>49</id> |
</test> |
<test> |
<address>first.last@-xample.com</address> |
<valid>false</valid> |
<comment>Label can't begin with a hyphen</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>50</id> |
</test> |
<test> |
<address>first.last@exampl-.com</address> |
<valid>false</valid> |
<comment>Label can't end with a hyphen</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>51</id> |
</test> |
<test> |
<address>first.last@x234567890123456789012345678901234567890123456789012345678901234.example.com</address> |
<valid>false</valid> |
<comment>Label can't be longer than 63 octets</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>52</id> |
</test> |
<test> |
<address>"Abc\@def"@example.com</address> |
<valid>true</valid> |
<source>RFC 3696 (February 2004)</source> |
<sourcelink>http://tools.ietf.org/html/rfc3696#section-3</sourcelink> |
<id>53</id> |
</test> |
<test> |
<address>"Fred\ Bloggs"@example.com</address> |
<valid>true</valid> |
<source>RFC 3696 (as amended by erratum 2005-07-09)</source> |
<sourcelink>http://www.rfc-editor.org/errata_search.php?rfc=3696&eid=246</sourcelink> |
<id>54</id> |
</test> |
<test> |
<address>"Joe.\\Blow"@example.com</address> |
<valid>true</valid> |
<source>RFC 3696 (as amended by erratum 2005-07-09)</source> |
<sourcelink>http://www.rfc-editor.org/errata_search.php?rfc=3696&eid=246</sourcelink> |
<id>55</id> |
</test> |
<test> |
<address>"Abc@def"@example.com</address> |
<valid>true</valid> |
<source>RFC 3696 (as amended by erratum 2005-07-09)</source> |
<sourcelink>http://www.rfc-editor.org/errata_search.php?rfc=3696&eid=246</sourcelink> |
<id>56</id> |
</test> |
<test> |
<address>"Fred Bloggs"@example.com</address> |
<valid>true</valid> |
<source>RFC 3696 (February 2004)</source> |
<sourcelink>http://tools.ietf.org/html/rfc3696#section-3</sourcelink> |
<id>57</id> |
</test> |
<test> |
<address>user+mailbox@example.com</address> |
<valid>true</valid> |
<source>RFC 3696 (February 2004)</source> |
<sourcelink>http://tools.ietf.org/html/rfc3696#section-3</sourcelink> |
<id>58</id> |
</test> |
<test> |
<address>customer/department=shipping@example.com</address> |
<valid>true</valid> |
<source>RFC 3696 (February 2004)</source> |
<sourcelink>http://tools.ietf.org/html/rfc3696#section-3</sourcelink> |
<id>59</id> |
</test> |
<test> |
<address>$A12345@example.com</address> |
<valid>true</valid> |
<source>RFC 3696 (February 2004)</source> |
<sourcelink>http://tools.ietf.org/html/rfc3696#section-3</sourcelink> |
<id>60</id> |
</test> |
<test> |
<address>!def!xyz%abc@example.com</address> |
<valid>true</valid> |
<source>RFC 3696 (February 2004)</source> |
<sourcelink>http://tools.ietf.org/html/rfc3696#section-3</sourcelink> |
<id>61</id> |
</test> |
<test> |
<address>_somename@example.com</address> |
<valid>true</valid> |
<source>RFC 3696 (February 2004)</source> |
<sourcelink>http://tools.ietf.org/html/rfc3696#section-3</sourcelink> |
<id>62</id> |
</test> |
<test> |
<address>dclo@us.ibm.com</address> |
<valid>true</valid> |
<source>Doug Lovell (LinuxJournal, June 2007)</source> |
<sourcelink>http://www.linuxjournal.com/article/9585</sourcelink> |
<id>63</id> |
</test> |
<test> |
<address>abc\@def@example.com</address> |
<valid>false</valid> |
<comment>This example from RFC 3696 was corrected in an erratum</comment> |
<source>Doug Lovell (LinuxJournal, June 2007)</source> |
<sourcelink>http://www.linuxjournal.com/article/9585</sourcelink> |
<id>64</id> |
</test> |
<test> |
<address>abc\\@example.com</address> |
<valid>false</valid> |
<comment>This example from RFC 3696 was corrected in an erratum</comment> |
<source>Doug Lovell (LinuxJournal, June 2007)</source> |
<sourcelink>http://www.linuxjournal.com/article/9585</sourcelink> |
<id>65</id> |
</test> |
<test> |
<address>peter.piper@example.com</address> |
<valid>true</valid> |
<source>Doug Lovell (LinuxJournal, June 2007)</source> |
<sourcelink>http://www.linuxjournal.com/article/9585</sourcelink> |
<id>66</id> |
</test> |
<test> |
<address>Doug\ \"Ace\"\ Lovell@example.com</address> |
<valid>false</valid> |
<comment>Escaping can only happen in a quoted string</comment> |
<source>Doug Lovell (LinuxJournal, June 2007)</source> |
<sourcelink>http://www.linuxjournal.com/article/9585</sourcelink> |
<id>67</id> |
</test> |
<test> |
<address>"Doug \"Ace\" L."@example.com</address> |
<valid>true</valid> |
<source>Doug Lovell (LinuxJournal, June 2007)</source> |
<sourcelink>http://www.linuxjournal.com/article/9585</sourcelink> |
<id>68</id> |
</test> |
<test> |
<address>abc@def@example.com</address> |
<valid>false</valid> |
<comment>Doug Lovell says this should fail</comment> |
<source>Doug Lovell (LinuxJournal, June 2007)</source> |
<sourcelink>http://www.linuxjournal.com/article/9585</sourcelink> |
<id>69</id> |
</test> |
<test> |
<address>abc\\@def@example.com</address> |
<valid>false</valid> |
<comment>Doug Lovell says this should fail</comment> |
<source>Doug Lovell (LinuxJournal, June 2007)</source> |
<sourcelink>http://www.linuxjournal.com/article/9585</sourcelink> |
<id>70</id> |
</test> |
<test> |
<address>abc\@example.com</address> |
<valid>false</valid> |
<comment>Doug Lovell says this should fail</comment> |
<source>Doug Lovell (LinuxJournal, June 2007)</source> |
<sourcelink>http://www.linuxjournal.com/article/9585</sourcelink> |
<id>71</id> |
</test> |
<test> |
<address>@example.com</address> |
<valid>false</valid> |
<comment>No local part</comment> |
<source>Doug Lovell (LinuxJournal, June 2007)</source> |
<sourcelink>http://www.linuxjournal.com/article/9585</sourcelink> |
<id>72</id> |
</test> |
<test> |
<address>doug@</address> |
<valid>false</valid> |
<comment>Doug Lovell says this should fail</comment> |
<source>Doug Lovell (LinuxJournal, June 2007)</source> |
<sourcelink>http://www.linuxjournal.com/article/9585</sourcelink> |
<id>73</id> |
</test> |
<test> |
<address>"qu@example.com</address> |
<valid>false</valid> |
<comment>Doug Lovell says this should fail</comment> |
<source>Doug Lovell (LinuxJournal, June 2007)</source> |
<sourcelink>http://www.linuxjournal.com/article/9585</sourcelink> |
<id>74</id> |
</test> |
<test> |
<address>ote"@example.com</address> |
<valid>false</valid> |
<comment>Doug Lovell says this should fail</comment> |
<source>Doug Lovell (LinuxJournal, June 2007)</source> |
<sourcelink>http://www.linuxjournal.com/article/9585</sourcelink> |
<id>75</id> |
</test> |
<test> |
<address>.dot@example.com</address> |
<valid>false</valid> |
<comment>Doug Lovell says this should fail</comment> |
<source>Doug Lovell (LinuxJournal, June 2007)</source> |
<sourcelink>http://www.linuxjournal.com/article/9585</sourcelink> |
<id>76</id> |
</test> |
<test> |
<address>dot.@example.com</address> |
<valid>false</valid> |
<comment>Doug Lovell says this should fail</comment> |
<source>Doug Lovell (LinuxJournal, June 2007)</source> |
<sourcelink>http://www.linuxjournal.com/article/9585</sourcelink> |
<id>77</id> |
</test> |
<test> |
<address>two..dot@example.com</address> |
<valid>false</valid> |
<comment>Doug Lovell says this should fail</comment> |
<source>Doug Lovell (LinuxJournal, June 2007)</source> |
<sourcelink>http://www.linuxjournal.com/article/9585</sourcelink> |
<id>78</id> |
</test> |
<test> |
<address>"Doug "Ace" L."@example.com</address> |
<valid>false</valid> |
<comment>Doug Lovell says this should fail</comment> |
<source>Doug Lovell (LinuxJournal, June 2007)</source> |
<sourcelink>http://www.linuxjournal.com/article/9585</sourcelink> |
<id>79</id> |
</test> |
<test> |
<address>Doug\ \"Ace\"\ L\.@example.com</address> |
<valid>false</valid> |
<comment>Doug Lovell says this should fail</comment> |
<source>Doug Lovell (LinuxJournal, June 2007)</source> |
<sourcelink>http://www.linuxjournal.com/article/9585</sourcelink> |
<id>80</id> |
</test> |
<test> |
<address>hello world@example.com</address> |
<valid>false</valid> |
<comment>Doug Lovell says this should fail</comment> |
<source>Doug Lovell (LinuxJournal, June 2007)</source> |
<sourcelink>http://www.linuxjournal.com/article/9585</sourcelink> |
<id>81</id> |
</test> |
<test> |
<address>gatsby@f.sc.ot.t.f.i.tzg.era.l.d.</address> |
<valid>false</valid> |
<comment>Doug Lovell says this should fail</comment> |
<source>Doug Lovell (LinuxJournal, June 2007)</source> |
<sourcelink>http://www.linuxjournal.com/article/9585</sourcelink> |
<id>82</id> |
</test> |
<test> |
<valid>true</valid> |
<address>test@example.com</address> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>83</id> |
</test> |
<test> |
<valid>true</valid> |
<address>TEST@example.com</address> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>84</id> |
</test> |
<test> |
<valid>true</valid> |
<address>1234567890@example.com</address> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>85</id> |
</test> |
<test> |
<valid>true</valid> |
<address>test+test@example.com</address> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>86</id> |
</test> |
<test> |
<valid>true</valid> |
<address>test-test@example.com</address> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>87</id> |
</test> |
<test> |
<valid>true</valid> |
<address>t*est@example.com</address> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>88</id> |
</test> |
<test> |
<valid>true</valid> |
<address>+1~1+@example.com</address> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>89</id> |
</test> |
<test> |
<valid>true</valid> |
<address>{_test_}@example.com</address> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>90</id> |
</test> |
<test> |
<valid>true</valid> |
<address>"[[ test ]]"@example.com</address> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>91</id> |
</test> |
<test> |
<valid>true</valid> |
<address>test.test@example.com</address> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>92</id> |
</test> |
<test> |
<valid>true</valid> |
<address>"test.test"@example.com</address> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>93</id> |
</test> |
<test> |
<valid>true</valid> |
<address>test."test"@example.com</address> |
<comment>Obsolete form, but documented in RFC 5322</comment> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>94</id> |
</test> |
<test> |
<valid>true</valid> |
<address>"test@test"@example.com</address> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>95</id> |
</test> |
<test> |
<valid>true</valid> |
<address>test@123.123.123.x123</address> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>96</id> |
</test> |
<test> |
<valid>false</valid> |
<address>test@123.123.123.123</address> |
<comment>Top Level Domain won't be all-numeric (see RFC 3696 Section 2). I disagree with Dave Child on this one.</comment> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>97</id> |
</test> |
<test> |
<valid>true</valid> |
<address>test@[123.123.123.123]</address> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>98</id> |
</test> |
<test> |
<valid>true</valid> |
<address>test@example.example.com</address> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>99</id> |
</test> |
<test> |
<valid>true</valid> |
<address>test@example.example.example.com</address> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>100</id> |
</test> |
<test> |
<valid>false</valid> |
<address>test.example.com</address> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>101</id> |
</test> |
<test> |
<valid>false</valid> |
<address>test.@example.com</address> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>102</id> |
</test> |
<test> |
<valid>false</valid> |
<address>test..test@example.com</address> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>103</id> |
</test> |
<test> |
<valid>false</valid> |
<address>.test@example.com</address> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>104</id> |
</test> |
<test> |
<valid>false</valid> |
<address>test@test@example.com</address> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>105</id> |
</test> |
<test> |
<valid>false</valid> |
<address>test@@example.com</address> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>106</id> |
</test> |
<test> |
<valid>false</valid> |
<address>-- test --@example.com</address> |
<comment>No spaces allowed in local part</comment> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>107</id> |
</test> |
<test> |
<valid>false</valid> |
<address>[test]@example.com</address> |
<comment>Square brackets only allowed within quotes</comment> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>108</id> |
</test> |
<test> |
<valid>true</valid> |
<address>"test\test"@example.com</address> |
<comment>Any character can be escaped in a quoted string</comment> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>109</id> |
</test> |
<test> |
<valid>false</valid> |
<address>"test"test"@example.com</address> |
<comment>Quotes cannot be nested</comment> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>110</id> |
</test> |
<test> |
<valid>false</valid> |
<address>()[]\;:,><@example.com</address> |
<comment>Disallowed Characters</comment> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>111</id> |
</test> |
<test> |
<valid>false</valid> |
<comment>Dave Child says so</comment> |
<address>test@.</address> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>112</id> |
</test> |
<test> |
<valid>false</valid> |
<comment>Dave Child says so</comment> |
<address>test@example.</address> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>113</id> |
</test> |
<test> |
<valid>false</valid> |
<comment>Dave Child says so</comment> |
<address>test@.org</address> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>114</id> |
</test> |
<test> |
<valid>false</valid> |
<address>test@123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012.com</address> |
<comment>255 characters is maximum length for domain. This is 256.</comment> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>115</id> |
</test> |
<test> |
<valid>false</valid> |
<comment>Dave Child says so</comment> |
<address>test@example</address> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>116</id> |
</test> |
<test> |
<valid>false</valid> |
<comment>Dave Child says so</comment> |
<address>test@[123.123.123.123</address> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>117</id> |
</test> |
<test> |
<valid>false</valid> |
<comment>Dave Child says so</comment> |
<address>test@123.123.123.123]</address> |
<source>Dave Child</source> |
<sourcelink>http://code.google.com/p/php-email-address-validation/</sourcelink> |
<id>118</id> |
</test> |
<test> |
<address>NotAnEmail</address> |
<valid>false</valid> |
<comment>Phil Haack says so</comment> |
<source>Phil Haack</source> |
<sourcelink>http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx</sourcelink> |
<id>119</id> |
</test> |
<test> |
<address>@NotAnEmail</address> |
<valid>false</valid> |
<comment>Phil Haack says so</comment> |
<source>Phil Haack</source> |
<sourcelink>http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx</sourcelink> |
<id>120</id> |
</test> |
<test> |
<address>"test\\blah"@example.com</address> |
<valid>true</valid> |
<source>Phil Haack</source> |
<sourcelink>http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx</sourcelink> |
<id>121</id> |
</test> |
<test> |
<address>"test\blah"@example.com</address> |
<valid>true</valid> |
<comment>Any character can be escaped in a quoted string</comment> |
<source>Phil Haack</source> |
<sourcelink>http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx</sourcelink> |
<id>122</id> |
</test> |
<test> |
<address>"test\ blah"@example.com</address> |
<valid>true</valid> |
<comment>Quoted string specifically excludes carriage returns unless escaped</comment> |
<source>Phil Haack</source> |
<sourcelink>http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx</sourcelink> |
<id>123</id> |
</test> |
<test> |
<address>"test blah"@example.com</address> |
<valid>false</valid> |
<comment>Quoted string specifically excludes carriage returns</comment> |
<source>Phil Haack</source> |
<sourcelink>http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx</sourcelink> |
<id>124</id> |
</test> |
<test> |
<address>"test\"blah"@example.com</address> |
<valid>true</valid> |
<source>Phil Haack</source> |
<sourcelink>http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx</sourcelink> |
<id>125</id> |
</test> |
<test> |
<address>"test"blah"@example.com</address> |
<valid>false</valid> |
<comment>Phil Haack says so</comment> |
<source>Phil Haack</source> |
<sourcelink>http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx</sourcelink> |
<id>126</id> |
</test> |
<test> |
<address>customer/department@example.com</address> |
<valid>true</valid> |
<source>Phil Haack</source> |
<sourcelink>http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx</sourcelink> |
<id>127</id> |
</test> |
<test> |
<address>_Yosemite.Sam@example.com</address> |
<valid>true</valid> |
<source>Phil Haack</source> |
<sourcelink>http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx</sourcelink> |
<id>128</id> |
</test> |
<test> |
<address>~@example.com</address> |
<valid>true</valid> |
<source>Phil Haack</source> |
<sourcelink>http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx</sourcelink> |
<id>129</id> |
</test> |
<test> |
<address>.wooly@example.com</address> |
<valid>false</valid> |
<comment>Phil Haack says so</comment> |
<source>Phil Haack</source> |
<sourcelink>http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx</sourcelink> |
<id>130</id> |
</test> |
<test> |
<address>wo..oly@example.com</address> |
<valid>false</valid> |
<comment>Phil Haack says so</comment> |
<source>Phil Haack</source> |
<sourcelink>http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx</sourcelink> |
<id>131</id> |
</test> |
<test> |
<address>pootietang.@example.com</address> |
<valid>false</valid> |
<comment>Phil Haack says so</comment> |
<source>Phil Haack</source> |
<sourcelink>http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx</sourcelink> |
<id>132</id> |
</test> |
<test> |
<address>.@example.com</address> |
<valid>false</valid> |
<comment>Phil Haack says so</comment> |
<source>Phil Haack</source> |
<sourcelink>http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx</sourcelink> |
<id>133</id> |
</test> |
<test> |
<address>"Austin@Powers"@example.com</address> |
<valid>true</valid> |
<source>Phil Haack</source> |
<sourcelink>http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx</sourcelink> |
<id>134</id> |
</test> |
<test> |
<address>Ima.Fool@example.com</address> |
<valid>true</valid> |
<source>Phil Haack</source> |
<sourcelink>http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx</sourcelink> |
<id>135</id> |
</test> |
<test> |
<address>"Ima.Fool"@example.com</address> |
<valid>true</valid> |
<source>Phil Haack</source> |
<sourcelink>http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx</sourcelink> |
<id>136</id> |
</test> |
<test> |
<address>"Ima Fool"@example.com</address> |
<valid>true</valid> |
<source>Phil Haack</source> |
<sourcelink>http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx</sourcelink> |
<id>137</id> |
</test> |
<test> |
<address>Ima Fool@example.com</address> |
<valid>false</valid> |
<comment>Phil Haack says so</comment> |
<source>Phil Haack</source> |
<sourcelink>http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx</sourcelink> |
<id>138</id> |
</test> |
<test> |
<address>phil.h\@\@ck@haacked.com</address> |
<valid>false</valid> |
<comment>Escaping can only happen in a quoted string</comment> |
<source>Phil Haack</source> |
<sourcelink>http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx</sourcelink> |
<id>139</id> |
</test> |
<test> |
<address>"first"."last"@example.com</address> |
<valid>true</valid> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>140</id> |
</test> |
<test> |
<address>"first".middle."last"@example.com</address> |
<valid>true</valid> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>141</id> |
</test> |
<test> |
<address>"first\\"last"@example.com</address> |
<valid>false</valid> |
<comment>Contains an unescaped quote</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>142</id> |
</test> |
<test> |
<address>"first".last@example.com</address> |
<valid>true</valid> |
<comment>obs-local-part form as described in RFC 5322</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>143</id> |
</test> |
<test> |
<address>first."last"@example.com</address> |
<valid>true</valid> |
<comment>obs-local-part form as described in RFC 5322</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>144</id> |
</test> |
<test> |
<address>"first"."middle"."last"@example.com</address> |
<valid>true</valid> |
<comment>obs-local-part form as described in RFC 5322</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>145</id> |
</test> |
<test> |
<address>"first.middle"."last"@example.com</address> |
<valid>true</valid> |
<comment>obs-local-part form as described in RFC 5322</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>146</id> |
</test> |
<test> |
<address>"first.middle.last"@example.com</address> |
<valid>true</valid> |
<comment>obs-local-part form as described in RFC 5322</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>147</id> |
</test> |
<test> |
<address>"first..last"@example.com</address> |
<valid>true</valid> |
<comment>obs-local-part form as described in RFC 5322</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>148</id> |
</test> |
<test> |
<address>foo@[\1.2.3.4]</address> |
<valid>false</valid> |
<comment>RFC 5321 specifies the syntax for address-literal and does not allow escaping</comment> |
<source>Cal Henderson</source> |
<sourcelink>http://code.iamcal.com/php/rfc822/</sourcelink> |
<id>149</id> |
</test> |
<test> |
<address>"first\\\"last"@example.com</address> |
<valid>true</valid> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>150</id> |
</test> |
<test> |
<address>first."mid\dle"."last"@example.com</address> |
<valid>true</valid> |
<comment>Backslash can escape anything but must escape something</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>151</id> |
</test> |
<test> |
<address>Test. Folding. Whitespace@example.com</address> |
<valid>true</valid> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>152</id> |
</test> |
<test> |
<address>first."".last@example.com</address> |
<valid>false</valid> |
<comment>Contains a zero-length element</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>153</id> |
</test> |
<test> |
<address>first\last@example.com</address> |
<valid>false</valid> |
<comment>Unquoted string must be an atom</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>154</id> |
</test> |
<test> |
<address>Abc\@def@example.com</address> |
<valid>false</valid> |
<comment>Was incorrectly given as a valid address in the original RFC 3696</comment> |
<source>RFC 3696 erratum 246</source> |
<sourcelink>http://www.rfc-editor.org/errata_search.php?rfc=3696&eid=246</sourcelink> |
<id>155</id> |
</test> |
<test> |
<address>Fred\ Bloggs@example.com</address> |
<valid>false</valid> |
<comment>Was incorrectly given as a valid address in the original RFC 3696</comment> |
<source>RFC 3696 erratum 246</source> |
<sourcelink>http://www.rfc-editor.org/errata_search.php?rfc=3696&eid=246</sourcelink> |
<id>156</id> |
</test> |
<test> |
<address>Joe.\\Blow@example.com</address> |
<valid>false</valid> |
<comment>Was incorrectly given as a valid address in the original RFC 3696</comment> |
<source>RFC 3696 erratum 246</source> |
<sourcelink>http://www.rfc-editor.org/errata_search.php?rfc=3696&eid=246</sourcelink> |
<id>157</id> |
</test> |
<test> |
<address>first.last@[IPv6:1111:2222:3333:4444:5555:6666:12.34.567.89]</address> |
<valid>false</valid> |
<comment>IPv4 part contains an invalid octet</comment> |
<source>Cal Henderson</source> |
<sourcelink>http://code.iamcal.com/php/rfc822/</sourcelink> |
<id>158</id> |
</test> |
<test> |
<address>"test\ blah"@example.com</address> |
<valid>false</valid> |
<comment>Folding white space can't appear within a quoted pair</comment> |
<source>Cal Henderson</source> |
<sourcelink>http://code.iamcal.com/php/rfc822/</sourcelink> |
<id>159</id> |
</test> |
<test> |
<address>"test blah"@example.com</address> |
<valid>true</valid> |
<comment>This is a valid quoted string with folding white space</comment> |
<source>Phil Haack</source> |
<sourcelink>http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx</sourcelink> |
<id>160</id> |
</test> |
<test> |
<address>{^c\@**Dog^}@cartoon.com</address> |
<valid>false</valid> |
<comment>This is a throwaway example from Doug Lovell's article. Actually it's not a valid address.</comment> |
<source>Doug Lovell (LinuxJournal, June 2007)</source> |
<sourcelink>http://www.linuxjournal.com/article/9585</sourcelink> |
<id>161</id> |
</test> |
<test> |
<address>(foo)cal(bar)@(baz)iamcal.com(quux)</address> |
<valid>true</valid> |
<comment>A valid address containing comments</comment> |
<source>Cal Henderson</source> |
<sourcelink>http://code.iamcal.com/php/rfc822/</sourcelink> |
<id>162</id> |
</test> |
<test> |
<address>cal@iamcal(woo).(yay)com</address> |
<valid>true</valid> |
<comment>A valid address containing comments</comment> |
<source>Cal Henderson</source> |
<sourcelink>http://code.iamcal.com/php/rfc822/</sourcelink> |
<id>163</id> |
</test> |
<test> |
<address>"foo"(yay)@(hoopla)[1.2.3.4]</address> |
<valid>false</valid> |
<comment>Address literal can't be commented (RFC 5321)</comment> |
<source>Cal Henderson</source> |
<sourcelink>http://code.iamcal.com/php/rfc822/</sourcelink> |
<id>164</id> |
</test> |
<test> |
<address>cal(woo(yay)hoopla)@iamcal.com</address> |
<valid>true</valid> |
<comment>A valid address containing comments</comment> |
<source>Cal Henderson</source> |
<sourcelink>http://code.iamcal.com/php/rfc822/</sourcelink> |
<id>165</id> |
</test> |
<test> |
<address>cal(foo\@bar)@iamcal.com</address> |
<valid>true</valid> |
<comment>A valid address containing comments</comment> |
<source>Cal Henderson</source> |
<sourcelink>http://code.iamcal.com/php/rfc822/</sourcelink> |
<id>166</id> |
</test> |
<test> |
<address>cal(foo\)bar)@iamcal.com</address> |
<valid>true</valid> |
<comment>A valid address containing comments and an escaped parenthesis</comment> |
<source>Cal Henderson</source> |
<sourcelink>http://code.iamcal.com/php/rfc822/</sourcelink> |
<id>167</id> |
</test> |
<test> |
<address>cal(foo(bar)@iamcal.com</address> |
<valid>false</valid> |
<comment>Unclosed parenthesis in comment</comment> |
<source>Cal Henderson</source> |
<sourcelink>http://code.iamcal.com/php/rfc822/</sourcelink> |
<id>168</id> |
</test> |
<test> |
<address>cal(foo)bar)@iamcal.com</address> |
<valid>false</valid> |
<comment>Too many closing parentheses</comment> |
<source>Cal Henderson</source> |
<sourcelink>http://code.iamcal.com/php/rfc822/</sourcelink> |
<id>169</id> |
</test> |
<test> |
<address>cal(foo\)@iamcal.com</address> |
<valid>false</valid> |
<comment>Backslash at end of comment has nothing to escape</comment> |
<source>Cal Henderson</source> |
<sourcelink>http://code.iamcal.com/php/rfc822/</sourcelink> |
<id>170</id> |
</test> |
<test> |
<address>first().last@example.com</address> |
<valid>true</valid> |
<comment>A valid address containing an empty comment</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>171</id> |
</test> |
<test> |
<address>first.( middle )last@example.com</address> |
<valid>true</valid> |
<comment>Comment with folding white space</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>172</id> |
</test> |
<test> |
<address>first(12345678901234567890123456789012345678901234567890)last@(1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890)example.com</address> |
<valid>false</valid> |
<comment>Too long with comments, not too long without</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>173</id> |
</test> |
<test> |
<address>first(Welcome to the ("wonderful" (!)) world of email)@example.com</address> |
<valid>true</valid> |
<comment>Silly example from my blog post</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>174</id> |
</test> |
<test> |
<address>pete(his account)@silly.test(his host)</address> |
<valid>true</valid> |
<comment>Canonical example from RFC 5322</comment> |
<source>RFC 5322</source> |
<sourcelink>http://tools.ietf.org/html/rfc5322</sourcelink> |
<id>175</id> |
</test> |
<test> |
<address>c@(Chris's host.)public.example</address> |
<valid>true</valid> |
<comment>Canonical example from RFC 5322</comment> |
<source>RFC 5322</source> |
<sourcelink>http://tools.ietf.org/html/rfc5322</sourcelink> |
<id>176</id> |
</test> |
<test> |
<address>jdoe@machine(comment). example</address> |
<valid>true</valid> |
<comment>Canonical example from RFC 5322</comment> |
<source>RFC 5322</source> |
<sourcelink>http://tools.ietf.org/html/rfc5322</sourcelink> |
<id>177</id> |
</test> |
<test> |
<address>1234 @ local(blah) .machine .example</address> |
<valid>true</valid> |
<comment>Canonical example from RFC 5322</comment> |
<source>RFC 5322</source> |
<sourcelink>http://tools.ietf.org/html/rfc5322</sourcelink> |
<id>178</id> |
</test> |
<test> |
<address>first(middle)last@example.com</address> |
<valid>false</valid> |
<comment>Can't have a comment or white space except at an element boundary</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>179</id> |
</test> |
<test> |
<address>first(abc.def).last@example.com</address> |
<valid>true</valid> |
<comment>Comment can contain a dot</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>180</id> |
</test> |
<test> |
<address>first(a"bc.def).last@example.com</address> |
<valid>true</valid> |
<comment>Comment can contain double quote</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>181</id> |
</test> |
<test> |
<address>first.(")middle.last(")@example.com</address> |
<valid>true</valid> |
<comment>Comment can contain a quote</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>182</id> |
</test> |
<test> |
<address>first(abc("def".ghi).mno)middle(abc("def".ghi).mno).last@(abc("def".ghi).mno)example(abc("def".ghi).mno).(abc("def".ghi).mno)com(abc("def".ghi).mno)</address> |
<valid>false</valid> |
<comment>Can't have comments or white space except at an element boundary</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>183</id> |
</test> |
<test> |
<address>first(abc\(def)@example.com</address> |
<valid>true</valid> |
<comment>Comment can contain quoted-pair</comment> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>184</id> |
</test> |
<test> |
<address>first.last@x(1234567890123456789012345678901234567890123456789012345678901234567890).com</address> |
<valid>true</valid> |
<comment>Label is longer than 63 octets, but not with comment removed</comment> |
<source>Cal Henderson</source> |
<sourcelink>http://code.iamcal.com/php/rfc822/</sourcelink> |
<id>185</id> |
</test> |
<test> |
<address>a(a(b(c)d(e(f))g)h(i)j)@example.com</address> |
<valid>true</valid> |
<source>Cal Henderson</source> |
<sourcelink>http://code.iamcal.com/php/rfc822/</sourcelink> |
<id>186</id> |
</test> |
<test> |
<address>a(a(b(c)d(e(f))g)(h(i)j)@example.com</address> |
<valid>false</valid> |
<comment>Braces are not properly matched</comment> |
<source>Cal Henderson</source> |
<sourcelink>http://code.iamcal.com/php/rfc822/</sourcelink> |
<id>187</id> |
</test> |
<test> |
<address>name.lastname@domain.com</address> |
<valid>true</valid> |
<source>Paul Gregg</source> |
<sourcelink>http://pgregg.com/projects/php/code/showvalidemail.php</sourcelink> |
<id>188</id> |
</test> |
<test> |
<address>.@</address> |
<valid>false</valid> |
<source>Paul Gregg</source> |
<sourcelink>http://pgregg.com/projects/php/code/showvalidemail.php</sourcelink> |
<id>189</id> |
</test> |
<test> |
<address>a@b</address> |
<valid>false</valid> |
<source>Paul Gregg</source> |
<sourcelink>http://pgregg.com/projects/php/code/showvalidemail.php</sourcelink> |
<id>190</id> |
</test> |
<test> |
<address>@bar.com</address> |
<valid>false</valid> |
<source>Paul Gregg</source> |
<sourcelink>http://pgregg.com/projects/php/code/showvalidemail.php</sourcelink> |
<id>191</id> |
</test> |
<test> |
<address>@@bar.com</address> |
<valid>false</valid> |
<source>Paul Gregg</source> |
<sourcelink>http://pgregg.com/projects/php/code/showvalidemail.php</sourcelink> |
<id>192</id> |
</test> |
<test> |
<address>a@bar.com</address> |
<valid>true</valid> |
<source>Paul Gregg</source> |
<sourcelink>http://pgregg.com/projects/php/code/showvalidemail.php</sourcelink> |
<id>193</id> |
</test> |
<test> |
<address>aaa.com</address> |
<valid>false</valid> |
<source>Paul Gregg</source> |
<sourcelink>http://pgregg.com/projects/php/code/showvalidemail.php</sourcelink> |
<id>194</id> |
</test> |
<test> |
<address>aaa@.com</address> |
<valid>false</valid> |
<source>Paul Gregg</source> |
<sourcelink>http://pgregg.com/projects/php/code/showvalidemail.php</sourcelink> |
<id>195</id> |
</test> |
<test> |
<address>aaa@.123</address> |
<valid>false</valid> |
<source>Paul Gregg</source> |
<sourcelink>http://pgregg.com/projects/php/code/showvalidemail.php</sourcelink> |
<id>196</id> |
</test> |
<test> |
<address>aaa@[123.123.123.123]</address> |
<valid>true</valid> |
<source>Paul Gregg</source> |
<sourcelink>http://pgregg.com/projects/php/code/showvalidemail.php</sourcelink> |
<id>197</id> |
</test> |
<test> |
<address>aaa@[123.123.123.123]a</address> |
<valid>false</valid> |
<comment>extra data outside ip</comment> |
<source>Paul Gregg</source> |
<sourcelink>http://pgregg.com/projects/php/code/showvalidemail.php</sourcelink> |
<id>198</id> |
</test> |
<test> |
<address>aaa@[123.123.123.333]</address> |
<valid>false</valid> |
<comment>not a valid IP</comment> |
<source>Paul Gregg</source> |
<sourcelink>http://pgregg.com/projects/php/code/showvalidemail.php</sourcelink> |
<id>199</id> |
</test> |
<test> |
<address>a@bar.com.</address> |
<valid>false</valid> |
<source>Paul Gregg</source> |
<sourcelink>http://pgregg.com/projects/php/code/showvalidemail.php</sourcelink> |
<id>200</id> |
</test> |
<test> |
<address>a@bar</address> |
<valid>false</valid> |
<source>Paul Gregg</source> |
<sourcelink>http://pgregg.com/projects/php/code/showvalidemail.php</sourcelink> |
<id>201</id> |
</test> |
<test> |
<address>a-b@bar.com</address> |
<valid>true</valid> |
<source>Paul Gregg</source> |
<sourcelink>http://pgregg.com/projects/php/code/showvalidemail.php</sourcelink> |
<id>202</id> |
</test> |
<test> |
<address>+@b.c</address> |
<valid>true</valid> |
<comment>TLDs can be any length</comment> |
<source>Paul Gregg</source> |
<sourcelink>http://pgregg.com/projects/php/code/showvalidemail.php</sourcelink> |
<id>203</id> |
</test> |
<test> |
<address>+@b.com</address> |
<valid>true</valid> |
<source>Paul Gregg</source> |
<sourcelink>http://pgregg.com/projects/php/code/showvalidemail.php</sourcelink> |
<id>204</id> |
</test> |
<test> |
<address>a@-b.com</address> |
<valid>false</valid> |
<source>Paul Gregg</source> |
<sourcelink>http://pgregg.com/projects/php/code/showvalidemail.php</sourcelink> |
<id>205</id> |
</test> |
<test> |
<address>a@b-.com</address> |
<valid>false</valid> |
<source>Paul Gregg</source> |
<sourcelink>http://pgregg.com/projects/php/code/showvalidemail.php</sourcelink> |
<id>206</id> |
</test> |
<test> |
<address>-@..com</address> |
<valid>false</valid> |
<source>Paul Gregg</source> |
<sourcelink>http://pgregg.com/projects/php/code/showvalidemail.php</sourcelink> |
<id>207</id> |
</test> |
<test> |
<address>-@a..com</address> |
<valid>false</valid> |
<source>Paul Gregg</source> |
<sourcelink>http://pgregg.com/projects/php/code/showvalidemail.php</sourcelink> |
<id>208</id> |
</test> |
<test> |
<address>a@b.co-foo.uk</address> |
<valid>true</valid> |
<source>Paul Gregg</source> |
<sourcelink>http://pgregg.com/projects/php/code/showvalidemail.php</sourcelink> |
<id>209</id> |
</test> |
<test> |
<address>"hello my name is"@stutter.com</address> |
<valid>true</valid> |
<source>Paul Gregg</source> |
<sourcelink>http://pgregg.com/projects/php/code/showvalidemail.php</sourcelink> |
<id>210</id> |
</test> |
<test> |
<address>"Test \"Fail\" Ing"@example.com</address> |
<valid>true</valid> |
<source>Paul Gregg</source> |
<sourcelink>http://pgregg.com/projects/php/code/showvalidemail.php</sourcelink> |
<id>211</id> |
</test> |
<test> |
<address>valid@special.museum</address> |
<valid>true</valid> |
<source>Paul Gregg</source> |
<sourcelink>http://pgregg.com/projects/php/code/showvalidemail.php</sourcelink> |
<id>212</id> |
</test> |
<test> |
<address>invalid@special.museum-</address> |
<valid>false</valid> |
<source>Paul Gregg</source> |
<sourcelink>http://pgregg.com/projects/php/code/showvalidemail.php</sourcelink> |
<id>213</id> |
</test> |
<test> |
<address>shaitan@my-domain.thisisminekthx</address> |
<valid>true</valid> |
<comment>Disagree with Paul Gregg here</comment> |
<source>Paul Gregg</source> |
<sourcelink>http://pgregg.com/projects/php/code/showvalidemail.php</sourcelink> |
<id>214</id> |
</test> |
<test> |
<address>test@...........com</address> |
<valid>false</valid> |
<comment>......</comment> |
<source>Paul Gregg</source> |
<sourcelink>http://pgregg.com/projects/php/code/showvalidemail.php</sourcelink> |
<id>215</id> |
</test> |
<test> |
<address>foobar@192.168.0.1</address> |
<valid>false</valid> |
<comment>ip need to be []</comment> |
<source>Paul Gregg</source> |
<sourcelink>http://pgregg.com/projects/php/code/showvalidemail.php</sourcelink> |
<id>216</id> |
</test> |
<test> |
<address>"Joe\\Blow"@example.com</address> |
<valid>true</valid> |
<source>Paul Gregg</source> |
<sourcelink>http://pgregg.com/projects/php/code/showvalidemail.php</sourcelink> |
<id>217</id> |
</test> |
<test> |
<address>Invalid \ Folding \ Whitespace@example.com</address> |
<valid>false</valid> |
<source>Paul Gregg</source> |
<comment>This isn't FWS so Dominic Sayers says it's invalid</comment> |
<sourcelink>http://pgregg.com/projects/php/code/showvalidemail.php</sourcelink> |
<id>218</id> |
</test> |
<test> |
<address>HM2Kinsists@(that comments are allowed)this.is.ok</address> |
<valid>true</valid> |
<source>Paul Gregg</source> |
<sourcelink>http://pgregg.com/projects/php/code/showvalidemail.php</sourcelink> |
<id>219</id> |
</test> |
<test> |
<address>user%uucp!path@somehost.edu</address> |
<valid>true</valid> |
<source>Paul Gregg</source> |
<sourcelink>http://pgregg.com/projects/php/code/showvalidemail.php</sourcelink> |
<id>220</id> |
</test> |
<test> |
<address>"first(last)"@example.com</address> |
<valid>true</valid> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>221</id> |
</test> |
<test> |
<address> ( x ) first ( x ) . ( x) last ( x ) @example.com</address> |
<valid>true</valid> |
<source>Dominic Sayers</source> |
<sourcelink>http://www.dominicsayers.com/isemail</sourcelink> |
<id>222</id> |
</test> |
<test> |
<address>test. obs@syntax.com</address> |
<valid>true</valid> |
<comment>obs-fws allows multiple lines</comment> |
<source>George Pollard</source> |
<sourcelink>http://porg.es/blog/properly-validating-e-mail-addresses</sourcelink> |
<id>223</id> |
</test> |
<test> |
<address>test. obs@syntax.com</address> |
<valid>true</valid> |
<comment>obs-fws allows multiple lines (test 2: space before break)</comment> |
<source>George Pollard</source> |
<sourcelink>http://porg.es/blog/properly-validating-e-mail-addresses</sourcelink> |
<id>224</id> |
</test> |
<test> |
<address>test. obs@syntax.com</address> |
<valid>false</valid> |
<comment>obs-fws must have at least one WSP per line</comment> |
<source>George Pollard</source> |
<sourcelink>http://porg.es/blog/properly-validating-e-mail-addresses</sourcelink> |
<id>225</id> |
</test> |
<test> |
<address>"null \\0"@char.com</address> |
<valid>true</valid> |
<comment>can have escaped null character</comment> |
<source>George Pollard</source> |
<sourcelink>http://porg.es/blog/properly-validating-e-mail-addresses</sourcelink> |
<id>226</id> |
</test> |
<test> |
<address>"null \0"@char.com</address> |
<valid>false</valid> |
<comment>cannot have unescaped null character</comment> |
<source>George Pollard</source> |
<sourcelink>http://porg.es/blog/properly-validating-e-mail-addresses</sourcelink> |
<id>227</id> |
</test> |
<test> |
<address>null\\0@char.com</address> |
<valid>false</valid> |
<comment>escaped null must be in quoted string</comment> |
<source>George Pollard</source> |
<sourcelink>http://porg.es/blog/properly-validating-e-mail-addresses</sourcelink> |
<id>228</id> |
</test> |
<test> |
<address>cdburgess+!#$%&'*-/=?+_{}|~test@gmail.com</address> |
<valid>true</valid> |
<comment>Example given in comments</comment> |
<source>http://www.dominicsayers.com/isemail/#comment-30024957</source> |
<sourcelink>cdburgess</sourcelink> |
<id>229</id> |
</test> |
</tests> |
Property changes: |
Added: svn:mime-type |
+text/plain |
\ No newline at end of property |
/ViaThinkSoft Java Utils/test/emailExperimentalTests.xml |
---|
0,0 → 1,807 |
<?xml version="1.0" encoding="UTF-8" standalone="no"?> |
<!-- |
Umlaute sind nicht erlaubt |
Anmerkung: Die Übersetzung in den Punnycode muss durch den Clienten |
stattfinden |
TODO: Sollen diese Adressen trotzdem zugelassen werden? |
* müller@compuglobal.org" => false |
* "test@müller.de" => false |
* "müller@müllermilch.de" => false |
--> |
<tests> |
<test> |
<address>info@compuglobal.org</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9000</id> |
</test> |
<test> |
<address>info@example.eu</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9001</id> |
</test> |
<test> |
<address>info@example.uk</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9002</id> |
</test> |
<test> |
<address>info@example.co.uk</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9003</id> |
</test> |
<test> |
<address>info@example.ltd.uk</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9004</id> |
</test> |
<test> |
<address>info@example.asso.fr</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9005</id> |
</test> |
<test> |
<address>info@example.mil</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9006</id> |
</test> |
<test> |
<address>example@example.com</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9007</id> |
</test> |
<test> |
<address>john@server.department.company.com</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9008</id> |
</test> |
<test> |
<address>test <mail@test.de></address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9009</id> |
</test> |
<test> |
<address>INFO@COMPUGLOBAL.ORG</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9010</id> |
</test> |
<test> |
<address>info@compuglobal.org info@compuglobal.org</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9011</id> |
</test> |
<test> |
<address>info@compuglobal.org, info@compuglobal.org</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9012</id> |
</test> |
<test> |
<address>info@compuglobal.org; info@compuglobal.org</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9013</id> |
</test> |
<test> |
<address>info@compuglobal.org </address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9014</id> |
</test> |
<test> |
<address> info@compuglobal.org </address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9015</id> |
</test> |
<test> |
<address> |
|
info@compuglobal.org |
|
</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9016</id> |
</test> |
<test> |
<address>invalid@test@example.com</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9017</id> |
</test> |
<test> |
<address>invalidexample.com</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9018</id> |
</test> |
<test> |
<address>john@aol...com</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9019</id> |
</test> |
<test> |
<address>john@aol...aol.com</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9020</id> |
</test> |
<test> |
<address>test@invalid</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9021</id> |
</test> |
<test> |
<address>invalid</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9022</id> |
</test> |
<test> |
<address/> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9023</id> |
</test> |
<test> |
<address>hallo@127.0.0.1</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9024</id> |
</test> |
<test> |
<address>hallo@[127.0.0.1]</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9025</id> |
</test> |
<test> |
<address>Arabic@مثال.إختبار</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9026</id> |
</test> |
<test> |
<address>Persian@مثال.آزمایشی</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9027</id> |
</test> |
<test> |
<address>ChineseSimplified@例子.测试</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9028</id> |
</test> |
<test> |
<address>ChineseTraditional@例子.測試</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9029</id> |
</test> |
<test> |
<address>Cyrillic@пример.испытание</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9030</id> |
</test> |
<test> |
<address>Hindi@उदाहरण.परीक्षा</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9031</id> |
</test> |
<test> |
<address>Greek@παράδειγμα.δοκιμή</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9032</id> |
</test> |
<test> |
<address>Korean@실례.테스트</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9033</id> |
</test> |
<test> |
<address>YiddishHebrew@בײַשפּיל.טעסט</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9034</id> |
</test> |
<test> |
<address>Japanese@例え.テスト</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9035</id> |
</test> |
<test> |
<address>Tamil@உதாரணம்.பரிட்சை</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9036</id> |
</test> |
<test> |
<address>Arabic@xn--mgbh0fb.xn--kgbechtv</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9037</id> |
</test> |
<test> |
<address>Persian@xn--mgbh0fb.xn--hgbk6aj7f53bba</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9038</id> |
</test> |
<test> |
<address>ChineseSimplified@xn--fsqu00a.xn--0zwm56d</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9039</id> |
</test> |
<test> |
<address>ChineseTraditional@xn--fsqu00a.xn--g6w251d</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9040</id> |
</test> |
<test> |
<address>Cyrillic@xn--e1afmkfd.xn--80akhbyknj4f</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9041</id> |
</test> |
<test> |
<address>Hindi@xn--p1b6ci4b4b3a.xn--11b5bs3a9aj6g</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9042</id> |
</test> |
<test> |
<address>Greek@xn--hxajbheg2az3al.xn--jxalpdlp</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9043</id> |
</test> |
<test> |
<address>Korean@xn--9n2bp8q.xn--9t4b11yi5a</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9044</id> |
</test> |
<test> |
<address>YiddishHebrew@xn--fdbk5d8ap9b8a8d.xn--deba0ad</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9045</id> |
</test> |
<test> |
<address>Japanese@xn--r8jz45g.xn--zckzah</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9046</id> |
</test> |
<test> |
<address>Tamil@xn--zkc6cc5bi7f6e.xn--hlcj6aya9esc7a</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9047</id> |
</test> |
<test> |
<address>root</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9048</id> |
</test> |
<test> |
<address>a@b.c</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9049</id> |
</test> |
<test> |
<address>me@.my.com</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9050</id> |
</test> |
<test> |
<address>hello world@example.com</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9051</id> |
</test> |
<test> |
<address>test.@example.com</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9052</id> |
</test> |
<test> |
<address>.test@example.com</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9053</id> |
</test> |
<test> |
<address>"Angela Merkel"@example.com</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9054</id> |
</test> |
<test> |
<address>Abc.example.com</address> |
<valid>false</valid> |
<source>http://en.wikipedia.org/wiki/E-mail_address</source> |
<comment>haracter @ is missing</comment> |
<sourcelink/> |
<id>9055</id> |
</test> |
<test> |
<address>Abc.@example.com</address> |
<valid>false</valid> |
<source/> |
<comment>character dot(.) is last in local part</comment> |
<sourcelink/> |
<id>9056</id> |
</test> |
<test> |
<address>Abc..123@example.com</address> |
<valid>false</valid> |
<source/> |
<comment>character dot(.) is double</comment> |
<sourcelink/> |
<id>9057</id> |
</test> |
<test> |
<address>A@b@c@example.com</address> |
<valid>false</valid> |
<source>http://en.wikipedia.org/wiki/E-mail_address</source> |
<comment>only one @ is allowed outside quotations marks</comment> |
<sourcelink/> |
<id>9058</id> |
</test> |
<test> |
<address>()[]\;:,<>@example.com</address> |
<valid>false</valid> |
<source>http://en.wikipedia.org/wiki/E-mail_address</source> |
<comment>none of the characters before the @ in this example are allowed outside quotation marks</comment> |
<sourcelink/> |
<id>9059</id> |
</test> |
<test> |
<address>test@localhost</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9060</id> |
</test> |
<test> |
<address>john@mail.invalid</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9061</id> |
</test> |
<test> |
<address>john@mail.xx</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9062</id> |
</test> |
<test> |
<address>foo\@bar@internet.com</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink>http://stackoverflow.com/questions/2514810/php-email-validation-question/2515111#2515111</sourcelink> |
<id>9063</id> |
</test> |
<test> |
<address>test/foo=bar@persona.com</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink>http://stackoverflow.com/questions/2514810/php-email-validation-question/2515111#2515111</sourcelink> |
<id>9064</id> |
</test> |
<test> |
<address>my..name@address.com</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink>http://stackoverflow.com/questions/2514810/php-email-validation-question/2515111#2515111</sourcelink> |
<id>9065</id> |
</test> |
<test> |
<address>.myaddress@address.com</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink>http://stackoverflow.com/questions/2514810/php-email-validation-question/2515111#2515111</sourcelink> |
<id>9066</id> |
</test> |
<test> |
<address>Aa0.!#$%&'*+-/=?^_`{|}~\ \"\@\:\;@example.com</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink/> |
<id>9067</id> |
</test> |
<test> |
<address>dclo@us.ibm.com</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink>http://www.linuxjournal.com/article/9585?page=0,2</sourcelink> |
<id>9068</id> |
</test> |
<test> |
<address>abc\@def@example.com</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink>http://www.linuxjournal.com/article/9585?page=0,2</sourcelink> |
<id>9069</id> |
</test> |
<test> |
<address>abc\\@example.com</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink>http://www.linuxjournal.com/article/9585?page=0,2</sourcelink> |
<id>9070</id> |
</test> |
<test> |
<address>Fred\ Bloggs@example.com</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink>http://www.linuxjournal.com/article/9585?page=0,2</sourcelink> |
<id>9071</id> |
</test> |
<test> |
<address>Joe.\\Blow@example.com</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink>http://www.linuxjournal.com/article/9585?page=0,2</sourcelink> |
<id>9072</id> |
</test> |
<test> |
<address>"Abc@def"@example.com</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink>http://www.linuxjournal.com/article/9585?page=0,2</sourcelink> |
<id>9073</id> |
</test> |
<test> |
<address>"Fred Bloggs"@example.com</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink>http://www.linuxjournal.com/article/9585?page=0,2</sourcelink> |
<id>9074</id> |
</test> |
<test> |
<address>customer/department=shipping@example.com</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink>http://www.linuxjournal.com/article/9585?page=0,2</sourcelink> |
<id>9075</id> |
</test> |
<test> |
<address>\$A12345@example.com</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink>http://www.linuxjournal.com/article/9585?page=0,2</sourcelink> |
<id>9076</id> |
</test> |
<test> |
<address>!def!xyz%abc@example.com</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink>http://www.linuxjournal.com/article/9585?page=0,2</sourcelink> |
<id>9077</id> |
</test> |
<test> |
<address>_somename@example.com</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink>http://www.linuxjournal.com/article/9585?page=0,2</sourcelink> |
<id>9078</id> |
</test> |
<test> |
<address>user+mailbox@example.com</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink>http://www.linuxjournal.com/article/9585?page=0,2</sourcelink> |
<id>9079</id> |
</test> |
<test> |
<address>peter.piper@example.com</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink>http://www.linuxjournal.com/article/9585?page=0,2</sourcelink> |
<id>9080</id> |
</test> |
<test> |
<address>Doug\ \"Ace\"\ Lovell@example.com</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink>http://www.linuxjournal.com/article/9585?page=0,2</sourcelink> |
<id>9081</id> |
</test> |
<test> |
<address>"Doug \"Ace\" L."@example.com</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink>http://www.linuxjournal.com/article/9585?page=0,2</sourcelink> |
<id>9082</id> |
</test> |
<test> |
<address>abc@def@example.com</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink>http://www.linuxjournal.com/article/9585?page=0,2</sourcelink> |
<id>9083</id> |
</test> |
<test> |
<address>abc\\@def@example.com</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink>http://www.linuxjournal.com/article/9585?page=0,2</sourcelink> |
<id>9084</id> |
</test> |
<test> |
<address>abc\@example.com</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink>http://www.linuxjournal.com/article/9585?page=0,2</sourcelink> |
<id>9085</id> |
</test> |
<test> |
<address>@example.com</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink>http://www.linuxjournal.com/article/9585?page=0,2</sourcelink> |
<id>9086</id> |
</test> |
<test> |
<address>doug@</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink>http://www.linuxjournal.com/article/9585?page=0,2</sourcelink> |
<id>9087</id> |
</test> |
<test> |
<address>"qu@example.com</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink>http://www.linuxjournal.com/article/9585?page=0,2</sourcelink> |
<id>9088</id> |
</test> |
<test> |
<address>ote"@example.com</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink>http://www.linuxjournal.com/article/9585?page=0,2</sourcelink> |
<id>9089</id> |
</test> |
<test> |
<address>.dot@example.com</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink>http://www.linuxjournal.com/article/9585?page=0,2</sourcelink> |
<id>9090</id> |
</test> |
<test> |
<address>dot.@example.com</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink>http://www.linuxjournal.com/article/9585?page=0,2</sourcelink> |
<id>9091</id> |
</test> |
<test> |
<address>two..dot@example.com</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink>http://www.linuxjournal.com/article/9585?page=0,2</sourcelink> |
<id>9092</id> |
</test> |
<test> |
<address>"Doug "Ace" L."@example.com</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink>http://www.linuxjournal.com/article/9585?page=0,2</sourcelink> |
<id>9093</id> |
</test> |
<test> |
<address>Doug\ \"Ace\"\ L\.@example.com</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink>http://www.linuxjournal.com/article/9585?page=0,2</sourcelink> |
<id>9094</id> |
</test> |
<test> |
<address>hello world@example.com</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink>http://www.linuxjournal.com/article/9585?page=0,2</sourcelink> |
<id>9095</id> |
</test> |
<test> |
<address>gatsby@f.sc.ot.t.f.i.tzg.era.l.d.</address> |
<valid>false</valid> |
<source/> |
<comment/> |
<sourcelink>http://www.linuxjournal.com/article/9585?page=0,2</sourcelink> |
<id>9096</id> |
</test> |
<test> |
<address>{^c\@**Dog^}@cartoon.com</address> |
<valid>true</valid> |
<source/> |
<comment/> |
<sourcelink>http://www.linuxjournal.com/article/9585?page=0,2</sourcelink> |
<id>9097</id> |
</test> |
</tests> |
Property changes: |
Added: svn:mime-type |
+text/plain |
\ No newline at end of property |
/ViaThinkSoft Java Utils/src/com/iamcal/rfc3696/Bits.java |
---|
0,0 → 1,78 |
package com.iamcal.rfc3696; |
public class Bits { |
private String local; |
private String localAtom; |
private String localQuoted; |
private String localObs; |
private String domain; |
private String domainAtom; |
private String domainLiteral; |
private String domainObs; |
public String getLocal() { |
return local; |
} |
public void setLocal(String local) { |
this.local = local; |
} |
public String getLocalAtom() { |
return localAtom; |
} |
public void setLocalAtom(String localAtom) { |
this.localAtom = localAtom; |
} |
public String getLocalQuoted() { |
return localQuoted; |
} |
public void setLocalQuoted(String localQuoted) { |
this.localQuoted = localQuoted; |
} |
public String getLocalObs() { |
return localObs; |
} |
public void setLocalObs(String localObs) { |
this.localObs = localObs; |
} |
public String getDomain() { |
return domain; |
} |
public void setDomain(String domain) { |
this.domain = domain; |
} |
public String getDomainAtom() { |
return domainAtom; |
} |
public void setDomainAtom(String domainAtom) { |
this.domainAtom = domainAtom; |
} |
public String getDomainLiteral() { |
return domainLiteral; |
} |
public void setDomainLiteral(String domainLiteral) { |
this.domainLiteral = domainLiteral; |
} |
public String getDomainObs() { |
return domainObs; |
} |
public void setDomainObs(String domainObs) { |
this.domainObs = domainObs; |
} |
} |
Property changes: |
Added: svn:mime-type |
+text/plain |
\ No newline at end of property |
/ViaThinkSoft Java Utils/src/com/iamcal/rfc3696/RFC3696EmailParser.java |
---|
0,0 → 1,422 |
package com.iamcal.rfc3696; |
import java.util.regex.MatchResult; |
import java.util.regex.Matcher; |
import java.util.regex.Pattern; |
// |
// RFC3696 Email Parser |
// |
// By Cal Henderson <cal@iamcal.com> |
// |
// This code is dual licensed: |
// CC Attribution-ShareAlike 2.5 - http://creativecommons.org/licenses/by-sa/2.5/ |
// GPLv3 - http://www.gnu.org/copyleft/gpl.html |
// |
// $Revision: 5039 $ |
// |
// Translated from PHP to Java and slightly improved by Daniel Marschall |
// Source: http://code.iamcal.com/php/rfc822/rfc3696.phps |
// Current version: 2010-06-10 |
// |
public class RFC3696EmailParser { |
public static boolean isValidEmailAddress(String email) { // was isValidRFC3696EmailAddress(String) |
if (email == null) email = ""; |
// #################################################################################### |
// # |
// # NO-WS-CTL = %d1-8 / ; US-ASCII control characters |
// # %d11 / ; that do not include the |
// # %d12 / ; carriage return, line feed, |
// # %d14-31 / ; and white space characters |
// # %d127 |
// # ALPHA = %x41-5A / %x61-7A ; A-Z / a-z |
// # DIGIT = %x30-39 |
final String no_ws_ctl = "[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]"; |
final String alpha = "[\\x41-\\x5a\\x61-\\x7a]"; |
final String digit = "[\\x30-\\x39]"; |
final String cr = "\\x0d"; |
final String lf = "\\x0a"; |
final String crlf = "(?:"+cr+lf+")"; |
// #################################################################################### |
// # |
// # obs-char = %d0-9 / %d11 / ; %d0-127 except CR and |
// # %d12 / %d14-127 ; LF |
// # obs-text = *LF *CR *(obs-char *LF *CR) |
// # text = %d1-9 / ; Characters excluding CR and LF |
// # %d11 / |
// # %d12 / |
// # %d14-127 / |
// # obs-text |
// # obs-qp = "\" (%d0-127) |
// # quoted-pair = ("\" text) / obs-qp |
final String obs_char = "[\\x00-\\x09\\x0b\\x0c\\x0e-\\x7f]"; |
// final String obs_text = "(?:"+lf+"*"+cr+"*(?:"+obs_char+lf+"*"+cr+"*)*)"; |
// final String text = "(?:[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f]|"+obs_text+")"; |
// # |
// # there's an issue with the definition of 'text', since 'obs_text' can |
// # be blank and that allows qp's with no character after the slash. we're |
// # treating that as bad, so this just checks we have at least one |
// # (non-CRLF) character |
// # |
final String text = "(?:"+lf+"*"+cr+"*"+obs_char+lf+"*"+cr+"*)"; |
final String obs_qp = "(?:\\x5c[\\x00-\\x7f])"; |
final String quoted_pair = "(?:\\x5c"+text+"|"+obs_qp+")"; |
// #################################################################################### |
// # |
// # obs-FWS = 1*WSP *(CRLF 1*WSP) |
// # FWS = ([*WSP CRLF] 1*WSP) / ; Folding white space |
// # obs-FWS |
// # ctext = NO-WS-CTL / ; Non white space controls |
// # %d33-39 / ; The rest of the US-ASCII |
// # %d42-91 / ; characters not including "(", |
// # %d93-126 ; ")", or "\" |
// # ccontent = ctext / quoted-pair / comment |
// # comment = "(" *([FWS] ccontent) [FWS] ")" |
// # CFWS = *([FWS] comment) (([FWS] comment) / FWS) |
// |
// # |
// # note: we translate ccontent only partially to avoid an infinite loop |
// # instead, we'll recursively strip *nested* comments before processing |
// # the input. that will leave 'plain old comments' to be matched during |
// # the main parse. |
// # |
final String wsp = "[\\x20\\x09]"; |
final String obs_fws = "(?:"+wsp+"+(?:"+crlf+wsp+"+)*)"; |
final String fws = "(?:(?:(?:"+wsp+"*"+crlf+")?"+wsp+"+)|"+obs_fws+")"; |
final String ctext = "(?:"+no_ws_ctl+"|[\\x21-\\x27\\x2A-\\x5b\\x5d-\\x7e])"; |
final String ccontent = "(?:"+ctext+"|"+quoted_pair+")"; |
final String comment = "(?:\\x28(?:"+fws+"?"+ccontent+")*"+fws+"?\\x29)"; |
final String cfws = "(?:(?:"+fws+"?"+comment+")*(?:"+fws+"?"+comment+"|"+fws+"))"; |
// # |
// # these are the rules for removing *nested* comments. we'll just detect |
// # outer comment and replace it with an empty comment, and recurse until |
// # we stop. |
// # |
final String outer_ccontent_dull = "(?:"+fws+"?"+ctext+"|"+quoted_pair+")"; |
final String outer_ccontent_nest = "(?:"+fws+"?"+comment+")"; |
final String outer_comment = "(?:\\x28"+outer_ccontent_dull+"*(?:"+outer_ccontent_nest+outer_ccontent_dull+"*)+"+fws+"?\\x29)"; |
// #################################################################################### |
// # |
// # atext = ALPHA / DIGIT / ; Any character except controls, |
// # "!" / "#" / ; SP, and specials. |
// # "$" / "%" / ; Used for atoms |
// # "&" / "'" / |
// # "*" / "+" / |
// # "-" / "/" / |
// # "=" / "?" / |
// # "^" / "_" / |
// # "`" / "{" / |
// # "|" / "}" / |
// # "~" |
// # atom = [CFWS] 1*atext [CFWS] |
final String atext = "(?:"+alpha+"|"+digit+"|[\\x21\\x23-\\x27\\x2a\\x2b\\x2d\\x2f\\x3d\\x3f\\x5e\\x5f\\x60\\x7b-\\x7e])"; |
final String atom = "(?:"+cfws+"?(?:"+atext+")+"+cfws+"?)"; |
// #################################################################################### |
// # |
// # qtext = NO-WS-CTL / ; Non white space controls |
// # %d33 / ; The rest of the US-ASCII |
// # %d35-91 / ; characters not including "\" |
// # %d93-126 ; or the quote character |
// # qcontent = qtext / quoted-pair |
// # quoted-string = [CFWS] |
// # DQUOTE *([FWS] qcontent) [FWS] DQUOTE |
// # [CFWS] |
// # word = atom / quoted-string |
final String qtext = "(?:"+no_ws_ctl+"|[\\x21\\x23-\\x5b\\x5d-\\x7e])"; |
final String qcontent = "(?:"+qtext+"|"+quoted_pair+")"; |
// final String quoted_string = "(?:"+cfws+"?\\x22(?:"+fws+"?"+qcontent+")*"+fws+"?\\x22"+cfws+"?)"; |
// # |
// # changed the '*' to a '+' to require that quoted strings are not empty |
// # |
final String quoted_string = "(?:"+cfws+"?\\x22(?:"+fws+"?"+qcontent+")+"+fws+"?\\x22"+cfws+"?)"; |
final String word = "(?:"+atom+"|"+quoted_string+")"; |
// #################################################################################### |
// # |
// # obs-local-part = word *("." word) |
// # obs-domain = atom *("." atom) |
final String obs_local_part = "(?:"+word+"(?:\\x2e"+word+")*)"; |
final String obs_domain = "(?:"+atom+"(?:\\x2e"+atom+")*)"; |
// #################################################################################### |
// # |
// # dot-atom-text = 1*atext *("." 1*atext) |
// # dot-atom = [CFWS] dot-atom-text [CFWS] |
final String dot_atom_text = "(?:"+atext+"+(?:\\x2e"+atext+"+)*)"; |
final String dot_atom = "(?:"+cfws+"?"+dot_atom_text+""+cfws+"?)"; |
// #################################################################################### |
// # |
// # domain-literal = [CFWS] "[" *([FWS] dcontent) [FWS] "]" [CFWS] |
// # dcontent = dtext / quoted-pair |
// # dtext = NO-WS-CTL / ; Non white space controls |
// # |
// # %d33-90 / ; The rest of the US-ASCII |
// # %d94-126 ; characters not including "[", |
// # ; "]", or "\" |
final String dtext = "(?:"+no_ws_ctl+"|[\\x21-\\x5a\\x5e-\\x7e])"; |
final String dcontent = "(?:"+dtext+"|"+quoted_pair+")"; |
final String domain_literal = "(?:"+cfws+"?\\x5b(?:"+fws+"?"+dcontent+")*"+fws+"?\\x5d"+cfws+"?)"; |
// #################################################################################### |
// # |
// # local-part = dot-atom / quoted-string / obs-local-part |
// # domain = dot-atom / domain-literal / obs-domain |
// # addr-spec = local-part "@" domain |
final String local_part = "(("+dot_atom+")|("+quoted_string+")|("+obs_local_part+"))"; |
final String domain = "(("+dot_atom+")|("+domain_literal+")|("+obs_domain+"))"; |
final String addr_spec = local_part+"\\x40"+domain; |
// # |
// # see http://www.dominicsayers.com/isemail/ for details, but this should probably be 254 |
// # |
// TODO: Change to 254. |
// According to Errata ID 1690 of RFC 3696 (submitted by Dominik Sayers) |
// the length accepted by the IETF is 254 and not 256. |
// http://www.rfc-editor.org/errata_search.php?rfc=3696&eid=1690 |
if (email.length() > 256) return false; |
// # |
// # we need to strip nested comments first - we replace them with a simple comment |
// # |
email = RFC3696StripComments(outer_comment, email, "(x)"); |
// # |
// # now match what's left |
// # |
Matcher matcher = Pattern.compile("^"+addr_spec+"$").matcher(email); |
matcher.find(); |
if (!matcher.matches()) { |
return false; |
} |
MatchResult m = matcher.toMatchResult(); |
Bits bits = new Bits(); |
bits.setLocal((m.group(1) == null) ? "" : m.group(1)); |
bits.setLocalAtom((m.group(2) == null) ? "" : m.group(2)); |
bits.setLocalQuoted((m.group(3) == null) ? "" : m.group(3)); |
bits.setLocalObs((m.group(4) == null) ? "" : m.group(4)); |
bits.setDomain((m.group(5) == null) ? "" : m.group(5)); |
bits.setDomainAtom((m.group(6) == null) ? "" : m.group(6)); |
bits.setDomainLiteral((m.group(7) == null) ? "" : m.group(7)); |
bits.setDomainObs((m.group(8) == null) ? "" : m.group(8)); |
// # |
// # we need to now strip comments from bits.getLocal() and bits.getDomain(), |
// # since we know they're i the right place and we want them out of the |
// # way for checking IPs, label sizes, etc |
// # |
bits.setLocal(RFC3696StripComments(comment, bits.getLocal())); |
bits.setDomain(RFC3696StripComments(comment, bits.getDomain())); |
// # |
// # length limits on segments |
// # |
if (bits.getLocal().length() > 64) return false; |
if (bits.getDomain().length() > 255) return false; |
// # |
// # restrictions on domain-literals from RFC2821 section 4.1.3 |
// # |
if (bits.getDomainLiteral().length() > 0) { |
final String Snum = "(\\d{1,3})"; |
final String IPv4_address_literal = Snum+"\\."+Snum+"\\."+Snum+"\\."+Snum; |
final String IPv6_hex = "(?:[0-9a-fA-F]{1,4})"; |
final String IPv6_full = "IPv6\\:"+IPv6_hex+"(:?\\:"+IPv6_hex+"){7}"; |
final String IPv6_comp_part = "(?:"+IPv6_hex+"(?:\\:"+IPv6_hex+"){0,5})?"; |
final String IPv6_comp = "IPv6\\:("+IPv6_comp_part+"\\:\\:"+IPv6_comp_part+")"; |
final String IPv6v4_full = "IPv6\\:"+IPv6_hex+"(?:\\:"+IPv6_hex+"){5}\\:"+IPv4_address_literal; |
final String IPv6v4_comp_part = IPv6_hex+"(?:\\:"+IPv6_hex+"){0,3}"; |
final String IPv6v4_comp = "IPv6\\:((?:"+IPv6v4_comp_part+")?\\:\\:(?:"+IPv6v4_comp_part+"\\:)?)"+IPv4_address_literal; |
// # |
// # IPv4 is simple |
// # |
matcher = Pattern.compile("^\\["+IPv4_address_literal+"\\]$").matcher(bits.getDomain()); |
matcher.find(); |
m = matcher.toMatchResult(); |
if (matcher.matches()) { |
if (Integer.parseInt(m.group(1)) > 255) return false; |
if (Integer.parseInt(m.group(2)) > 255) return false; |
if (Integer.parseInt(m.group(3)) > 255) return false; |
if (Integer.parseInt(m.group(4)) > 255) return false; |
} else { |
// # |
// # this should be IPv6 - a bunch of tests are needed here :) |
// # |
while (true) { |
matcher = Pattern.compile("^\\["+IPv6_full+"\\]$").matcher(bits.getDomain()); |
matcher.find(); |
if (matcher.matches()){ |
break; |
} |
matcher = Pattern.compile("^\\["+IPv6_comp+"\\]$").matcher(bits.getDomain()); |
matcher.find(); |
m = matcher.toMatchResult(); |
if (matcher.matches()) { |
String m1 = m.group(1); |
String[] explode = m1.split("::"); |
String a = ""; |
String b = ""; |
if (explode.length >= 2) { |
if (explode[0] != null) a = explode[0]; |
if (explode[1] != null) b = explode[1]; |
} |
String folded = ((a.length() > 0) && (b.length() > 0)) ? a+":"+b : a+b; |
String[] groups = folded.split(":"); |
if (groups.length > 6) return false; |
break; |
} |
matcher = Pattern.compile("^\\["+IPv6v4_full+"\\]$").matcher(bits.getDomain()); |
matcher.find(); |
m = matcher.toMatchResult(); |
if (matcher.matches()) { |
if (Integer.parseInt(m.group(1)) > 255) return false; |
if (Integer.parseInt(m.group(2)) > 255) return false; |
if (Integer.parseInt(m.group(3)) > 255) return false; |
if (Integer.parseInt(m.group(4)) > 255) return false; |
break; |
} |
matcher = Pattern.compile("^\\["+IPv6v4_comp+"\\]$").matcher(bits.getDomain()); |
matcher.find(); |
m = matcher.toMatchResult(); |
if (matcher.matches()) { |
String m1 = m.group(1); |
String[] explode = m1.split("::"); |
String a = ""; |
String b = ""; |
if (explode.length >= 2) { |
if (explode[0] != null) a = explode[0]; |
if (explode[1] != null) b = explode[1]; |
} |
if (b.length() > 0) /* Added by Daniel Marschall due to translation process */ { |
b = b.substring(0, b.length()-1); // remove the trailing colon before the IPv4 address |
} |
String folded = ((a.length() > 0) && (b.length() > 0)) ? a+":"+b : a+b; |
String[] groups = folded.split(":"); |
if (groups.length > 4) return false; |
break; |
} |
return false; |
} |
} |
}else{ |
// # |
// # the domain is either dot-atom or obs-domain - either way, it's |
// # made up of simple labels and we split on dots |
// # |
String[] labels = bits.getDomain().split("\\."); |
// # |
// # this is allowed by both dot-atom and obs-domain, but is un-routeable on the |
// # public internet, so we'll fail it (e.g. user@localhost) |
// # |
if (labels.length == 1) return false; |
// # |
// # checks on each label |
// # |
for (String label : labels) { |
if (label.length() > 63) return false; |
if (label.charAt(0) == '-') return false; |
if (label.charAt(label.length()-1) == '-') return false; |
} |
// # |
// # last label can't be all numeric |
// # |
String arrayPopResult; |
if (labels.length > 0) { |
arrayPopResult = labels[labels.length - 1]; |
String[] tmpLabels = new String[labels.length - 1]; |
for (int i = 0; i < labels.length - 1; i++) { |
tmpLabels[i] = labels[i]; |
} |
} else { |
arrayPopResult = ""; |
} |
matcher = Pattern.compile("^[0-9]+$").matcher(arrayPopResult); |
matcher.find(); |
if (matcher.matches()) return false; |
} |
return true; |
} |
private static String RFC3696StripComments(String comment, String email, |
String replace) { |
while (true) { |
String newEmail = email.replaceAll(comment, replace); |
if (newEmail.length() == email.length()) { |
return email; |
} |
email = newEmail; |
} |
} |
private static String RFC3696StripComments(String comment, String email) { |
return RFC3696StripComments(comment, email, ""); |
} |
private RFC3696EmailParser() { |
} |
} |
Property changes: |
Added: svn:mime-type |
+text/plain |
\ No newline at end of property |
/ViaThinkSoft Java Utils/src/com/iamcal/rfc3696/rfc3696.php |
---|
0,0 → 1,377 |
<?php |
# |
# RFC3696 Email Parser |
# |
# By Cal Henderson <cal@iamcal.com> |
# |
# This code is dual licensed: |
# CC Attribution-ShareAlike 2.5 - http://creativecommons.org/licenses/by-sa/2.5/ |
# GPLv3 - http://www.gnu.org/copyleft/gpl.html |
# |
# $Revision: 5039 $ |
# |
################################################################################## |
function is_rfc3696_valid_email_address($email){ |
#################################################################################### |
# |
# NO-WS-CTL = %d1-8 / ; US-ASCII control characters |
# %d11 / ; that do not include the |
# %d12 / ; carriage return, line feed, |
# %d14-31 / ; and white space characters |
# %d127 |
# ALPHA = %x41-5A / %x61-7A ; A-Z / a-z |
# DIGIT = %x30-39 |
$no_ws_ctl = "[\\x01-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]"; |
$alpha = "[\\x41-\\x5a\\x61-\\x7a]"; |
$digit = "[\\x30-\\x39]"; |
$cr = "\\x0d"; |
$lf = "\\x0a"; |
$crlf = "(?:$cr$lf)"; |
#################################################################################### |
# |
# obs-char = %d0-9 / %d11 / ; %d0-127 except CR and |
# %d12 / %d14-127 ; LF |
# obs-text = *LF *CR *(obs-char *LF *CR) |
# text = %d1-9 / ; Characters excluding CR and LF |
# %d11 / |
# %d12 / |
# %d14-127 / |
# obs-text |
# obs-qp = "\" (%d0-127) |
# quoted-pair = ("\" text) / obs-qp |
$obs_char = "[\\x00-\\x09\\x0b\\x0c\\x0e-\\x7f]"; |
$obs_text = "(?:$lf*$cr*(?:$obs_char$lf*$cr*)*)"; |
$text = "(?:[\\x01-\\x09\\x0b\\x0c\\x0e-\\x7f]|$obs_text)"; |
# |
# there's an issue with the definition of 'text', since 'obs_text' can |
# be blank and that allows qp's with no character after the slash. we're |
# treating that as bad, so this just checks we have at least one |
# (non-CRLF) character |
# |
$text = "(?:$lf*$cr*$obs_char$lf*$cr*)"; |
$obs_qp = "(?:\\x5c[\\x00-\\x7f])"; |
$quoted_pair = "(?:\\x5c$text|$obs_qp)"; |
#################################################################################### |
# |
# obs-FWS = 1*WSP *(CRLF 1*WSP) |
# FWS = ([*WSP CRLF] 1*WSP) / ; Folding white space |
# obs-FWS |
# ctext = NO-WS-CTL / ; Non white space controls |
# %d33-39 / ; The rest of the US-ASCII |
# %d42-91 / ; characters not including "(", |
# %d93-126 ; ")", or "\" |
# ccontent = ctext / quoted-pair / comment |
# comment = "(" *([FWS] ccontent) [FWS] ")" |
# CFWS = *([FWS] comment) (([FWS] comment) / FWS) |
# |
# note: we translate ccontent only partially to avoid an infinite loop |
# instead, we'll recursively strip *nested* comments before processing |
# the input. that will leave 'plain old comments' to be matched during |
# the main parse. |
# |
$wsp = "[\\x20\\x09]"; |
$obs_fws = "(?:$wsp+(?:$crlf$wsp+)*)"; |
$fws = "(?:(?:(?:$wsp*$crlf)?$wsp+)|$obs_fws)"; |
$ctext = "(?:$no_ws_ctl|[\\x21-\\x27\\x2A-\\x5b\\x5d-\\x7e])"; |
$ccontent = "(?:$ctext|$quoted_pair)"; |
$comment = "(?:\\x28(?:$fws?$ccontent)*$fws?\\x29)"; |
$cfws = "(?:(?:$fws?$comment)*(?:$fws?$comment|$fws))"; |
# |
# these are the rules for removing *nested* comments. we'll just detect |
# outer comment and replace it with an empty comment, and recurse until |
# we stop. |
# |
$outer_ccontent_dull = "(?:$fws?$ctext|$quoted_pair)"; |
$outer_ccontent_nest = "(?:$fws?$comment)"; |
$outer_comment = "(?:\\x28$outer_ccontent_dull*(?:$outer_ccontent_nest$outer_ccontent_dull*)+$fws?\\x29)"; |
#################################################################################### |
# |
# atext = ALPHA / DIGIT / ; Any character except controls, |
# "!" / "#" / ; SP, and specials. |
# "$" / "%" / ; Used for atoms |
# "&" / "'" / |
# "*" / "+" / |
# "-" / "/" / |
# "=" / "?" / |
# "^" / "_" / |
# "`" / "{" / |
# "|" / "}" / |
# "~" |
# atom = [CFWS] 1*atext [CFWS] |
$atext = "(?:$alpha|$digit|[\\x21\\x23-\\x27\\x2a\\x2b\\x2d\\x2f\\x3d\\x3f\\x5e\\x5f\\x60\\x7b-\\x7e])"; |
$atom = "(?:$cfws?(?:$atext)+$cfws?)"; |
#################################################################################### |
# |
# qtext = NO-WS-CTL / ; Non white space controls |
# %d33 / ; The rest of the US-ASCII |
# %d35-91 / ; characters not including "\" |
# %d93-126 ; or the quote character |
# qcontent = qtext / quoted-pair |
# quoted-string = [CFWS] |
# DQUOTE *([FWS] qcontent) [FWS] DQUOTE |
# [CFWS] |
# word = atom / quoted-string |
$qtext = "(?:$no_ws_ctl|[\\x21\\x23-\\x5b\\x5d-\\x7e])"; |
$qcontent = "(?:$qtext|$quoted_pair)"; |
$quoted_string = "(?:$cfws?\\x22(?:$fws?$qcontent)*$fws?\\x22$cfws?)"; |
# |
# changed the '*' to a '+' to require that quoted strings are not empty |
# |
$quoted_string = "(?:$cfws?\\x22(?:$fws?$qcontent)+$fws?\\x22$cfws?)"; |
$word = "(?:$atom|$quoted_string)"; |
#################################################################################### |
# |
# obs-local-part = word *("." word) |
# obs-domain = atom *("." atom) |
$obs_local_part = "(?:$word(?:\\x2e$word)*)"; |
$obs_domain = "(?:$atom(?:\\x2e$atom)*)"; |
#################################################################################### |
# |
# dot-atom-text = 1*atext *("." 1*atext) |
# dot-atom = [CFWS] dot-atom-text [CFWS] |
$dot_atom_text = "(?:$atext+(?:\\x2e$atext+)*)"; |
$dot_atom = "(?:$cfws?$dot_atom_text$cfws?)"; |
#################################################################################### |
# |
# domain-literal = [CFWS] "[" *([FWS] dcontent) [FWS] "]" [CFWS] |
# dcontent = dtext / quoted-pair |
# dtext = NO-WS-CTL / ; Non white space controls |
# |
# %d33-90 / ; The rest of the US-ASCII |
# %d94-126 ; characters not including "[", |
# ; "]", or "\" |
$dtext = "(?:$no_ws_ctl|[\\x21-\\x5a\\x5e-\\x7e])"; |
$dcontent = "(?:$dtext|$quoted_pair)"; |
$domain_literal = "(?:$cfws?\\x5b(?:$fws?$dcontent)*$fws?\\x5d$cfws?)"; |
#################################################################################### |
# |
# local-part = dot-atom / quoted-string / obs-local-part |
# domain = dot-atom / domain-literal / obs-domain |
# addr-spec = local-part "@" domain |
$local_part = "(($dot_atom)|($quoted_string)|($obs_local_part))"; |
$domain = "(($dot_atom)|($domain_literal)|($obs_domain))"; |
$addr_spec = "$local_part\\x40$domain"; |
# |
# see http://www.dominicsayers.com/isemail/ for details, but this should probably be 254 |
# |
if (strlen($email) > 256) return 0; |
# |
# we need to strip nested comments first - we replace them with a simple comment |
# |
$email = rfc3696_strip_comments($outer_comment, $email, "(x)"); |
# |
# now match what's left |
# |
if (!preg_match("!^$addr_spec$!", $email, $m)){ |
return 0; |
} |
$bits = array( |
'local' => isset($m[1]) ? $m[1] : '', |
'local-atom' => isset($m[2]) ? $m[2] : '', |
'local-quoted' => isset($m[3]) ? $m[3] : '', |
'local-obs' => isset($m[4]) ? $m[4] : '', |
'domain' => isset($m[5]) ? $m[5] : '', |
'domain-atom' => isset($m[6]) ? $m[6] : '', |
'domain-literal' => isset($m[7]) ? $m[7] : '', |
'domain-obs' => isset($m[8]) ? $m[8] : '', |
); |
# |
# we need to now strip comments from $bits[local] and $bits[domain], |
# since we know they're i the right place and we want them out of the |
# way for checking IPs, label sizes, etc |
# |
$bits['local'] = rfc3696_strip_comments($comment, $bits['local']); |
$bits['domain'] = rfc3696_strip_comments($comment, $bits['domain']); |
# |
# length limits on segments |
# |
if (strlen($bits['local']) > 64) return 0; |
if (strlen($bits['domain']) > 255) return 0; |
# |
# restrictuions on domain-literals from RFC2821 section 4.1.3 |
# |
if (strlen($bits['domain-literal'])){ |
$Snum = "(\d{1,3})"; |
$IPv4_address_literal = "$Snum\.$Snum\.$Snum\.$Snum"; |
$IPv6_hex = "(?:[0-9a-fA-F]{1,4})"; |
$IPv6_full = "IPv6\:$IPv6_hex(:?\:$IPv6_hex){7}"; |
$IPv6_comp_part = "(?:$IPv6_hex(?:\:$IPv6_hex){0,5})?"; |
$IPv6_comp = "IPv6\:($IPv6_comp_part\:\:$IPv6_comp_part)"; |
$IPv6v4_full = "IPv6\:$IPv6_hex(?:\:$IPv6_hex){5}\:$IPv4_address_literal"; |
$IPv6v4_comp_part = "$IPv6_hex(?:\:$IPv6_hex){0,3}"; |
$IPv6v4_comp = "IPv6\:((?:$IPv6v4_comp_part)?\:\:(?:$IPv6v4_comp_part\:)?)$IPv4_address_literal"; |
# |
# IPv4 is simple |
# |
if (preg_match("!^\[$IPv4_address_literal\]$!", $bits['domain'], $m)){ |
if (intval($m[1]) > 255) return 0; |
if (intval($m[2]) > 255) return 0; |
if (intval($m[3]) > 255) return 0; |
if (intval($m[4]) > 255) return 0; |
}else{ |
# |
# this should be IPv6 - a bunch of tests are needed here :) |
# |
while (1){ |
if (preg_match("!^\[$IPv6_full\]$!", $bits['domain'])){ |
break; |
} |
if (preg_match("!^\[$IPv6_comp\]$!", $bits['domain'], $m)){ |
list($a, $b) = explode('::', $m[1]); |
$folded = (strlen($a) && strlen($b)) ? "$a:$b" : "$a$b"; |
$groups = explode(':', $folded); |
if (count($groups) > 6) return 0; |
break; |
} |
if (preg_match("!^\[$IPv6v4_full\]$!", $bits['domain'], $m)){ |
if (intval($m[1]) > 255) return 0; |
if (intval($m[2]) > 255) return 0; |
if (intval($m[3]) > 255) return 0; |
if (intval($m[4]) > 255) return 0; |
break; |
} |
if (preg_match("!^\[$IPv6v4_comp\]$!", $bits['domain'], $m)){ |
list($a, $b) = explode('::', $m[1]); |
$b = substr($b, 0, -1); # remove the trailing colon before the IPv4 address |
$folded = (strlen($a) && strlen($b)) ? "$a:$b" : "$a$b"; |
$groups = explode(':', $folded); |
if (count($groups) > 4) return 0; |
break; |
} |
return 0; |
} |
} |
}else{ |
# |
# the domain is either dot-atom or obs-domain - either way, it's |
# made up of simple labels and we split on dots |
# |
$labels = explode('.', $bits['domain']); |
# |
# this is allowed by both dot-atom and obs-domain, but is un-routeable on the |
# public internet, so we'll fail it (e.g. user@localhost) |
# |
if (count($labels) == 1) return 0; |
# |
# checks on each label |
# |
foreach ($labels as $label){ |
if (strlen($label) > 63) return 0; |
if (substr($label, 0, 1) == '-') return 0; |
if (substr($label, -1) == '-') return 0; |
} |
# |
# last label can't be all numeric |
# |
if (preg_match('!^[0-9]+$!', array_pop($labels))) return 0; |
} |
return 1; |
} |
################################################################################## |
function rfc3696_strip_comments($comment, $email, $replace=''){ |
while (1){ |
$new = preg_replace("!$comment!", $replace, $email); |
if (strlen($new) == strlen($email)){ |
return $email; |
} |
$email = $new; |
} |
} |
################################################################################## |
?> |
/ViaThinkSoft Java Utils/src/com/dominicsayers/isemail/EMailSyntaxDiagnosis.java |
---|
0,0 → 1,7 |
package com.dominicsayers.isemail; |
public enum EMailSyntaxDiagnosis { |
ISEMAIL_VALID, ISEMAIL_TOOLONG, ISEMAIL_NOAT, ISEMAIL_NOLOCALPART, ISEMAIL_NODOMAIN, ISEMAIL_ZEROLENGTHELEMENT, ISEMAIL_BADCOMMENT_START, ISEMAIL_BADCOMMENT_END, ISEMAIL_UNESCAPEDDELIM, ISEMAIL_EMPTYELEMENT, ISEMAIL_UNESCAPEDSPECIAL, ISEMAIL_LOCALTOOLONG, ISEMAIL_IPV4BADPREFIX, ISEMAIL_IPV6BADPREFIXMIXED, ISEMAIL_IPV6BADPREFIX, ISEMAIL_IPV6GROUPCOUNT, ISEMAIL_IPV6DOUBLEDOUBLECOLON, ISEMAIL_IPV6BADCHAR, ISEMAIL_IPV6TOOMANYGROUPS, ISEMAIL_TLD, ISEMAIL_DOMAINEMPTYELEMENT, ISEMAIL_DOMAINELEMENTTOOLONG, ISEMAIL_DOMAINBADCHAR, ISEMAIL_DOMAINTOOLONG, ISEMAIL_TLDNUMERIC, ISEMAIL_DOMAINNOTFOUND/*, ISEMAIL_NOTDEFINED */ |
} |
Property changes: |
Added: svn:mime-type |
+text/plain |
\ No newline at end of property |
/ViaThinkSoft Java Utils/src/com/dominicsayers/isemail/PHPFunctions.java |
---|
0,0 → 1,98 |
package com.dominicsayers.isemail; |
import java.util.regex.Matcher; |
import java.util.regex.Pattern; |
/** |
* IMPORTANT NOTE! These functions were developed during the translation process |
* of the E-Mail-Address verification class for Dominic Sayers. These functions |
* are NEITHER AN IDENTICAL NOR A OFFICIAL equivalence of PHP's functions. The |
* functionality is only as much as needed by my initial purpose. Special cases |
* are usually not implemented. Please also note that you have to use the JAVA |
* REGULAR EXPRESSION syntax! PHP's PCRE IS NOT INTERPRETED OR CONVERTED! |
*/ |
public class PHPFunctions { |
public static int preg_match(String regex, String input) { |
Matcher m = Pattern.compile(regex).matcher(input); |
int c = 0; |
while (m.find()) { |
return 1; // preg_match() bricht bei erster Übereinstimmung ab. |
} |
return c; |
} |
public static String[] preg_match_to_array(String regex, String input) { |
Matcher m = Pattern.compile(regex).matcher(input); |
if (m.find()) { |
String[] result = new String[m.groupCount() + 1]; |
for (int i = 0; i < result.length; i++) { |
result[i] = m.group(i); |
} |
return result; |
} else { |
return new String[0]; |
} |
} |
public static String[] preg_split(String regex, String input) { |
return input.split(regex, -1); |
} |
/** |
* @returns [group#][match#] |
*/ |
private static String[] appendToStringArray(String[] ary, String append) { |
if (ary == null) |
ary = new String[0]; |
String[] ary2 = new String[ary.length + 1]; |
for (int i = 0; i < ary.length; i++) { |
ary2[i] = ary[i]; |
} |
ary2[ary.length] = append; |
return ary2; |
} |
public static String[][] preg_match_all(String regex, String input) { |
Matcher m = Pattern.compile(regex).matcher(input); |
if (m.find()) { |
int j = -1; |
String[][] result = new String[m.groupCount() + 1][]; |
do { |
j++; |
for (int i = 0; i < result.length; i++) { |
result[i] = appendToStringArray(result[i], m.group(i)); |
} |
} while (m.find()); |
return result; |
} else { |
return new String[0][0]; |
} |
} |
public static String substr(String input, int start) { |
return input.substring(start); |
} |
public static String substr(String input, int start, int length) { |
return input.substring(start, start + length); |
} |
public static String preg_replace(String pattern, String replacement, |
String subject) { |
return subject.replaceAll(pattern, replacement); |
} |
private PHPFunctions() { |
} |
} |
Property changes: |
Added: svn:mime-type |
+text/plain |
\ No newline at end of property |
/ViaThinkSoft Java Utils/src/com/dominicsayers/isemail/IsEMail.java |
---|
0,0 → 1,648 |
package com.dominicsayers.isemail; |
import javax.naming.NamingException; |
/** |
* @package isemail |
* @author Dominic Sayers <dominic_sayers@hotmail.com>; Translated from PHP into |
* Java by Daniel Marschall [www.daniel-marschall.de] |
* @copyright 2010 Dominic Sayers |
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
* @link http://www.dominicsayers.com/isemail |
* @version 1.17 - Upper length limit corrected to 254 characters; |
* Java-Translation 2010-06-13 |
*/ |
/* |
* Copyright (c) 2008-2010, Dominic Sayers All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions are met: |
* |
* Redistributions of source code must retain the above copyright notice, this |
* list of conditions and the following disclaimer. Redistributions in binary |
* form must reproduce the above copyright notice, this list of conditions and |
* the following disclaimer in the documentation and/or other materials provided |
* with the distribution. Neither the name of Dominic Sayers nor the names of |
* its contributors may be used to endorse or promote products derived from this |
* software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
* POSSIBILITY OF SUCH DAMAGE. |
*/ |
public class IsEMail { |
/** |
* Checks the syntax of an email address without DNS check. |
* |
* @param email |
* The email address to be checked. |
* @return True if the email address is valid. |
*/ |
public static boolean is_email(String email) { |
return (is_email_diagnosis(email, false) == EMailSyntaxDiagnosis.ISEMAIL_VALID); |
} |
/** |
* Checks the syntax of an email address. |
* |
* @param email |
* The email address to be checked. |
* @param checkDNS |
* Whether a DNS check should be performed or not. |
* @return True if the email address is valid. |
*/ |
public static boolean is_email(String email, boolean checkDNS) { |
return (is_email_diagnosis(email, checkDNS) == EMailSyntaxDiagnosis.ISEMAIL_VALID); |
} |
/** |
* Checks the syntax of an email address with diagnosis and without DNS |
* check. |
* |
* @param email |
* The email address to be checked. |
* @return A diagnosis of the email syntax. |
*/ |
public static EMailSyntaxDiagnosis is_email_diagnosis(String email) { |
return is_email_diagnosis(email, false); |
} |
/** |
* Checks the syntax of an email address with diagnosis. |
* |
* @param email |
* The email address to be checked. |
* @param checkDNS |
* Whether a DNS check should be performed or not. |
* @return A diagnosis of the email syntax. |
*/ |
public static EMailSyntaxDiagnosis is_email_diagnosis(String email, |
boolean checkDNS) { |
if (email == null) |
email = ""; |
// Check that 'email' is a valid address. Read the following RFCs to |
// understand the constraints: |
// (http://tools.ietf.org/html/rfc5322) |
// (http://tools.ietf.org/html/rfc3696) |
// (http://tools.ietf.org/html/rfc5321) |
// (http://tools.ietf.org/html/rfc4291#section-2.2) |
// (http://tools.ietf.org/html/rfc1123#section-2.1) |
// the upper limit on address lengths should normally be considered to |
// be 254 |
// (http://www.rfc-editor.org/errata_search.php?rfc=3696) |
// NB My erratum has now been verified by the IETF so the correct answer |
// is 254 |
// |
// The maximum total length of a reverse-path or forward-path is 256 |
// characters (including the punctuation and element separators) |
// (http://tools.ietf.org/html/rfc5321#section-4.5.3.1.3) |
// NB There is a mandatory 2-character wrapper round the actual address |
int emailLength = email.length(); |
// revision 1.17: Max length reduced to 254 (see above) |
if (emailLength > 254) { |
return EMailSyntaxDiagnosis.ISEMAIL_TOOLONG; // Too long |
} |
// Contemporary email addresses consist of a "local part" separated from |
// a "domain part" (a fully-qualified domain name) by an at-sign ("@"). |
// (http://tools.ietf.org/html/rfc3696#section-3) |
int atIndex = email.lastIndexOf('@'); |
if (atIndex == -1) { |
return EMailSyntaxDiagnosis.ISEMAIL_NOAT; // No at-sign |
} |
if (atIndex == 0) { |
return EMailSyntaxDiagnosis.ISEMAIL_NOLOCALPART; // No local part |
} |
if (atIndex == emailLength - 1) { |
// No domain part |
return EMailSyntaxDiagnosis.ISEMAIL_NODOMAIN; |
// revision 1.14: Length test bug suggested by Andrew Campbell of |
// Gloucester, MA |
} |
// Sanitize comments |
// - remove nested comments, quotes and dots in comments |
// - remove parentheses and dots from quoted strings |
int braceDepth = 0; |
boolean inQuote = false; |
boolean escapeThisChar = false; |
for (int i = 0; i < emailLength; ++i) { |
char charX = email.charAt(i); |
boolean replaceChar = false; |
if (charX == '\\') { |
escapeThisChar = !escapeThisChar; // Escape the next character? |
} else { |
switch (charX) { |
case '(': |
if (escapeThisChar) { |
replaceChar = true; |
} else { |
if (inQuote) { |
replaceChar = true; |
} else { |
if (braceDepth++ > 0) { |
replaceChar = true; // Increment brace depth |
} |
} |
} |
break; |
case ')': |
if (escapeThisChar) { |
replaceChar = true; |
} else { |
if (inQuote) { |
replaceChar = true; |
} else { |
if (--braceDepth > 0) |
replaceChar = true; // Decrement brace depth |
if (braceDepth < 0) { |
braceDepth = 0; |
} |
} |
} |
break; |
case '"': |
if (escapeThisChar) { |
replaceChar = true; |
} else { |
if (braceDepth == 0) { |
// Are we inside a quoted string? |
inQuote = !inQuote; |
} else { |
replaceChar = true; |
} |
} |
break; |
case '.': // Dots don't help us either |
if (escapeThisChar) { |
replaceChar = true; |
} else { |
if (braceDepth > 0) |
replaceChar = true; |
} |
break; |
default: |
} |
escapeThisChar = false; |
if (replaceChar) { |
// Replace the offending character with something harmless |
// revision 1.12: Line above replaced because PHPLint |
// doesn't like that syntax |
email = replaceCharAt(email, i, 'x'); |
} |
} |
} |
String localPart = PHPFunctions.substr(email, 0, atIndex); |
String domain = PHPFunctions.substr(email, atIndex + 1); |
// Folding white space |
final String FWS = "(?:(?:(?:[ \\t]*(?:\\r\\n))?[ \\t]+)|(?:[ \\t]+(?:(?:\\r\\n)[ \\t]+)*))"; |
// Let's check the local part for RFC compliance... |
// |
// local-part = dot-atom / quoted-string / obs-local-part |
// obs-local-part = word *("." word) |
// (http://tools.ietf.org/html/rfc5322#section-3.4.1) |
// |
// Problem: need to distinguish between "first.last" and "first"."last" |
// (i.e. one element or two). And I suck at regexes. |
String[] dotArray = PHPFunctions.preg_split( |
"(?m)\\.(?=(?:[^\\\"]*\\\"[^\\\"]*\\\")*(?![^\\\"]*\\\"))", |
localPart); |
int partLength = 0; |
for (String element : dotArray) { |
// Remove any leading or trailing FWS |
element = PHPFunctions.preg_replace("^" + FWS + "|" + FWS + "$", |
"", element); |
int elementLength = element.length(); |
if (elementLength == 0) { |
// Can't have empty element (consecutive dots or |
// dots at the start or end) |
return EMailSyntaxDiagnosis.ISEMAIL_ZEROLENGTHELEMENT; |
} |
// revision 1.15: Speed up the test and get rid of |
// "unitialized string offset" notices from PHP |
// We need to remove any valid comments (i.e. those at the start or |
// end of the element) |
if (element.charAt(0) == '(') { |
int indexBrace = element.indexOf(')'); |
if (indexBrace != -1) { |
if (PHPFunctions.preg_match("(?<!\\\\)[\\(\\)]", |
PHPFunctions.substr(element, 1, indexBrace - 1)) > 0) { |
// Illegal characters in comment |
return EMailSyntaxDiagnosis.ISEMAIL_BADCOMMENT_START; |
} |
element = PHPFunctions.substr(element, indexBrace + 1, |
elementLength - indexBrace - 1); |
elementLength = element.length(); |
} |
} |
if (element.charAt(elementLength - 1) == ')') { |
int indexBrace = element.lastIndexOf('('); |
if (indexBrace != -1) { |
if (PHPFunctions.preg_match("(?<!\\\\)(?:[\\(\\)])", |
PHPFunctions.substr(element, indexBrace + 1, |
elementLength - indexBrace - 2)) > 0) { |
// Illegal characters in comment |
return EMailSyntaxDiagnosis.ISEMAIL_BADCOMMENT_END; |
} |
element = PHPFunctions.substr(element, 0, indexBrace); |
elementLength = element.length(); |
} |
} |
// Remove any leading or trailing FWS around the element (inside any |
// comments) |
element = PHPFunctions.preg_replace("^" + FWS + "|" + FWS + "$", |
"", element); |
// What's left counts towards the maximum length for this part |
if (partLength > 0) |
partLength++; // for the dot |
partLength += element.length(); |
// Each dot-delimited component can be an atom or a quoted string |
// (because of the obs-local-part provision) |
if (PHPFunctions.preg_match("(?s)^\"(?:.)*\"$", element) > 0) { |
// Quoted-string tests: |
// |
// Remove any FWS |
element = PHPFunctions.preg_replace("(?<!\\\\)" + FWS, "", |
element); |
// My regex skillz aren't up to distinguishing between \" \\" |
// \\\" \\\\" etc. |
// So remove all \\ from the string first... |
element = PHPFunctions.preg_replace("\\\\\\\\", " ", element); |
if (PHPFunctions |
.preg_match( |
"(?<!\\\\|^)[\"\\r\\n\\x00](?!$)|\\\\\"$|\"\"", |
element) > 0) { |
// ", CR, LF and NUL must be escaped, "" is too short |
return EMailSyntaxDiagnosis.ISEMAIL_UNESCAPEDDELIM; |
} |
} else { |
// Unquoted string tests: |
// |
// Period (".") may...appear, but may not be used to start or |
// end the |
// local part, nor may two or more consecutive periods appear. |
// (http://tools.ietf.org/html/rfc3696#section-3) |
// |
// A zero-length element implies a period at the beginning or |
// end of the |
// local part, or two periods together. Either way it's not |
// allowed. |
if (element.equals("")) { |
// Dots in wrong place |
return EMailSyntaxDiagnosis.ISEMAIL_EMPTYELEMENT; |
} |
// Any ASCII graphic (printing) character other than the |
// at-sign ("@"), backslash, double quote, comma, or square |
// brackets may |
// appear without quoting. If any of that list of excluded |
// characters |
// are to appear, they must be quoted |
// (http://tools.ietf.org/html/rfc3696#section-3) |
// |
// Any excluded characters? i.e. 0x00-0x20, (, ), <, >, [, ], :, |
// ;, @, \, comma, period, " |
if (PHPFunctions.preg_match( |
"[\\x00-\\x20\\(\\)<>\\[\\]:;@\\\\,\\.\"]", element) > 0) { |
// These characters must be in a quoted string |
return EMailSyntaxDiagnosis.ISEMAIL_UNESCAPEDSPECIAL; |
} |
} |
} |
if (partLength > 64) { |
// Local part must be 64 characters or less |
return EMailSyntaxDiagnosis.ISEMAIL_LOCALTOOLONG; |
} |
// Now let's check the domain part... |
// The domain name can also be replaced by an IP address in square |
// brackets |
// (http://tools.ietf.org/html/rfc3696#section-3) |
// (http://tools.ietf.org/html/rfc5321#section-4.1.3) |
// (http://tools.ietf.org/html/rfc4291#section-2.2) |
if (PHPFunctions.preg_match("^\\[(.)+]$", domain) == 1) { |
// It's an address-literal |
String addressLiteral = PHPFunctions.substr(domain, 1, domain |
.length() - 2); |
String IPv6; |
int groupMax; |
// Extract IPv4 part from the end of the address-literal (if there |
// is one) |
String[] matchesIP = PHPFunctions |
.preg_match_to_array( |
"\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$", |
addressLiteral); |
if (matchesIP.length > 0) { |
int index = addressLiteral.lastIndexOf(matchesIP[0]); |
if (index == 0) { |
// Nothing there except a valid IPv4 address, so... |
return EMailSyntaxDiagnosis.ISEMAIL_VALID; |
} else { |
// Assume it's an attempt at a mixed address (IPv6 + IPv4) |
if (addressLiteral.charAt(index - 1) != ':') { |
// Character preceding IPv4 address must be ':' |
return EMailSyntaxDiagnosis.ISEMAIL_IPV4BADPREFIX; |
} |
if (!addressLiteral.startsWith("IPv6:")) { |
// RFC5321 section 4.1.3 |
return EMailSyntaxDiagnosis.ISEMAIL_IPV6BADPREFIXMIXED; |
} |
IPv6 = PHPFunctions.substr(addressLiteral, 5, |
(index == 7) ? 2 : index - 6); |
groupMax = 6; |
} |
} else { |
// It must be an attempt at pure IPv6 |
if (!addressLiteral.startsWith("IPv6:")) { |
// RFC5321 section 4.1.3 |
return EMailSyntaxDiagnosis.ISEMAIL_IPV6BADPREFIX; |
} |
IPv6 = PHPFunctions.substr(addressLiteral, 5); |
groupMax = 8; |
} |
String[][] matchesIP6 = PHPFunctions.preg_match_all( |
"^[0-9a-fA-F]{0,4}|\\:[0-9a-fA-F]{0,4}|(.)", IPv6); |
int groupCount = 0; |
if (matchesIP6.length > 0) { |
groupCount = matchesIP6[0].length; |
} // else: Undefined state (should never be reached) |
int index = IPv6.indexOf("::"); |
if (index == -1) { |
// We need exactly the right number of groups |
if (groupCount != groupMax) { |
// RFC5321 section 4.1.3 |
return EMailSyntaxDiagnosis.ISEMAIL_IPV6GROUPCOUNT; |
} |
} else { |
if (index != IPv6.lastIndexOf("::")) { |
// More than one '::' |
return EMailSyntaxDiagnosis.ISEMAIL_IPV6DOUBLEDOUBLECOLON; |
} |
groupMax = (index == 0 || index == (IPv6.length() - 2)) ? groupMax |
: groupMax - 1; |
if (groupCount > groupMax) { |
// Too many IPv6 groups in address |
return EMailSyntaxDiagnosis.ISEMAIL_IPV6TOOMANYGROUPS; |
} |
} |
// Daniel Marschall: For the Java translation, I optimized |
// the process. Instead of sorting the array (which needs |
// null-pointer checks and array-length checks) and then |
// checking element [0], I decided to directly check every |
// element. |
// Check for unmatched characters |
// array_multisort(matchesIP6[1], SORT_DESC); |
// if ($matchesIP6[1][0] !== '')) { |
// return EMailResultState.ISEMAIL_IPV6BADCHAR; |
// } |
// Check for unmatched characters |
if (matchesIP6.length > 1) { |
for (String s : matchesIP6[1]) { |
if ((s != null) && (!s.equals(""))) { |
return EMailSyntaxDiagnosis.ISEMAIL_IPV6BADCHAR; |
} |
} |
} // else: Undefined state (should never be reached) |
// It's a valid IPv6 address, so... |
return EMailSyntaxDiagnosis.ISEMAIL_VALID; |
} else { |
// It's a domain name... |
// The syntax of a legal Internet host name was specified in RFC-952 |
// One aspect of host name syntax is hereby changed: the |
// restriction on the first character is relaxed to allow either a |
// letter or a digit. |
// (http://tools.ietf.org/html/rfc1123#section-2.1) |
// |
// NB RFC 1123 updates RFC 1035, but this is not currently apparent |
// from reading RFC 1035. |
// |
// Most common applications, including email and the Web, will |
// generally not |
// permit...escaped strings |
// (http://tools.ietf.org/html/rfc3696#section-2) |
// |
// the better strategy has now become to make the |
// "at least one period" test, |
// to verify LDH conformance (including verification that the |
// apparent TLD name |
// is not all-numeric) |
// (http://tools.ietf.org/html/rfc3696#section-2) |
// |
// Characters outside the set of alphabetic characters, digits, and |
// hyphen MUST NOT appear in domain name |
// labels for SMTP clients or servers |
// (http://tools.ietf.org/html/rfc5321#section-4.1.2) |
// |
// RFC5321 precludes the use of a trailing dot in a domain name for |
// SMTP purposes |
// (http://tools.ietf.org/html/rfc5321#section-4.1.2) |
dotArray = PHPFunctions.preg_split( |
"(?m)\\.(?=(?:[^\\\"]*\\\"[^\\\"]*\\\")*(?![^\\\"]*\\\"))", |
domain); |
partLength = 0; |
// Since we use 'element' after the foreach |
// loop let's make sure it has a value |
String lastElement = ""; |
// revision 1.13: Line above added because PHPLint now checks for |
// Definitely Assigned Variables |
if (dotArray.length == 1) { |
// Mail host can't be a TLD (cite? What about localhost?) |
return EMailSyntaxDiagnosis.ISEMAIL_TLD; |
} |
for (String element : dotArray) { |
lastElement = element; |
// Remove any leading or trailing FWS |
element = PHPFunctions.preg_replace( |
"^" + FWS + "|" + FWS + "$", "", element); |
int elementLength = element.length(); |
// Each dot-delimited component must be of type atext |
// A zero-length element implies a period at the beginning or |
// end of the |
// local part, or two periods together. Either way it's not |
// allowed. |
if (elementLength == 0) { |
// Dots in wrong place |
return EMailSyntaxDiagnosis.ISEMAIL_DOMAINEMPTYELEMENT; |
} |
// revision 1.15: Speed up the test and get rid of |
// "unitialized string offset" notices from PHP |
// Then we need to remove all valid comments (i.e. those at the |
// start or end of the element |
if (element.charAt(0) == '(') { |
int indexBrace = element.indexOf(')'); |
if (indexBrace != -1) { |
if (PHPFunctions |
.preg_match("(?<!\\\\)[\\(\\)]", PHPFunctions |
.substr(element, 1, indexBrace - 1)) > 0) { |
// revision 1.17: Fixed name of constant (also |
// spotted by turboflash - thanks!) |
// Illegal characters in comment |
return EMailSyntaxDiagnosis.ISEMAIL_BADCOMMENT_START; |
} |
element = PHPFunctions.substr(element, indexBrace + 1, |
elementLength - indexBrace - 1); |
elementLength = element.length(); |
} |
} |
if (element.charAt(elementLength - 1) == ')') { |
int indexBrace = element.lastIndexOf('('); |
if (indexBrace != -1) { |
if (PHPFunctions.preg_match("(?<!\\\\)(?:[\\(\\)])", |
PHPFunctions.substr(element, indexBrace + 1, |
elementLength - indexBrace - 2)) > 0) { |
// revision 1.17: Fixed name of constant (also |
// spotted by turboflash - thanks!) |
// Illegal characters in comment |
return EMailSyntaxDiagnosis.ISEMAIL_BADCOMMENT_END; |
} |
element = PHPFunctions.substr(element, 0, indexBrace); |
elementLength = element.length(); |
} |
} |
// Remove any leading or trailing FWS around the element (inside |
// any comments) |
element = PHPFunctions.preg_replace( |
"^" + FWS + "|" + FWS + "$", "", element); |
// What's left counts towards the maximum length for this part |
if (partLength > 0) |
partLength++; // for the dot |
partLength += element.length(); |
// The DNS defines domain name syntax very generally -- a |
// string of labels each containing up to 63 8-bit octets, |
// separated by dots, and with a maximum total of 255 |
// octets. |
// (http://tools.ietf.org/html/rfc1123#section-6.1.3.5) |
if (elementLength > 63) { |
// Label must be 63 characters or less |
return EMailSyntaxDiagnosis.ISEMAIL_DOMAINELEMENTTOOLONG; |
} |
// Any ASCII graphic (printing) character other than the |
// at-sign ("@"), backslash, double quote, comma, or square |
// brackets may |
// appear without quoting. If any of that list of excluded |
// characters |
// are to appear, they must be quoted |
// (http://tools.ietf.org/html/rfc3696#section-3) |
// |
// If the hyphen is used, it is not permitted to appear at |
// either the beginning or end of a label. |
// (http://tools.ietf.org/html/rfc3696#section-2) |
// |
// Any excluded characters? i.e. 0x00-0x20, (, ), <, >, [, ], :, |
// ;, @, \, comma, period, " |
if (PHPFunctions.preg_match( |
"[\\x00-\\x20\\(\\)<>\\[\\]:;@\\\\,\\.\"]|^-|-$", |
element) > 0) { |
return EMailSyntaxDiagnosis.ISEMAIL_DOMAINBADCHAR; |
} |
} |
if (partLength > 255) { |
// Domain part must be 255 characters or less |
// (http://tools.ietf.org/html/rfc1123#section-6.1.3.5) |
return EMailSyntaxDiagnosis.ISEMAIL_DOMAINTOOLONG; |
} |
if (PHPFunctions.preg_match("^[0-9]+$", lastElement) > 0) { |
// TLD can't be all-numeric |
// (http://www.apps.ietf.org/rfc/rfc3696.html#sec-2) |
return EMailSyntaxDiagnosis.ISEMAIL_TLDNUMERIC; |
} |
// Check DNS? |
if (checkDNS) { |
try { |
if (!((DNSLookup.doLookup(domain, DNSType.A) > 0) || (DNSLookup |
.doLookup(domain, DNSType.MX) > 0))) { |
// Domain doesn't actually exist |
return EMailSyntaxDiagnosis.ISEMAIL_DOMAINNOTFOUND; |
} |
} catch (NamingException e) { |
return EMailSyntaxDiagnosis.ISEMAIL_DOMAINNOTFOUND; |
} |
} |
} |
// Eliminate all other factors, and the one which remains must be the |
// truth. (Sherlock Holmes, The Sign of Four) |
return EMailSyntaxDiagnosis.ISEMAIL_VALID; |
} |
/** |
* Replaces a char in a String |
* |
* @param s |
* The input string |
* @param pos |
* The position of the char to be replaced |
* @param c |
* The new char |
* @return The new String |
* @see http://www.rgagnon.com/javadetails/java-0030.html |
*/ |
public static String replaceCharAt(String s, int pos, char c) { |
return s.substring(0, pos) + c + s.substring(pos + 1); |
} |
private IsEMail() { |
} |
} |
Property changes: |
Added: svn:mime-type |
+text/plain |
\ No newline at end of property |
/ViaThinkSoft Java Utils/src/com/dominicsayers/isemail/DNSType.java |
---|
0,0 → 1,7 |
package com.dominicsayers.isemail; |
public enum DNSType { |
A, MX, NS, SOA, PTR, CNAME, AAAA, A6, SRV, NAPTR, TXT, ANY; |
} |
Property changes: |
Added: svn:mime-type |
+text/plain |
\ No newline at end of property |
/ViaThinkSoft Java Utils/src/com/dominicsayers/isemail/is_email.php |
---|
0,0 → 1,426 |
<?php |
/** |
* @package isemail |
* @author Dominic Sayers <dominic_sayers@hotmail.com> |
* @copyright 2010 Dominic Sayers |
* @license http://www.opensource.org/licenses/bsd-license.php BSD License |
* @link http://www.dominicsayers.com/isemail |
* @version 1.17 - Upper length limit corrected to 254 characters |
*/ |
/* |
Copyright (c) 2008-2010, Dominic Sayers |
All rights reserved. |
Redistribution and use in source and binary forms, with or without modification, |
are permitted provided that the following conditions are met: |
* Redistributions of source code must retain the above copyright notice, this |
list of conditions and the following disclaimer. |
* Redistributions in binary form must reproduce the above copyright notice, |
this list of conditions and the following disclaimer in the documentation |
and/or other materials provided with the distribution. |
* Neither the name of Dominic Sayers nor the names of its contributors may be |
used to endorse or promote products derived from this software without |
specific prior written permission. |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/*. |
require_module 'standard'; |
require_module 'pcre'; |
.*/ |
/*.mixed.*/ function is_email (/*.string.*/ $email, $checkDNS = false, $diagnose = false) { |
// Check that $email is a valid address. Read the following RFCs to understand the constraints: |
// (http://tools.ietf.org/html/rfc5322) |
// (http://tools.ietf.org/html/rfc3696) |
// (http://tools.ietf.org/html/rfc5321) |
// (http://tools.ietf.org/html/rfc4291#section-2.2) |
// (http://tools.ietf.org/html/rfc1123#section-2.1) |
if (!defined('ISEMAIL_VALID')) { |
define('ISEMAIL_VALID' , 0); |
define('ISEMAIL_TOOLONG' , 1); |
define('ISEMAIL_NOAT' , 2); |
define('ISEMAIL_NOLOCALPART' , 3); |
define('ISEMAIL_NODOMAIN' , 4); |
define('ISEMAIL_ZEROLENGTHELEMENT' , 5); |
define('ISEMAIL_BADCOMMENT_START' , 6); |
define('ISEMAIL_BADCOMMENT_END' , 7); |
define('ISEMAIL_UNESCAPEDDELIM' , 8); |
define('ISEMAIL_EMPTYELEMENT' , 9); |
define('ISEMAIL_UNESCAPEDSPECIAL' , 10); |
define('ISEMAIL_LOCALTOOLONG' , 11); |
define('ISEMAIL_IPV4BADPREFIX' , 12); |
define('ISEMAIL_IPV6BADPREFIXMIXED' , 13); |
define('ISEMAIL_IPV6BADPREFIX' , 14); |
define('ISEMAIL_IPV6GROUPCOUNT' , 15); |
define('ISEMAIL_IPV6DOUBLEDOUBLECOLON' , 16); |
define('ISEMAIL_IPV6BADCHAR' , 17); |
define('ISEMAIL_IPV6TOOMANYGROUPS' , 18); |
define('ISEMAIL_TLD' , 19); |
define('ISEMAIL_DOMAINEMPTYELEMENT' , 20); |
define('ISEMAIL_DOMAINELEMENTTOOLONG' , 21); |
define('ISEMAIL_DOMAINBADCHAR' , 22); |
define('ISEMAIL_DOMAINTOOLONG' , 23); |
define('ISEMAIL_TLDNUMERIC' , 24); |
define('ISEMAIL_DOMAINNOTFOUND' , 25); |
define('ISEMAIL_NOTDEFINED' , 99); |
} |
// the upper limit on address lengths should normally be considered to be 254 |
// (http://www.rfc-editor.org/errata_search.php?rfc=3696) |
// NB My erratum has now been verified by the IETF so the correct answer is 254 |
// |
// The maximum total length of a reverse-path or forward-path is 256 |
// characters (including the punctuation and element separators) |
// (http://tools.ietf.org/html/rfc5321#section-4.5.3.1.3) |
// NB There is a mandatory 2-character wrapper round the actual address |
$emailLength = strlen($email); |
// revision 1.17: Max length reduced to 254 (see above) |
if ($emailLength > 254) return $diagnose ? ISEMAIL_TOOLONG : false; // Too long |
// Contemporary email addresses consist of a "local part" separated from |
// a "domain part" (a fully-qualified domain name) by an at-sign ("@"). |
// (http://tools.ietf.org/html/rfc3696#section-3) |
$atIndex = strrpos($email,'@'); |
if ($atIndex === false) return $diagnose ? ISEMAIL_NOAT : false; // No at-sign |
if ($atIndex === 0) return $diagnose ? ISEMAIL_NOLOCALPART : false; // No local part |
if ($atIndex === $emailLength - 1) return $diagnose ? ISEMAIL_NODOMAIN : false; // No domain part |
// revision 1.14: Length test bug suggested by Andrew Campbell of Gloucester, MA |
// Sanitize comments |
// - remove nested comments, quotes and dots in comments |
// - remove parentheses and dots from quoted strings |
$braceDepth = 0; |
$inQuote = false; |
$escapeThisChar = false; |
for ($i = 0; $i < $emailLength; ++$i) { |
$char = $email[$i]; |
$replaceChar = false; |
if ($char === '\\') { |
$escapeThisChar = !$escapeThisChar; // Escape the next character? |
} else { |
switch ($char) { |
case '(': |
if ($escapeThisChar) { |
$replaceChar = true; |
} else { |
if ($inQuote) { |
$replaceChar = true; |
} else { |
if ($braceDepth++ > 0) $replaceChar = true; // Increment brace depth |
} |
} |
break; |
case ')': |
if ($escapeThisChar) { |
$replaceChar = true; |
} else { |
if ($inQuote) { |
$replaceChar = true; |
} else { |
if (--$braceDepth > 0) $replaceChar = true; // Decrement brace depth |
if ($braceDepth < 0) $braceDepth = 0; |
} |
} |
break; |
case '"': |
if ($escapeThisChar) { |
$replaceChar = true; |
} else { |
if ($braceDepth === 0) { |
$inQuote = !$inQuote; // Are we inside a quoted string? |
} else { |
$replaceChar = true; |
} |
} |
break; |
case '.': // Dots don't help us either |
if ($escapeThisChar) { |
$replaceChar = true; |
} else { |
if ($braceDepth > 0) $replaceChar = true; |
} |
break; |
default: |
} |
$escapeThisChar = false; |
// if ($replaceChar) $email[$i] = 'x'; // Replace the offending character with something harmless |
// revision 1.12: Line above replaced because PHPLint doesn't like that syntax |
if ($replaceChar) $email = (string) substr_replace($email, 'x', $i, 1); // Replace the offending character with something harmless |
} |
} |
$localPart = substr($email, 0, $atIndex); |
$domain = substr($email, $atIndex + 1); |
$FWS = "(?:(?:(?:[ \\t]*(?:\\r\\n))?[ \\t]+)|(?:[ \\t]+(?:(?:\\r\\n)[ \\t]+)*))"; // Folding white space |
// Let's check the local part for RFC compliance... |
// |
// local-part = dot-atom / quoted-string / obs-local-part |
// obs-local-part = word *("." word) |
// (http://tools.ietf.org/html/rfc5322#section-3.4.1) |
// |
// Problem: need to distinguish between "first.last" and "first"."last" |
// (i.e. one element or two). And I suck at regexes. |
$dotArray = /*. (array[int]string) .*/ preg_split('/\\.(?=(?:[^\\"]*\\"[^\\"]*\\")*(?![^\\"]*\\"))/m', $localPart); |
$partLength = 0; |
foreach ($dotArray as $element) { |
// Remove any leading or trailing FWS |
$element = preg_replace("/^$FWS|$FWS\$/", '', $element); |
$elementLength = strlen($element); |
if ($elementLength === 0) return $diagnose ? ISEMAIL_ZEROLENGTHELEMENT : false; // Can't have empty element (consecutive dots or dots at the start or end) |
// revision 1.15: Speed up the test and get rid of "unitialized string offset" notices from PHP |
// We need to remove any valid comments (i.e. those at the start or end of the element) |
if ($element[0] === '(') { |
$indexBrace = strpos($element, ')'); |
if ($indexBrace !== false) { |
if (preg_match('/(?<!\\\\)[\\(\\)]/', substr($element, 1, $indexBrace - 1)) > 0) { |
return $diagnose ? ISEMAIL_BADCOMMENT_START : false; // Illegal characters in comment |
} |
$element = substr($element, $indexBrace + 1, $elementLength - $indexBrace - 1); |
$elementLength = strlen($element); |
} |
} |
if ($element[$elementLength - 1] === ')') { |
$indexBrace = strrpos($element, '('); |
if ($indexBrace !== false) { |
if (preg_match('/(?<!\\\\)(?:[\\(\\)])/', substr($element, $indexBrace + 1, $elementLength - $indexBrace - 2)) > 0) { |
return $diagnose ? ISEMAIL_BADCOMMENT_END : false; // Illegal characters in comment |
} |
$element = substr($element, 0, $indexBrace); |
$elementLength = strlen($element); |
} |
} |
// Remove any leading or trailing FWS around the element (inside any comments) |
$element = preg_replace("/^$FWS|$FWS\$/", '', $element); |
// What's left counts towards the maximum length for this part |
if ($partLength > 0) $partLength++; // for the dot |
$partLength += strlen($element); |
// Each dot-delimited component can be an atom or a quoted string |
// (because of the obs-local-part provision) |
if (preg_match('/^"(?:.)*"$/s', $element) > 0) { |
// Quoted-string tests: |
// |
// Remove any FWS |
$element = preg_replace("/(?<!\\\\)$FWS/", '', $element); |
// My regex skillz aren't up to distinguishing between \" \\" \\\" \\\\" etc. |
// So remove all \\ from the string first... |
$element = preg_replace('/\\\\\\\\/', ' ', $element); |
if (preg_match('/(?<!\\\\|^)["\\r\\n\\x00](?!$)|\\\\"$|""/', $element) > 0) return $diagnose ? ISEMAIL_UNESCAPEDDELIM : false; // ", CR, LF and NUL must be escaped, "" is too short |
} else { |
// Unquoted string tests: |
// |
// Period (".") may...appear, but may not be used to start or end the |
// local part, nor may two or more consecutive periods appear. |
// (http://tools.ietf.org/html/rfc3696#section-3) |
// |
// A zero-length element implies a period at the beginning or end of the |
// local part, or two periods together. Either way it's not allowed. |
if ($element === '') return $diagnose ? ISEMAIL_EMPTYELEMENT : false; // Dots in wrong place |
// Any ASCII graphic (printing) character other than the |
// at-sign ("@"), backslash, double quote, comma, or square brackets may |
// appear without quoting. If any of that list of excluded characters |
// are to appear, they must be quoted |
// (http://tools.ietf.org/html/rfc3696#section-3) |
// |
// Any excluded characters? i.e. 0x00-0x20, (, ), <, >, [, ], :, ;, @, \, comma, period, " |
if (preg_match('/[\\x00-\\x20\\(\\)<>\\[\\]:;@\\\\,\\."]/', $element) > 0) return $diagnose ? ISEMAIL_UNESCAPEDSPECIAL : false; // These characters must be in a quoted string |
} |
} |
if ($partLength > 64) return $diagnose ? ISEMAIL_LOCALTOOLONG : false; // Local part must be 64 characters or less |
// Now let's check the domain part... |
// The domain name can also be replaced by an IP address in square brackets |
// (http://tools.ietf.org/html/rfc3696#section-3) |
// (http://tools.ietf.org/html/rfc5321#section-4.1.3) |
// (http://tools.ietf.org/html/rfc4291#section-2.2) |
if (preg_match('/^\\[(.)+]$/', $domain) === 1) { |
// It's an address-literal |
$addressLiteral = substr($domain, 1, strlen($domain) - 2); |
$matchesIP = array(); |
// Extract IPv4 part from the end of the address-literal (if there is one) |
if (preg_match('/\\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/', $addressLiteral, $matchesIP) > 0) { |
$index = strrpos($addressLiteral, $matchesIP[0]); |
if ($index === 0) { |
// Nothing there except a valid IPv4 address, so... |
return $diagnose ? ISEMAIL_VALID : true; |
} else { |
// Assume it's an attempt at a mixed address (IPv6 + IPv4) |
if ($addressLiteral[$index - 1] !== ':') return $diagnose ? ISEMAIL_IPV4BADPREFIX : false; // Character preceding IPv4 address must be ':' |
if (substr($addressLiteral, 0, 5) !== 'IPv6:') return $diagnose ? ISEMAIL_IPV6BADPREFIXMIXED : false; // RFC5321 section 4.1.3 |
$IPv6 = substr($addressLiteral, 5, ($index ===7) ? 2 : $index - 6); |
$groupMax = 6; |
} |
} else { |
// It must be an attempt at pure IPv6 |
if (substr($addressLiteral, 0, 5) !== 'IPv6:') return $diagnose ? ISEMAIL_IPV6BADPREFIX : false; // RFC5321 section 4.1.3 |
$IPv6 = substr($addressLiteral, 5); |
$groupMax = 8; |
} |
$groupCount = preg_match_all('/^[0-9a-fA-F]{0,4}|\\:[0-9a-fA-F]{0,4}|(.)/', $IPv6, $matchesIP); |
$index = strpos($IPv6,'::'); |
if ($index === false) { |
// We need exactly the right number of groups |
if ($groupCount !== $groupMax) return $diagnose ? ISEMAIL_IPV6GROUPCOUNT : false; // RFC5321 section 4.1.3 |
} else { |
if ($index !== strrpos($IPv6,'::')) return $diagnose ? ISEMAIL_IPV6DOUBLEDOUBLECOLON : false; // More than one '::' |
$groupMax = ($index === 0 || $index === (strlen($IPv6) - 2)) ? $groupMax : $groupMax - 1; |
if ($groupCount > $groupMax) return $diagnose ? ISEMAIL_IPV6TOOMANYGROUPS : false; // Too many IPv6 groups in address |
} |
// Check for unmatched characters |
array_multisort($matchesIP[1], SORT_DESC); |
if ($matchesIP[1][0] !== '') return $diagnose ? ISEMAIL_IPV6BADCHAR : false; // Illegal characters in address |
// It's a valid IPv6 address, so... |
return $diagnose ? ISEMAIL_VALID : true; |
} else { |
// It's a domain name... |
// The syntax of a legal Internet host name was specified in RFC-952 |
// One aspect of host name syntax is hereby changed: the |
// restriction on the first character is relaxed to allow either a |
// letter or a digit. |
// (http://tools.ietf.org/html/rfc1123#section-2.1) |
// |
// NB RFC 1123 updates RFC 1035, but this is not currently apparent from reading RFC 1035. |
// |
// Most common applications, including email and the Web, will generally not |
// permit...escaped strings |
// (http://tools.ietf.org/html/rfc3696#section-2) |
// |
// the better strategy has now become to make the "at least one period" test, |
// to verify LDH conformance (including verification that the apparent TLD name |
// is not all-numeric) |
// (http://tools.ietf.org/html/rfc3696#section-2) |
// |
// Characters outside the set of alphabetic characters, digits, and hyphen MUST NOT appear in domain name |
// labels for SMTP clients or servers |
// (http://tools.ietf.org/html/rfc5321#section-4.1.2) |
// |
// RFC5321 precludes the use of a trailing dot in a domain name for SMTP purposes |
// (http://tools.ietf.org/html/rfc5321#section-4.1.2) |
$dotArray = /*. (array[int]string) .*/ preg_split('/\\.(?=(?:[^\\"]*\\"[^\\"]*\\")*(?![^\\"]*\\"))/m', $domain); |
$partLength = 0; |
$element = ''; // Since we use $element after the foreach loop let's make sure it has a value |
// revision 1.13: Line above added because PHPLint now checks for Definitely Assigned Variables |
if (count($dotArray) === 1) return $diagnose ? ISEMAIL_TLD : false; // Mail host can't be a TLD (cite? What about localhost?) |
foreach ($dotArray as $element) { |
// Remove any leading or trailing FWS |
$element = preg_replace("/^$FWS|$FWS\$/", '', $element); |
$elementLength = strlen($element); |
// Each dot-delimited component must be of type atext |
// A zero-length element implies a period at the beginning or end of the |
// local part, or two periods together. Either way it's not allowed. |
if ($elementLength === 0) return $diagnose ? ISEMAIL_DOMAINEMPTYELEMENT : false; // Dots in wrong place |
// revision 1.15: Speed up the test and get rid of "unitialized string offset" notices from PHP |
// Then we need to remove all valid comments (i.e. those at the start or end of the element |
if ($element[0] === '(') { |
$indexBrace = strpos($element, ')'); |
if ($indexBrace !== false) { |
if (preg_match('/(?<!\\\\)[\\(\\)]/', substr($element, 1, $indexBrace - 1)) > 0) { |
// revision 1.17: Fixed name of constant (also spotted by turboflash - thanks!) |
return $diagnose ? ISEMAIL_BADCOMMENT_START : false; // Illegal characters in comment |
} |
$element = substr($element, $indexBrace + 1, $elementLength - $indexBrace - 1); |
$elementLength = strlen($element); |
} |
} |
if ($element[$elementLength - 1] === ')') { |
$indexBrace = strrpos($element, '('); |
if ($indexBrace !== false) { |
if (preg_match('/(?<!\\\\)(?:[\\(\\)])/', substr($element, $indexBrace + 1, $elementLength - $indexBrace - 2)) > 0) |
// revision 1.17: Fixed name of constant (also spotted by turboflash - thanks!) |
return $diagnose ? ISEMAIL_BADCOMMENT_END : false; // Illegal characters in comment |
$element = substr($element, 0, $indexBrace); |
$elementLength = strlen($element); |
} |
} |
// Remove any leading or trailing FWS around the element (inside any comments) |
$element = preg_replace("/^$FWS|$FWS\$/", '', $element); |
// What's left counts towards the maximum length for this part |
if ($partLength > 0) $partLength++; // for the dot |
$partLength += strlen($element); |
// The DNS defines domain name syntax very generally -- a |
// string of labels each containing up to 63 8-bit octets, |
// separated by dots, and with a maximum total of 255 |
// octets. |
// (http://tools.ietf.org/html/rfc1123#section-6.1.3.5) |
if ($elementLength > 63) return $diagnose ? ISEMAIL_DOMAINELEMENTTOOLONG : false; // Label must be 63 characters or less |
// Any ASCII graphic (printing) character other than the |
// at-sign ("@"), backslash, double quote, comma, or square brackets may |
// appear without quoting. If any of that list of excluded characters |
// are to appear, they must be quoted |
// (http://tools.ietf.org/html/rfc3696#section-3) |
// |
// If the hyphen is used, it is not permitted to appear at |
// either the beginning or end of a label. |
// (http://tools.ietf.org/html/rfc3696#section-2) |
// |
// Any excluded characters? i.e. 0x00-0x20, (, ), <, >, [, ], :, ;, @, \, comma, period, " |
if (preg_match('/[\\x00-\\x20\\(\\)<>\\[\\]:;@\\\\,\\."]|^-|-$/', $element) > 0) { |
return $diagnose ? ISEMAIL_DOMAINBADCHAR : false; |
} |
} |
if ($partLength > 255) return $diagnose ? ISEMAIL_DOMAINTOOLONG : false; // Domain part must be 255 characters or less (http://tools.ietf.org/html/rfc1123#section-6.1.3.5) |
if (preg_match('/^[0-9]+$/', $element) > 0) return $diagnose ? ISEMAIL_TLDNUMERIC : false; // TLD can't be all-numeric (http://www.apps.ietf.org/rfc/rfc3696.html#sec-2) |
// Check DNS? |
if ($checkDNS && function_exists('checkdnsrr')) { |
if (!(checkdnsrr($domain, 'A') || checkdnsrr($domain, 'MX'))) { |
return $diagnose ? ISEMAIL_DOMAINNOTFOUND : false; // Domain doesn't actually exist |
} |
} |
} |
// Eliminate all other factors, and the one which remains must be the truth. |
// (Sherlock Holmes, The Sign of Four) |
return $diagnose ? ISEMAIL_VALID : true; |
} |
?> |
/ViaThinkSoft Java Utils/src/com/dominicsayers/isemail/DNSLookup.java |
---|
0,0 → 1,28 |
package com.dominicsayers.isemail; |
import java.util.Hashtable; |
import javax.naming.*; |
import javax.naming.directory.*; |
// Source: http://www.rgagnon.com/javadetails/java-0452.html |
// Modified |
public class DNSLookup { |
public static int doLookup(String hostName, DNSType type) |
throws NamingException { |
Hashtable<String, String> env = new Hashtable<String, String>(); |
env.put("java.naming.factory.initial", |
"com.sun.jndi.dns.DnsContextFactory"); |
DirContext ictx = new InitialDirContext(env); |
Attributes attrs = ictx.getAttributes(hostName, new String[] { type |
.toString() }); |
Attribute attr = attrs.get(type.toString()); |
if (attr == null) { |
return 0; |
} |
return attr.size(); |
} |
private DNSLookup() { |
} |
} |
Property changes: |
Added: svn:mime-type |
+text/plain |
\ No newline at end of property |
/ViaThinkSoft Java Utils/src/com/mindprod/bulk/EmailSyntaxValidator.java |
---|
0,0 → 1,346 |
/* |
* @(#)EmailSyntaxValidator.java |
* |
* Summary: Validate syntax of email addresses. |
* |
* Copyright: (c) 2002-2010 Roedy Green, Canadian Mind Products, http://mindprod.com |
* |
* Licence: This software may be copied and used freely for any purpose but military. |
* http://mindprod.com/contact/nonmil.html |
* |
* Requires: JDK 1.5+ |
* |
* Created with: IntelliJ IDEA IDE. |
* |
* Version History: |
* 1.7 2007-08-21 |
*/ |
package com.mindprod.bulk; |
// Download newest version here: |
// http://mindprod.com/products1.html#BULK |
// SVN: |
// http://wush.net/svn/mindprod/com/mindprod/bulk/EmailSyntaxValidator.java |
// TODO: E-Mail-Aufbereiter... Puny, Trim |
// TODO: BAD TLDS + PSEUDO (TOR: EXIT ETC) |
// TODO: Awaiting bulk comit |
// CHANGELOG BY DANIEL MARSCHALL |
// |
//Added ccTLDs |
// |
//.ax = Aland Islands |
//.eu = European Union |
//.me = Montenegro |
//.rs = Serbia |
//.su = Soviet Union (being phased out) |
//.tl = Timor-Leste |
// |
//Deleted ccTLDs |
// |
//.bv = Bouvet Island [Allocated/unused] |
//.eh = Western Sahara [Reserved/unassigned] |
//.fx = UNKNOWN |
//.gb = United Kingdom [Allocated/unused] |
//.pm = Saint Pierre and Miquelon [Allocated/unused] |
//.sj = Svalbard and Jan Mayen [Allocated/unused] |
//.so = Somalia [Allocated/unused] |
//.um = United States Minor Outlying Islands [Reserved/unassigned] |
//.yt = Mayotte [Allocated/unused] |
//.yu = Yugoslavia [Deleted/retired] |
// |
//Added BAD TLDs |
// |
//.example (RFC 2606) |
//.localhost (RFC 2606) |
//.test (RFC 2606) |
// |
//Added official TLDs |
// |
//.arpa (infrastructure TLD) |
//.tel (sponsored TLD) -- official TLD or rare TLD? |
//.mobi (sponsored TLD) -- official TLD or rare TLD? |
//.jobs (sponsored TLD) -- official TLD or rare TLD? |
//.cat (sponsored TLD) -- official TLD or rare TLD? |
// |
//Other changes |
// |
//* Commented out unused debugging stuff |
//* Removed main procedure and syso import |
import javax.mail.internet.AddressException; |
import javax.mail.internet.InternetAddress; |
import java.util.Arrays; |
import java.util.HashSet; |
import java.util.Locale; |
import java.util.regex.Matcher; |
import java.util.regex.Pattern; |
/** |
* Validate syntax of email addresses. |
* <p/> |
* Does not probe to see if mailserver exists in DNS or online. See MailProber |
* for that. See ValidateEmailFile for an example of how to use this class. |
* |
* @author Roedy Green, Canadian Mind Products |
* @version 1.7 2007-08-21 |
* @since 2002 |
*/ |
// TODO: @version check validity of & in first part of email address. Appears in |
// practice. |
public final class EmailSyntaxValidator { |
// ------------------------------ CONSTANTS ------------------------------ |
/** |
* True if want extra debugging output. |
*/ |
// @SuppressWarnings( { "UnusedDeclaration" }) |
// private static final boolean DEBUGGING = false; |
/** |
* Country where this program is running. |
*/ |
private static final String THIS_COUNTRY = Locale.getDefault().getCountry() |
.toLowerCase(); |
/** |
* Bad top level domains -- ones never valid. |
*/ |
private static final HashSet<String> BAD_TLDS = hmaker(new String[] { |
"invalid", "nowhere", "noone", "test", "example", "localhost", }); |
/** |
* Top level domains for countries. |
*/ |
private static final HashSet<String> NATIONAL_TLDS = hmaker(new String[] { |
"ac", "ad", "ae", "af", "ag", "ai", "al", "am", "an", "ao", "aq", |
"ar", "as", "at", "au", "aw", "ax", "az", "ba", "bb", "bd", "be", |
"bf", "bg", "bh", "bi", "bj", "bm", "bn", "bo", "br", "bs", "bt", |
"bw", "by", "bz", "ca", "cc", "cd", "cf", "cg", "ch", "ci", "ck", |
"cl", "cm", "cn", "co", "cr", "cu", "cv", "cx", "cy", "cz", "de", |
"dj", "dk", "dm", "do", "dz", "ec", "ee", "eg", "er", "es", "et", |
"eu", "eu", "fi", "fj", "fk", "fm", "fo", "fr", "ga", "gd", "ge", |
"gf", "gg", "gh", "gi", "gl", "gm", "gn", "gp", "gq", "gr", "gs", |
"gt", "gu", "gw", "gy", "hk", "hm", "hn", "hr", "ht", "hu", "id", |
"ie", "il", "im", "in", "io", "iq", "ir", "is", "it", "je", "jm", |
"jo", "jp", "ke", "kg", "kh", "ki", "km", "kn", "kp", "kr", "kw", |
"ky", "kz", "la", "lb", "lc", "li", "lk", "lr", "ls", "lt", "lu", |
"lv", "ly", "ma", "mc", "md", "me", "mg", "mh", "mk", "ml", "mm", |
"mn", "mo", "mp", "mq", "mr", "ms", "mt", "mu", "mv", "mw", "mx", |
"my", "mz", "na", "nc", "ne", "nf", "ng", "ni", "nl", "no", "np", |
"nr", "nu", "nz", "om", "pa", "pe", "pf", "pg", "ph", "pk", "pl", |
"pn", "pr", "ps", "pt", "pw", "py", "qa", "re", "ro", "rs", "ru", |
"rw", "sa", "sb", "sc", "sd", "se", "sg", "sh", "si", "sk", "sl", |
"sm", "sn", "sr", "st", "su", "sv", "sy", "sz", "tc", "td", "tf", |
"tg", "th", "tj", "tk", "tl", "tm", "tn", "to", "tp", "tr", "tt", |
"tv", "tw", "tz", "ua", "ug", "uk", "us", "uy", "uz", "va", "vc", |
"ve", "vg", "vi", "vn", "vu", "wf", "ws", "ye", "za", "zm", "zw", }); |
/** |
* Official top level domains. |
*/ |
private static final HashSet<String> OFFICIAL_TLDS = hmaker(new String[] { |
"aero", "biz", "coop", "com", "edu", "gov", "info", "mil", |
"museum", "name", "net", "org", "pro", "tel", "mobi", "jobs", |
"cat", "arpa", }); |
/** |
* Rarely used top level domains |
*/ |
private static final HashSet<String> RARE_TLDS = hmaker(new String[] { |
"cam", "mp3", "agent", "art", "arts", "asia", "auction", "aus", |
"bank", "cam", "chat", "church", "club", "corp", "dds", "design", |
"dns2go", "e", "email", "exp", "fam", "family", "faq", "fed", |
"film", "firm", "free", "fun", "g", "game", "games", "gay", "ger", |
"globe", "gmbh", "golf", "gov", "help", "hola", "i", "inc", "int", |
"jpn", "k12", "kids", "law", "learn", "llb", "llc", "llp", "lnx", |
"love", "ltd", "mag", "mail", "med", "media", "mp3", "netz", "nic", |
"nom", "npo", "per", "pol", "prices", "radio", "rsc", "school", |
"scifi", "sea", "service", "sex", "shop", "sky", "soc", "space", |
"sport", "tech", "tour", "travel", "usvi", "video", "web", "wine", |
"wir", "wired", "zine", "zoo", }); |
/** |
* regex to allow dots anywhere, but not at start of domain name, no + |
*/ |
private static final Pattern p3 = Pattern |
.compile("[a-z0-9\\-_\\.]++@[a-z0-9\\-_]++(\\.[a-z0-9\\-_]++)++"); |
/** |
* regex IP style names, no + |
*/ |
private static final Pattern p4 = Pattern |
.compile("[a-z0-9\\-_]++(\\.[a-z0-9\\-_]++)*@\\[([0-9]{1,3}\\.){3}[0-9]{1,3}\\]"); |
/** |
* regex to allow - _ dots in name, no + |
*/ |
private static final Pattern p5 = Pattern |
.compile("[a-z0-9\\-_]++(\\.[a-z0-9\\-_]++)*@[a-z0-9\\-_]++(\\.[a-z0-9\\-_]++)++"); |
/** |
* regex to allow _ - in name, lead and trailing ones are filtered later, no |
* +. |
*/ |
private static final Pattern p9 = Pattern |
.compile("[a-z0-9\\-_]++@[a-z0-9\\-_]++(\\.[a-z0-9\\-_]++)++"); |
/** |
* regex to split into fields |
*/ |
private static final Pattern splitter = Pattern.compile("[@\\.]"); |
// -------------------------- PUBLIC STATIC METHODS |
// -------------------------- |
/** |
* Check how likely an email address is to be valid. The higher the number |
* returned, the more likely the address is valid. This method does not |
* probe the internet in any way to see if the corresponding mail server or |
* domain exists. |
* |
* @param email |
* bare computer email address. e.g. roedyg@mindprod.com No |
* "Roedy Green" <roedyg@mindprod.com> style addresses. No local |
* addresses, e.g. roedy. |
* |
* @return <ul> |
* <li>0 = email address is definitely malformed, e.g. missing |
* @. ends in .invalid</li> <li>1 = address does not meet one of the valid |
* patterns below. It still might be ok according to some obscure rule in |
* RFC 822 Java InternetAddress accepts it as valid.</li> <li>2 = unknown |
* top level domain.</li> <li>3 = dots at beginning or end, doubled in |
* name.</li> <li>4 = address of form xxx@[209.139.205.2] using IP</li> |
* <li>5 = address of form xxx.xxx.xxx@xxx.xxx.xxx Dots _ or - in first |
* part of name</li> <li>6 = addreess of form xxx@xxx.xxx.xxx rare, but |
* known, domain</li> <li>7 = address of form xxx@xxx.xxx.ca or any |
* national suffix.</li> <li>8 = address of form xxx@xxx.xxx.xx the |
* matching this national suffix, e.g. .ca in Canada, .de in Germany</li> |
* <li>9 = address of form xxx@xxx.xxx.com .org .net .edu .gov .biz -- |
* official domains</li> |
* </ul> |
*/ |
public static int howValid(String email) { |
if (email == null) { |
return 0; |
} |
email = email.trim().toLowerCase(); |
int dotPlace = email.lastIndexOf('.'); |
if (0 < dotPlace && dotPlace < email.length() - 1) { |
String tld = email.substring(dotPlace + 1); |
if (BAD_TLDS.contains(tld)) { |
/* deliberate invalid address */ |
return 0; |
} |
// make sure none of fragments start or end in _ or - |
String[] fragments = splitter.split(email); |
boolean clean = true; |
for (String fragment : fragments) { |
if (fragment.startsWith("_") || fragment.endsWith("_") |
|| fragment.startsWith("-") || fragment.endsWith("-")) { |
clean = false; |
break; |
} |
}// end for |
if (clean) { |
Matcher m9 = p9.matcher(email); |
if (m9.matches()) { |
if (OFFICIAL_TLDS.contains(tld)) { |
return 9; |
} else if (THIS_COUNTRY.equals(tld)) { |
return 8; |
} else if (NATIONAL_TLDS.contains(tld)) { |
return 7; |
} else if (RARE_TLDS.contains(tld)) { |
return 6; |
} else { |
// TODO: Why is that 3 and not 2? |
return 3;/* unknown tld */ |
} |
} |
// allow dots in name |
Matcher m5 = p5.matcher(email); |
if (m5.matches()) { |
if (OFFICIAL_TLDS.contains(tld)) { |
return 5; |
} else if (THIS_COUNTRY.equals(tld)) { |
return 5; |
} else if (NATIONAL_TLDS.contains(tld)) { |
return 5; |
} else if (RARE_TLDS.contains(tld)) { |
return 5; |
} else { |
return 2;/* unknown tld */ |
} |
} |
// IP |
Matcher m4 = p4.matcher(email); |
if (m4.matches()) { |
return 4;/* can't tell TLD */ |
} |
// allow even lead/trail dots in name, except at start of domain |
Matcher m3 = p3.matcher(email); |
if (m3.matches()) { |
if (OFFICIAL_TLDS.contains(tld)) { |
return 3; |
} else if (THIS_COUNTRY.equals(tld)) { |
return 3; |
} else if (NATIONAL_TLDS.contains(tld)) { |
return 3; |
} else if (RARE_TLDS.contains(tld)) { |
return 3; |
} else { |
return 2;/* unknown domain */ |
} |
} |
}// end if clean |
} |
// allow even unclean addresses, and addresses without a TLD to have a |
// whack at passing RFC:822 |
try { |
/* |
* see if InternetAddress likes it, it follows RFC:822. It will |
* names without domains though. |
*/ |
InternetAddress.parse(email, true/* strict */); |
// it liked it, no exception happened. Seems very sloppy. |
return 1; |
} catch (AddressException e) { |
// it did not like it |
return 0; |
} |
} |
// -------------------------- STATIC METHODS -------------------------- |
/** |
* build a HashSet from a array of String literals. |
* |
* @param list |
* array of strings |
* |
* @return HashSet you can use to test if a string is in the set. |
*/ |
private static HashSet<String> hmaker(String[] list) { |
HashSet<String> map = new HashSet<String>(Math.max( |
(int) (list.length / .75f) + 1, 16)); |
map.addAll(Arrays.asList(list)); |
return map; |
} |
// --------------------------- main() method --------------------------- |
/** |
* main debugging harness. |
* |
* @param args |
* not used |
*/ |
// public static void main(String[] args) { |
// out.println(howValid("kellizer@.hotmail.com")); |
// } |
} |
Property changes: |
Added: svn:mime-type |
+text/plain |
\ No newline at end of property |