/* * Copyright (c) 2007 Lalit Mehta * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ package com.saiyam.rome.test; import java.net.HttpURLConnection; import java.net.URL; import java.util.Iterator; import java.util.List; import com.sun.syndication.feed.synd.SyndEntryImpl; import com.sun.syndication.feed.synd.SyndFeed; import com.sun.syndication.io.SyndFeedInput; import com.sun.syndication.io.XmlReader; /** * It Reads and prints Gmail Atom feed. *
* @author Lalit Mehta * */ public class CheckMail { public static void main(String[] args) { try { URL feedUrl = new URL("https://gmail.google.com/gmail/feed/atom"); HttpURLConnection httpcon = (HttpURLConnection)feedUrl.openConnection(); String encoding = new sun.misc.BASE64Encoder().encode("username:password".getBytes()); httpcon.setRequestProperty ("Authorization", "Basic " + encoding); SyndFeedInput input = new SyndFeedInput(); SyndFeed feed = input.build(new XmlReader(httpcon)); System.out.println("Title: " + feed.getTitle()); List entries = feed.getEntries(); System.out.println("Total Entries : " + entries.size()); Iterator it = entries.iterator(); while (it.hasNext()) { SyndEntryImpl e = (SyndEntryImpl) it.next(); System.out.println(e.getTitle()); System.out.println(e.getDescription()); System.out.println(); } } catch (Exception ex) { ex.printStackTrace(); System.out.println("ERROR: " + ex.getMessage()); } } }