<?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>Hacking so Existing &#187; IMAP</title>
	<atom:link href="http://dev.zhourenjian.com/blog/tag/imap/feed" rel="self" type="application/rss+xml" />
	<link>http://dev.zhourenjian.com/blog</link>
	<description>Zhou Renjian&#039;s Development Blog</description>
	<lastBuildDate>Fri, 23 Apr 2010 01:54:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Connect Yahoo IMAP Server by JavaMail</title>
		<link>http://dev.zhourenjian.com/blog/2009/11/29/connect-yahoo-imap-server-by-javamail.html</link>
		<comments>http://dev.zhourenjian.com/blog/2009/11/29/connect-yahoo-imap-server-by-javamail.html#comments</comments>
		<pubDate>Sun, 29 Nov 2009 10:02:45 +0000</pubDate>
		<dc:creator>Zhou Renjian</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[IMAP]]></category>
		<category><![CDATA[JavaMail]]></category>
		<category><![CDATA[Yahoo Mail]]></category>

		<guid isPermaLink="false">http://dev.zhourenjian.com/blog/2009/11/29/connect-yahoo-imap-server-by-javamail.html</guid>
		<description><![CDATA[These days, I were implementing an online web mail client for all mail services, like Gmail, Hotmail/Live Mail, Yahoo! Mail, AOL/AIM Mail. And adding Yahoo! Mail support cost me lots of time, but the solution is simple. Yahoo! Mail provides &#8230; <a href="http://dev.zhourenjian.com/blog/2009/11/29/connect-yahoo-imap-server-by-javamail.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>These days, I were implementing an <a href="http://webuzz.im/mail/">online web mail client for all mail services, like Gmail, Hotmail/Live Mail, Yahoo! Mail, AOL/AIM Mail</a>. And adding Yahoo! Mail support cost me lots of time, but the solution is simple.</p>
<p><a href="http://mail.yahoo.com/">Yahoo! Mail</a> provides only web access for free users and does not provide free POP3 services. You need to buy Yahoo! Mail Plus to have POP support. Not long before, Yahoo! Mail provided IMAP services for Zoho Web Mail. It means that IMAP support is free for any Yahoo! Mail users, no Yahoo! Mail Plus is needed. But Yahoo! Mail&#8217;s IMAP services is not a totally standard IMAP service. You need <a href="http://en.wikipedia.org/wiki/Yahoo!_Mail">send some special tokens</a> before you login. So a customized Thunderbird is need to Yahoo! IMAP support.</p>
<p><a href="http://java.sun.com/products/javamail/">JavaMail</a> provides a convenient way to connect mail servers by POP/IMAP/SMTP and others. Here is a &#8220;how-to&#8221; of making a little modification of JavaMail library to support Yahoo! Mail&#8217;s IMAP service.</p>
<p>1. Download sources of JavaMail<br />
2. Modify com.sun.mail.imap.IMAPStore.login(IMAPProtocol, String, String) from a <strong>private</strong> method into a <strong>protected</strong> method, because we need to override it for Yahoo! IMAP.<br />
3. Replace the compiled IMAPStore*.class files in JavaMail&#8217;s binary library file mail.jar.<br />
4. Write two classes:</p>
<pre>
public class YahooIMAPStore extends IMAPStore {

	public YahooIMAPStore(Session session, URLName url) {
		super(session, url);
	}

	@Override
	protected void login(IMAPProtocol p, String u, String pw)
			throws ProtocolException {
		Response[] r = p.command("ID (\"GUID\" \"1\")", null);
		p.notifyResponseHandlers(r);

		super.login(p, u, pw);
	}
}

public class YahooIMAPSSLStore extends IMAPSSLStore {

	public YahooIMAPSSLStore(Session session, URLName url) {
		super(session, url);
	}

	@Override
	protected void login(IMAPProtocol p, String u, String pw)
			throws ProtocolException {
		Response[] r = p.command("ID (\"GUID\" \"1\")", null);
		p.notifyResponseHandlers(r);

		super.login(p, u, pw);
	}
}
</pre>
<p>5. Modify JavaMail related codes to use overrided YahooIMAPStore:</p>
<pre>
if ("yahoo.com".equals(domain)
		|| "ymail.com".equals(domain)
		|| "rocketmail.cn".equals(domain)) {
	if (protocol == null) {
		<del datetime="2010-01-14T08:13:03+00:00">protocol = "imaps";
		host = "imap.next.mail.yahoo.com";
		port = 993;</del>

		protocol = "imap";
		host = "imap.mail.yahoo.com";
		port = 143;
	}
	if (sendProtocol == null) {
		sendProtocol = "smtps";
		sendHost = "smtp.mail.yahoo.com";
		sendPort = 587;
	}
}
...
if (host.indexOf(".yahoo.com") != -1) {
	props.setProperty("mail.imap.class", "im.webuzz.mail.YahooIMAPStore");
	props.setProperty("mail.imaps.class", "im.webuzz.mail.YahooIMAPSSLStore");
}
Session session = Session.getInstance(props, null);
if (host.indexOf(".yahoo.com") != -1) {
	session.addProvider(new Provider(Provider.Type.STORE, "imap",
		"im.webuzz.mail.YahooIMAPStore", "WeBuzz", "1.0"));
	session.addProvider(new Provider(Provider.Type.STORE, "imaps",
		"im.webuzz.mail.YahooIMAPSSLStore", "WeBuzz", "1.0"));
}

store = session.getStore(protocol);
store.connect(host, user, password);
...
</pre>
<p>Done! Enjoy Yahoo! Mail&#8217;s IMAP support by JavaMail.</p>
<p>BTW: You can test out <a href="http://webuzz.im/web-yahoo-mail/">WeBuzz&#8217;s Web Mail for Yahoo! Mail</a>, which is using JavaMail and IMAP with the above hacks.</p>
]]></content:encoded>
			<wfw:commentRss>http://dev.zhourenjian.com/blog/2009/11/29/connect-yahoo-imap-server-by-javamail.html/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
