<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>KodeGeek &#187; gmail</title>
	<atom:link href="http://kodegeek.com/blog/tag/gmail/feed/" rel="self" type="application/rss+xml" />
	<link>http://kodegeek.com/blog</link>
	<description>Programación, fitness, interés geek</description>
	<lastBuildDate>Sun, 05 Feb 2012 19:12:12 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>OSX Postfix Relay &#8211; envio de correos usando OSX y Postfix</title>
		<link>http://kodegeek.com/blog/2010/02/15/osx-postfix-relay-envio-de-correos-usando-osx-y-postfix/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=osx-postfix-relay-envio-de-correos-usando-osx-y-postfix</link>
		<comments>http://kodegeek.com/blog/2010/02/15/osx-postfix-relay-envio-de-correos-usando-osx-y-postfix/#comments</comments>
		<pubDate>Tue, 16 Feb 2010 00:31:45 +0000</pubDate>
		<dc:creator>josevnz</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[cablevision]]></category>
		<category><![CDATA[gmail]]></category>
		<category><![CDATA[postfix]]></category>

		<guid isPermaLink="false">http://kodegeek.com/blog/?p=2255</guid>
		<description><![CDATA[Todo este lío comenzó cuando me tocó configurar a mi Mac Mini (la cual es mi servidor headless estos días) para que poder enviar correos desde PHP: < ?php $to = "josevnz@mydomain.com"; $subject = "Test from tepuyes server!"; $body = "Hi,\n\nHow are you?"; if (mail($to, $subject, $body)) { echo(" Message successfully sent!"); } else { [...]]]></description>
			<content:encoded><![CDATA[<p>Todo este lío comenzó cuando me tocó configurar a mi Mac Mini (la cual es mi servidor headless estos días) para que poder enviar correos desde PHP:<br />
<code><br />
< ?php<br />
$to = "josevnz@mydomain.com";<br />
$subject = "Test from tepuyes server!";<br />
$body = "Hi,\n\nHow are you?";<br />
if (mail($to, $subject, $body)) {<br />
  echo("
<p>Message successfully sent!");<br />
 } else {<br />
  echo("
<p>Message delivery failed...</p>
<p>");<br />
 }<br />
?><br />
</code></p>
<p><strong>Odio a PHP</strong>. En Windows se puede especificar un servidor SMTP pero en UNIX este lenguaje utiliza Sendmail o lo que haya por debajo. Se puede utilizar<a href="http://pear.php.net/package/Mail"> Pear PHP mail</a> pero eso implica que tengo que cambiar mi código.</p>
<p>Ahhh, nada como <a href="http://kodegeek.com/blog/2008/12/28/%C2%BFcomo-borrar-40000-correos-en-gmail-facil-usando-javamail-e-imap/">JavaMail</a> para estos casos <img src='http://kodegeek.com/blog/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>Bueno, volviendo al tema que nos interesa,  los correos nunca salían de la cola. Y es que mi proveedor de Internet, <a href="http://www.gadgetell.com/tech/comment/a-rant-and-rave-about-optimum-online/">Cablevision, bloquea cualquier conexión a servidores de correo en los puertos 25</a> en un intento por detener el SPAM.</p>
<p>Intenté utilizar el servidor de correo que ellos sugieren (mail.optonline.net) pero este se quejaba que mi maquina no tenia un registro A en DNS que pudiera ser resuelto (sorpresa, es una máquina detrás del firewall). Traté de utilizar el servidor de correo de la compañia que hospeda a<a href="http://help.godaddy.com/article/363"> mi dominio en DNS usando autenticación</a>, y para ello configuré lo siguiente en el archivo <strong>/etc/postfix/main.conf</strong>:<br />
<code><br />
relayhost = smtpout.secureserver.net:3535<br />
smtp_sasl_auth_enable = yes<br />
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd<br />
smtp_sasl_security_options = noanonymous<br />
smtp_tls_security_level = may<br />
smtp_tls_CApath = /etc/postfix/certs<br />
smtp_tls_session_cache_database = btree:/etc/postfix/smtp_scache<br />
smtp_tls_session_cache_timeout = 3600s<br />
smtp_tls_loglevel = 1<br />
tls_random_source = dev:/dev/urandom<br />
</code></p>
<p>Y en el archivo <strong>/etc/postfix/sasl_passwd</strong> pusé mi usuario y clave con el cual voy a hacer el relay:</p>
<p><code><br />
smtpout.secureserver.net: josevnz@mydomain.com:mycoolpassword<br />
</code></p>
<p>Necesitamos usar un certificado digital. La gente de Verisign ofrece uno el cual podemos bajar desde aqui: <a href="https://www.verisign.com/support/roots.html">https://www.verisign.com/support/roots.html</a> (en este caso yo lo copié en <strong>/private/tmp/roots.zip</strong>)</p>
<p>Luego un poco de carpintería ya que hay que decirle a Postfix que use los nuevos parámetros:</p>
<p><code><br />
sudo mv /private/tmp/roots.zip /etc/postfix/certs<br />
sudo unzip -j roots.zip<br />
sudo openssl x509 -inform der -in thawte\ Primary\ Root\ CA\ -\ G2_ECC.cer -out  thawte\ Primary\ Root\ CA\ -\ G2_ECC.pem<br />
sudo c_rehash /etc/postfix/certs<br />
sudo postmap /etc/postfix/sasl_passwd<br />
sudo postfix stop<br />
sudo postfix start<br />
</code></p>
<p>Sin embargo el servidor de &#8216;relay&#8217; que decidí utilizar tiene problemas de DNS:<br />
<code><br />
Tepuyes-Server:certs josevnz$ sudo mailq<br />
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------<br />
41D3C1201BB      348 Mon Feb 15 18:12:43  josevnz@Tepuyes-Server.local<br />
(Host or domain name not found. <strong>Name service error for name=smtpout.secureserver.net type=MX: Host not found, try again</strong>)<br />
                                         josevnz@mydomain.com<br />
</code></p>
<p>¡Que vaina!. Sin darme por vencido decidí utilizar a Gmail como relay, cambiando lo siguiente en <strong>/etc/postfix/main.cf</strong>:<br />
<code><br />
relayhost = <strong>smtp.gmail.com:587</strong><br />
smtp_sasl_auth_enable = yes<br />
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd<br />
smtp_sasl_security_options = noanonymous<br />
smtp_tls_security_level = may<br />
smtp_tls_CApath = /etc/postfix/certs<br />
smtp_tls_session_cache_database = btree:/etc/postfix/smtp_scache<br />
smtp_tls_session_cache_timeout = 3600s<br />
smtp_tls_loglevel = 1<br />
tls_random_source = dev:/dev/urandom<br />
</code></p>
<p>Y además en etc<strong>/postfix/sasl_passwd</strong>:<br />
<code><br />
<strong>smtp.gmail.com micuentaengmail@gmail.com:UltraSuperDuperPassword</strong><br />
</code></p>
<p>Reiniciamos a Postfix una vez mas:<br />
<code><br />
sudo postmap /etc/postfix/sasl_passwd<br />
sudo postfix stop<br />
sudo postfix start<br />
</code></p>
<p>Esto me permitió resolver el problema. Comparto este truco el cual funciona al menos en OSX Leopard y ahora me permite mandar correos desde PHP <img src='http://kodegeek.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://kodegeek.com/blog/2010/02/15/osx-postfix-relay-envio-de-correos-usando-osx-y-postfix/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Borrando correos masivamente usando Javamail</title>
		<link>http://kodegeek.com/blog/2008/12/30/borrando-correos-masivamente-usando-javamail/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=borrando-correos-masivamente-usando-javamail</link>
		<comments>http://kodegeek.com/blog/2008/12/30/borrando-correos-masivamente-usando-javamail/#comments</comments>
		<pubDate>Wed, 31 Dec 2008 05:51:58 +0000</pubDate>
		<dc:creator>josevnz</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[kodegeek]]></category>
		<category><![CDATA[opensource]]></category>
		<category><![CDATA[gmail]]></category>
		<category><![CDATA[imap]]></category>
		<category><![CDATA[javamail]]></category>
		<category><![CDATA[pop3]]></category>

		<guid isPermaLink="false">http://kodegeek.com/blog/?p=1341</guid>
		<description><![CDATA[Este articulo es una mejora al código que escribí anteriormente. Jugando un poco con Gmail me di cuenta que los correos aún pueden ser recuperados usando POP3, pese a que fueron borrados con IMAP. Realmente bizarro. Así que modifiqué el programa para que manejara un poco mejor el caso de POP3 o IMAP según las [...]]]></description>
			<content:encoded><![CDATA[<p>Este articulo es una mejora al código que escribí anteriormente. Jugando un poco con Gmail me di cuenta que los correos aún pueden ser recuperados usando POP3, pese a que fueron borrados con IMAP. Realmente bizarro. Así que modifiqué el programa para que manejara un poco mejor el caso de POP3 o IMAP según las propiedades.</p>
<p>Aquí está el código:</p>

<div class="wp_codebox"><table><tr id="p13412"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
</pre></td><td class="code" id="p1341code2"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.kodegeek.blog.mail</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Properties</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.logging.Level</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.logging.Logger</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.mail.Session</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.mail.Flags.Flag</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.mail.internet.MimeMessage</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.mail.Message</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.mail.Folder</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.mail.MessagingException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.mail.Store</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.sun.mail.imap.IMAPFolder</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.FileInputStream</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * I wrote this program to erase ALL the email on my GMAIL account. I have over 40,000 email so manually doing so was not an option :)
 * Please check the following resources:
 * &lt;ul&gt;
 * &lt;li&gt; http://java.sun.com/products/javamail/javadocs/index.html&lt;/li&gt;
 * &lt;li&gt; http://java.sun.com/developer/onlineTraining/JavaMail/contents.html&lt;/li&gt;
 * &lt;li&gt; http://java.sun.com/products/javamail/javadocs/com/sun/mail/imap/package-summary.html&lt;/li&gt;
 * &lt;li&gt; http://java.sun.com/products/javamail/downloads/index.html&lt;/li&gt;
 * &lt;/ul&gt;
 * Also define a properties file with the following (adjust it to your configuration):
 * # As defined by the Javadoc
 * &lt;ul&gt;
 * &lt;li&gt; mail.user=name.lastname@gmail.com&lt;/li&gt;
 * &lt;li&gt; mail.password=zzz&lt;/li&gt;
 * &lt;li&gt; mail.store.host=pop.imap.gmail.com&lt;/li&gt;
 * &lt;li&gt; mail.store.protocol=imap&lt;/li&gt;
 * &lt;li&gt; mail.imap.port=993&lt;/li&gt;
 * &lt;li&gt; mail.imap.socketFactory.port=993&lt;/li&gt;
 * &lt;li&gt; mail.imap.socketFactory.class=javax.net.ssl.SSLSocketFactory&lt;/li&gt;
 * &lt;/ul&gt;
 * More examples:
 * &lt;ul&gt;
 * &lt;li&gt;POP3: -Dmail.user=name.lastname@gmail.com  -Dmail.password=XXXX -Dmail.store.host=pop.gmail.com -Dmail.store.protocol=pop3 -Dmail.store.folder=INBOX -Dmail.pop3.port=995 -Dmail.pop3.socketFactory.port=995 -Dmail.pop3.socketFactory.class=javax.net.ssl.SSLSocketFactory&lt;/li&gt;
 * &lt;li&gt;IMAP: -Dmail.user=name.lastname@gmail.com  -Dmail.password=XXXX -Dmail.store.host=imap.gmail.com -Dmail.store.protocol=imap -Dmail.store.folder=INBOX -Dmail.imap.port=993 -Dmail.imap.socketFactory.port=993 -Dmail.imap.socketFactory.class=javax.net.ssl.SSLSocketFactory&lt;/li&gt;
 * &lt;/ul&gt;
 * License: GPL
 * http://kodegeek.com
 * @author Jose Vicente Nunez Zuleta
 * @version 12/28/2008
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">class</span> MailBulkEraser <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Command line processing
	 * @param args [0] Location of the properties configuration file, If not provided then will use system defaults (defined with -D)
	 * @throws Exception
	 * @since 0.1
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> <span style="color: #009900;">&#123;</span>
&nbsp;
		Logger logger <span style="color: #339933;">=</span> Logger.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span>MailBulkEraser.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aproperties+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Properties</span></a> props <span style="color: #339933;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">getProperties</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>args.<span style="color: #006633;">length</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			props.<span style="color: #006633;">load</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afileinputstream+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">FileInputStream</span></a><span style="color: #009900;">&#40;</span>args<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		Session session <span style="color: #339933;">=</span> Session.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span>props, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		session.<span style="color: #006633;">setDebug</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aboolean+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Boolean</span></a>.<span style="color: #006633;">parseBoolean</span><span style="color: #009900;">&#40;</span>props.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;debug&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		Store store <span style="color: #339933;">=</span> session.<span style="color: #006633;">getStore</span><span style="color: #009900;">&#40;</span>props.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mail.store.protocol&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a>.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Connecting to: %s@%s&quot;</span>, props.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mail.user&quot;</span><span style="color: #009900;">&#41;</span>, props.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mail.store.host&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		store.<span style="color: #006633;">connect</span><span style="color: #009900;">&#40;</span>props.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mail.store.host&quot;</span><span style="color: #009900;">&#41;</span>, props.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mail.user&quot;</span><span style="color: #009900;">&#41;</span>, props.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mail.password&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		Folder folder <span style="color: #339933;">=</span> store.<span style="color: #006633;">getDefaultFolder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Got default folder. Erasing emails from ALL the folders&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		Folder <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> folders <span style="color: #339933;">=</span> folder.<span style="color: #006633;">list</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">long</span> messgCnt <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>Folder currFolder<span style="color: #339933;">:</span> folders<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
			<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
&nbsp;
				<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>currFolder.<span style="color: #006633;">getType</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span> Folder.<span style="color: #006633;">HOLDS_MESSAGES</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #000000; font-weight: bold;">continue</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Skip this folder type</span>
				<span style="color: #009900;">&#125;</span>
				logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a>.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Opening folder: %s, num messages; %d&quot;</span>, currFolder.<span style="color: #006633;">getFullName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, currFolder.<span style="color: #006633;">getMessageCount</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				currFolder.<span style="color: #006633;">open</span><span style="color: #009900;">&#40;</span>Folder.<span style="color: #006633;">READ_WRITE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				Message <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> messages <span style="color: #339933;">=</span> currFolder.<span style="color: #006633;">getMessages</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">// Mark all the messages for delete</span>
				<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>Message message<span style="color: #339933;">:</span> messages<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
						<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span> currFolder.<span style="color: #006633;">isOpen</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
							logger.<span style="color: #006633;">warning</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a>.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Folder %s is closed. Moving to next folder&quot;</span>, currFolder.<span style="color: #006633;">getFullName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
							<span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span>
						<span style="color: #009900;">&#125;</span>
						message.<span style="color: #006633;">setFlag</span><span style="color: #009900;">&#40;</span>Flag.<span style="color: #006633;">DELETED</span>, <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						MimeMessage currMessage <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>MimeMessage<span style="color: #009900;">&#41;</span> message<span style="color: #339933;">;</span>
						logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a>.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Deleting mail subject: '%s', folder: '%s', date: '%s'&quot;</span>, currMessage.<span style="color: #006633;">getSubject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, currMessage.<span style="color: #006633;">getFolder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getFullName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, currMessage.<span style="color: #006633;">getSentDate</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>currFolder <span style="color: #000000; font-weight: bold;">instanceof</span> IMAPFolder<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
							messages <span style="color: #339933;">=</span> currFolder.<span style="color: #006633;">expunge</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Confirm delete for all the messages on the current folder</span>
						<span style="color: #009900;">&#125;</span>
						messgCnt <span style="color: #339933;">+=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>  <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Athrowable+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Throwable</span></a> thrbl<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
						logger.<span style="color: #006633;">log</span><span style="color: #009900;">&#40;</span>Level.<span style="color: #006633;">WARNING</span>, <span style="color: #0000ff;">&quot;There was a problem erasing the message, ignoring&quot;</span>, thrbl<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						<span style="color: #000000; font-weight: bold;">continue</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>
				<span style="color: #009900;">&#125;</span>
&nbsp;
				logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a>.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Messages erased on folder %s: %d&quot;</span>, currFolder.<span style="color: #006633;">getFullName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, messages.<span style="color: #006633;">length</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				currFolder.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>MessagingException messgExp<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				logger.<span style="color: #006633;">log</span><span style="color: #009900;">&#40;</span>Level.<span style="color: #006633;">WARNING</span>, <span style="color: #0000ff;">&quot;There was a problem, ignoring&quot;</span>, messgExp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
		logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a>.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Total number of erased messsages: %d&quot;</span>, messgCnt<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		store.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">exit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Nota de los cambios:</p>
<ul>
<li>El método expunge <a href="http://java.sun.com/products/javamail/javadocs/com/sun/mail/imap/IMAPFolder.html">sólo es válido para IMAP</a>. Verificamos eso.</li>
<li>Agregué nuevas propiedades de uso en el Javadoc.</li>
</ul>
<p>Que lo disfruten <img src='http://kodegeek.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
]]></content:encoded>
			<wfw:commentRss>http://kodegeek.com/blog/2008/12/30/borrando-correos-masivamente-usando-javamail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>¿Como borrar 40000 correos en Gmail? Fácil, usando Javamail e IMAP</title>
		<link>http://kodegeek.com/blog/2008/12/28/%c2%bfcomo-borrar-40000-correos-en-gmail-facil-usando-javamail-e-imap/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=%25c2%25bfcomo-borrar-40000-correos-en-gmail-facil-usando-javamail-e-imap</link>
		<comments>http://kodegeek.com/blog/2008/12/28/%c2%bfcomo-borrar-40000-correos-en-gmail-facil-usando-javamail-e-imap/#comments</comments>
		<pubDate>Sun, 28 Dec 2008 22:53:50 +0000</pubDate>
		<dc:creator>josevnz</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[gmail]]></category>
		<category><![CDATA[imap]]></category>
		<category><![CDATA[kodegeek]]></category>
		<category><![CDATA[opensource]]></category>

		<guid isPermaLink="false">http://kodegeek.com/blog/?p=1299</guid>
		<description><![CDATA[Este fin de semana me decidí a poner un poco de orden en mis cuentas de correo; Una de las cosas que me obligó a ello es que mi cuenta paga de Yahoo expiró y aún ando debatiendo si debo pagar $20 por una cuenta de correo que no ofrece nada por encima de Gmail. [...]]]></description>
			<content:encoded><![CDATA[<p>Este fin de semana me decidí a poner un poco de orden en mis cuentas de correo; Una de las cosas que me obligó a ello es que mi cuenta paga de Yahoo expiró y aún ando debatiendo si debo pagar $20 por una cuenta de correo que no ofrece nada por encima de Gmail. Al momento de revizar mi cuenta de Gmail me encuentro con que estoy usando por encima de 1 GB en correo con más de 40000 correos.</p>
<p>Si, es increíble la cantidad de basura que se acumula en dos años <img src='http://kodegeek.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Definitivamente no estaba dispuesto a perder mi tiempo borrando tal cantidad de correos a mano, en vez de eso me decicí a automatizar la tarea usando Java y el hecho de que Gmail soporta POP / IMAP (<a href="http://java.sun.com/products/javamail/javadocs/index.html">Javamail </a>cuenta con accesso a IMAP comp arte de su API). Una vez leido un poco abrí mi <a href="http://eclipse.org">Eclipse</a> y el resultado es el código que viene a continuación:</p>

<div class="wp_codebox"><table><tr id="p12994"><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
</pre></td><td class="code" id="p1299code4"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.kodegeek.blog.mail</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Properties</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.logging.Level</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.logging.Logger</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.mail.Session</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.mail.Flags.Flag</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.mail.internet.MimeMessage</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.mail.Message</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.mail.Folder</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.mail.MessagingException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.mail.Store</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.FileInputStream</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #008000; font-style: italic; font-weight: bold;">/**
 * I wrote this program to erase ALL the email on my GMAIL account. I have over 40,000 email so manually doing so was not an option :)
 * Please check the following resources:
 * &lt;ul&gt;
 * &lt;li&gt; http://java.sun.com/products/javamail/javadocs/index.html&lt;/li&gt;
 * &lt;li&gt; http://java.sun.com/developer/onlineTraining/JavaMail/contents.html&lt;/li&gt;
 * &lt;li&gt; http://java.sun.com/products/javamail/javadocs/com/sun/mail/imap/package-summary.html&lt;/li&gt;
 * &lt;li&gt; http://java.sun.com/products/javamail/downloads/index.html&lt;/li&gt;
 * &lt;/ul&gt;
 * Also define a properties file with the following (adjust it to your configuration):
 * # As defined by the Javadoc
 * &lt;ul&gt;
 * &lt;li&gt; mail.user=name.lastname@gmail.com&lt;/li&gt;
 * &lt;li&gt; mail.password=zzz&lt;/li&gt;
 * &lt;li&gt; mail.store.host=pop.imap.gmail.com&lt;/li&gt;
 * &lt;li&gt; mail.store.protocol=imap&lt;/li&gt;
 * &lt;li&gt; mail.imap.port=993&lt;/li&gt;
 * &lt;li&gt; mail.imap.socketFactory.port=993&lt;/li&gt;
 * &lt;li&gt; mail.imap.socketFactory.class=javax.net.ssl.SSLSocketFactory&lt;/li&gt;
 * &lt;/ul&gt;
 * License: GPL
 * http://kodegeek.com
 * @author Jose Vicente Nunez Zuleta
 * @version 12/28/2008
 */</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">class</span> ImapBulkEraser <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #008000; font-style: italic; font-weight: bold;">/**
	 * Command line processing
	 * @param args [0] Location of the properties configuration file, If not provided then will use system defaults (defined with -D)
	 * @throws Exception
	 * @since 0.1
	 */</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">static</span> <span style="color: #000066; font-weight: bold;">void</span> main<span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> args<span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aexception+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Exception</span></a> <span style="color: #009900;">&#123;</span>
&nbsp;
		Logger logger <span style="color: #339933;">=</span> Logger.<span style="color: #006633;">getLogger</span><span style="color: #009900;">&#40;</span>ImapBulkEraser.<span style="color: #000000; font-weight: bold;">class</span>.<span style="color: #006633;">getName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aproperties+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Properties</span></a> props <span style="color: #339933;">=</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Asystem+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">System</span></a>.<span style="color: #006633;">getProperties</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>args.<span style="color: #006633;">length</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			props.<span style="color: #006633;">load</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Afileinputstream+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">FileInputStream</span></a><span style="color: #009900;">&#40;</span>args<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		Session session <span style="color: #339933;">=</span> Session.<span style="color: #006633;">getInstance</span><span style="color: #009900;">&#40;</span>props, <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		session.<span style="color: #006633;">setDebug</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Aboolean+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">Boolean</span></a>.<span style="color: #006633;">parseBoolean</span><span style="color: #009900;">&#40;</span>props.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;debug&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		Store store <span style="color: #339933;">=</span> session.<span style="color: #006633;">getStore</span><span style="color: #009900;">&#40;</span>props.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mail.store.protocol&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a>.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Connecting to: %s@%s:%s&quot;</span>, props.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mail.user&quot;</span><span style="color: #009900;">&#41;</span>, props.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mail.store.host&quot;</span><span style="color: #009900;">&#41;</span>, props.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mail.imap.port&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		store.<span style="color: #006633;">connect</span><span style="color: #009900;">&#40;</span>props.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mail.store.host&quot;</span><span style="color: #009900;">&#41;</span>, props.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mail.user&quot;</span><span style="color: #009900;">&#41;</span>, props.<span style="color: #006633;">getProperty</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;mail.password&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		Folder folder <span style="color: #339933;">=</span> store.<span style="color: #006633;">getDefaultFolder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Got default folder. Erasing emails from ALL the folders&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		Folder <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> folders <span style="color: #339933;">=</span> folder.<span style="color: #006633;">list</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">long</span> messgCnt <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span>Folder currFolder<span style="color: #339933;">:</span> folders<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
			<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
&nbsp;
				<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#40;</span>currFolder.<span style="color: #006633;">getType</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;</span> Folder.<span style="color: #006633;">HOLDS_MESSAGES</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #000000; font-weight: bold;">continue</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Skip this folder type</span>
				<span style="color: #009900;">&#125;</span>
				logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a>.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Opening folder: %s, num messages; %d&quot;</span>, currFolder.<span style="color: #006633;">getFullName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, currFolder.<span style="color: #006633;">getMessageCount</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				currFolder.<span style="color: #006633;">open</span><span style="color: #009900;">&#40;</span>Folder.<span style="color: #006633;">READ_WRITE</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				Message <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> messages <span style="color: #339933;">=</span> currFolder.<span style="color: #006633;">getMessages</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
				<span style="color: #666666; font-style: italic;">// Mark all the messages for delete</span>
				<span style="color: #000000; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span>Message message<span style="color: #339933;">:</span> messages<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
					<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
						message.<span style="color: #006633;">setFlag</span><span style="color: #009900;">&#40;</span>Flag.<span style="color: #006633;">DELETED</span>, <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						MimeMessage currMessage <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>MimeMessage<span style="color: #009900;">&#41;</span> message<span style="color: #339933;">;</span>
						logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a>.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Set delete flag for mail subject: '%s', folder: '%s'&quot;</span>, currMessage.<span style="color: #006633;">getSubject</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, currMessage.<span style="color: #006633;">getFolder</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">getFullName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
						messages <span style="color: #339933;">=</span> currFolder.<span style="color: #006633;">expunge</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Confirm delete for all the messages on the current folder</span>
						messgCnt <span style="color: #339933;">+=</span> messages.<span style="color: #006633;">length</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>  <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>MessagingException messgExp<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
						logger.<span style="color: #006633;">log</span><span style="color: #009900;">&#40;</span>Level.<span style="color: #006633;">WARNING</span>, <span style="color: #0000ff;">&quot;There was a problem erasing the message, ignoring&quot;</span>, messgExp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
					<span style="color: #009900;">&#125;</span>
				<span style="color: #009900;">&#125;</span>
&nbsp;
				logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a>.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Messages erased on folder %s: %d&quot;</span>, currFolder.<span style="color: #006633;">getFullName</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>, messages.<span style="color: #006633;">length</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				currFolder.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
			<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>MessagingException messgExp<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				logger.<span style="color: #006633;">log</span><span style="color: #009900;">&#40;</span>Level.<span style="color: #006633;">WARNING</span>, <span style="color: #0000ff;">&quot;There was a problem, ignoring&quot;</span>, messgExp<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
&nbsp;
		<span style="color: #009900;">&#125;</span>
		logger.<span style="color: #006633;">info</span><span style="color: #009900;">&#40;</span><a href="http://www.google.com/search?hl=en&amp;q=allinurl%3Astring+java.sun.com&amp;btnI=I%27m%20Feeling%20Lucky"><span style="color: #003399;">String</span></a>.<span style="color: #006633;">format</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Total number of erased messsages: %d&quot;</span>, messgCnt<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		store.<span style="color: #006633;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Correr el código es trivial, asegurese de tener el JAR de Javamail en el $CLASSPATH y haga algo como esto:</p>
<p><code><br />
java com.kodegeek.blog.mail.ImapBulkEraser -Dmail.user=name.lastname@gmail.com  -Dmail.password=XXXX -Dmail.store.host=imap.gmail.com -Dmail.store.protocol=imap -Dmail.store.folder=INBOX -Dmail.imap.port=993 -Dmail.imap.socketFactory.port=993 -Dmail.imap.socketFactory.class=javax.net.ssl.SSLSocketFactory<br />
</code></p>
<p>El programa no es perfecto, ya que de vez en cuando me conseguí con la siguiente error:</p>
<p><code><br />
NFO: Set delete flag for mail subject: 'Deploying webapps in embedded environment', folder: 'tomcat-user'<br />
Dec 28, 2008 5:40:18 PM com.kodegeek.blog.mail.ImapBulkEraser main<br />
WARNING: There was a problem erasing the message, ignoring<br />
javax.mail.MessagingException: Failed to load IMAP envelope<br />
	at com.sun.mail.imap.IMAPMessage.loadEnvelope(IMAPMessage.java:1069)<br />
	at com.sun.mail.imap.IMAPMessage.getSubject(IMAPMessage.java:256)<br />
	at com.kodegeek.blog.mail.ImapBulkEraser.main(ImapBulkEraser.java:83)<br />
Dec 28, 2008 5:40:18 PM com.kodegeek.blog.mail.ImapBulkEraser main<br />
</code></p>
<p>Sin embargo esos no son todos los correos <img src='http://kodegeek.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Como siempre el código fuente de este programa es GPL y se puede bajar <a href="http://elangelnegro.cvs.sourceforge.net/viewvc/elangelnegro/src/java/main/com/kodegeek/blog/mail/ImapBulkEraser.java?view=markup">desde CVS</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://kodegeek.com/blog/2008/12/28/%c2%bfcomo-borrar-40000-correos-en-gmail-facil-usando-javamail-e-imap/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

