{"id":180,"date":"2005-01-08T14:36:02","date_gmt":"2005-01-08T13:36:02","guid":{"rendered":"http:\/\/frenchfragfactory.net\/ozh\/archives\/2005\/01\/08\/deleting-all-mails-with-a-simple-perl-script\/"},"modified":"2007-05-09T23:39:28","modified_gmt":"2007-05-09T21:39:28","slug":"deleting-all-mails-with-a-simple-perl-script","status":"publish","type":"post","link":"https:\/\/planetozh.com\/blog\/2005\/01\/deleting-all-mails-with-a-simple-perl-script\/","title":{"rendered":"Deleting all mails with a simple Perl script"},"content":{"rendered":"<p>I have a few alternative mail accounts, mostly used when I need to register with a site I don&#39;t trust and thus when I&#39;m expecting spam. Checking last night, I noticed that 3 accounts were filled up with a grand total of 3500 spams, so I wrote a small Perl script, using <a href=\"http:\/\/search.cpan.org\/~gbarr\/libnet-1.19\/Net\/POP3.pm\">Net::POP3<\/a>, to delete all mails in an account.<br \/>\n<!--more--><\/p>\n<div id=\"ig-sh-1\" class=\"syntax_hilite\">\n\n\t\t<div class=\"toolbar\">\n\n\t\t<div class=\"view-different-container\">\n\t\t\t\t\t\t<a href=\"#\" class=\"view-different\">&lt; View <span>plain text<\/span> &gt;<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t<div class=\"language-name\">perl<\/div>\n\n\t\t\n\t\t<br clear=\"both\">\n\n\t<\/div>\n\t\n\t<div class=\"code\">\n\t\t<ol class=\"perl\" style=\"font-family:monospace\"><li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #666666;font-style: italic\">#!\/usr\/bin\/perl<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #000000;font-weight: bold\">use<\/span> Net<span style=\"color: #339933\">::<\/span><span style=\"color: #006600\">POP3<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #b1b100\">if<\/span> <span style=\"color: #009900\">&#040;<\/span><span style=\"color: #339933\">@<\/span><span style=\"color: #000000;font-weight: bold\">ARGV<\/span> <span style=\"color: #339933\">&lt;<\/span> <span style=\"color: #cc66cc\">2<\/span><span style=\"color: #009900\">&#041;<\/span> <span style=\"color: #009900\">&#123;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; <span style=\"color: #000066\">print<\/span> <span style=\"color: #ff0000\">&quot;Usage : $0 &lt;login&gt; &lt;pass&gt;<span style=\"color: #000099;font-weight: bold\">\\n<\/span>&quot;<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; <span style=\"color: #000066\">exit<\/span> <span style=\"color: #cc66cc\">0<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #009900\">&#125;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #000066\">print<\/span> <span style=\"color: #ff0000\">&quot;Going to delete ALL mail from account $ARGV[0] ! ctrl-c to abort<span style=\"color: #000099;font-weight: bold\">\\n<\/span>&quot;<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #000066\">sleep<\/span> <span style=\"color: #cc66cc\">3<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #0000ff\">$pop<\/span> <span style=\"color: #339933\">=<\/span> Net<span style=\"color: #339933\">::<\/span><span style=\"color: #006600\">POP3<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #000000;font-weight: bold\">new<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #ff0000\">'pop.free.fr'<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #000066\">die<\/span> <span style=\"color: #ff0000\">&quot;Couldn\u00e2\u20ac\u2122t log on to server&quot;<\/span> <span style=\"color: #b1b100\">unless<\/span> <span style=\"color: #0000ff\">$pop<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #0000ff\">$total<\/span> <span style=\"color: #339933\">=<\/span> <span style=\"color: #0000ff\">$pop<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #006600\">login<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">$ARGV<\/span><span style=\"color: #009900\">&#091;<\/span><span style=\"color: #cc66cc\">0<\/span><span style=\"color: #009900\">&#093;<\/span><span style=\"color: #339933\">,<\/span><span style=\"color: #0000ff\">$ARGV<\/span><span style=\"color: #009900\">&#091;<\/span><span style=\"color: #cc66cc\">1<\/span><span style=\"color: #009900\">&#093;<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #000066\">die<\/span> <span style=\"color: #ff0000\">&quot;No mails or couldn\u00e2\u20ac\u2122t connect !&quot;<\/span> <span style=\"color: #b1b100\">unless<\/span> <span style=\"color: #0000ff\">$total<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #000066\">print<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #ff0000\">&quot;Deleting $total mails ...<span style=\"color: #000099;font-weight: bold\">\\n<\/span>&quot;<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #b1b100\">for<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">$i<\/span> <span style=\"color: #339933\">=<\/span> <span style=\"color: #cc66cc\">0<\/span><span style=\"color: #339933\">;<\/span> <span style=\"color: #0000ff\">$i<\/span><span style=\"color: #339933\">&lt;<\/span><span style=\"color: #0000ff\">$tot<\/span><span style=\"color: #339933\">;<\/span> <span style=\"color: #0000ff\">$i<\/span><span style=\"color: #339933\">++<\/span><span style=\"color: #009900\">&#041;<\/span> <span style=\"color: #009900\">&#123;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp; &nbsp; <span style=\"color: #0000ff\">$pop<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #000066\">delete<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #0000ff\">$i<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #009900\">&#125;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #0000ff\">$pop<\/span><span style=\"color: #339933\">-&gt;<\/span><span style=\"color: #006600\">quit<\/span><span style=\"color: #009900\">&#040;<\/span><span style=\"color: #009900\">&#041;<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\">&nbsp;<\/div><\/li>\n<li style=\"font-weight: normal;vertical-align:top\"><div style=\"font: normal normal 1em\/1.2em monospace;margin:0;padding:0;background:none;vertical-align:top\"><span style=\"color: #000066\">exit<\/span> <span style=\"color: #cc66cc\">1<\/span><span style=\"color: #339933\">;<\/span><\/div><\/li>\n<\/ol>\t<\/div>\n\n<\/div>\n\n","protected":false},"excerpt":{"rendered":"<p>Spammed ? Delete all mails in a click !<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[2,9,27],"class_list":["post-180","post","type-post","status-publish","format-standard","hentry","tag-code","tag-perl","tag-spam"],"_links":{"self":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/posts\/180","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/comments?post=180"}],"version-history":[{"count":0,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/posts\/180\/revisions"}],"wp:attachment":[{"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/media?parent=180"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/categories?post=180"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/planetozh.com\/blog\/wp-json\/wp\/v2\/tags?post=180"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}