Return-Path: X-Original-To: apmail-commons-user-archive@www.apache.org Delivered-To: apmail-commons-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7BFDA9E60 for ; Fri, 25 May 2012 02:24:57 +0000 (UTC) Received: (qmail 53195 invoked by uid 500); 25 May 2012 02:24:56 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 53080 invoked by uid 500); 25 May 2012 02:24:55 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 53069 invoked by uid 99); 25 May 2012 02:24:55 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 25 May 2012 02:24:55 +0000 X-ASF-Spam-Status: No, hits=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of sebbaz@gmail.com designates 209.85.214.171 as permitted sender) Received: from [209.85.214.171] (HELO mail-ob0-f171.google.com) (209.85.214.171) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 25 May 2012 02:24:48 +0000 Received: by obfk16 with SMTP id k16so688476obf.30 for ; Thu, 24 May 2012 19:24:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=F6eMQ7wp7nEaERYL62YHf//hNMm44ouQsoOG0tmCScs=; b=Mxm1h0Qx5vwVfivo9jJLoP+cLygHmBr7IwN42pG+EdlUOhFNC5AXPmzMXpGblVaHcS N9AnJ+UozWhdRYYQOtHtFsG0w7Or3u+SoLevi7kQBtjM2tmEhLSPhLbYmSzfA/uJmW+g fkxQccc4EF6vzWZFYZeP52DsLtYLFq98K5rUXNdwh4kYegm+URSe4+BmidFWFYhXKt98 Vjd/e9esW78eOdjG26XYnSQYYNR662Xl6AKqnHwQA1bnQj9kZcR1KPvVOfuhZ2K0WmCE tbE5LeTfPl8cOkmHZ+1MDUjxo2i1n6HVd//KwXysZMpvPmO0P0Q3GEngxyJq7Dl44tsN uikQ== MIME-Version: 1.0 Received: by 10.182.139.2 with SMTP id qu2mr1613346obb.34.1337912667594; Thu, 24 May 2012 19:24:27 -0700 (PDT) Received: by 10.182.105.70 with HTTP; Thu, 24 May 2012 19:24:27 -0700 (PDT) In-Reply-To: References: Date: Fri, 25 May 2012 03:24:27 +0100 Message-ID: Subject: Re: [net] Problem using IMAPClient to fetch email contents From: sebb To: Commons Users List Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable On 24 May 2012 01:28, Dimitri Koussa wrote: > Hi, > > I'm trying to use commons-net-3.1 to fetch body[header] and body[text] vi= a IMAP. > When I try to use the fetch command I get a MalformedServerReplyException= . > > The stack trace I get is: > > Exception in thread "main" > org.apache.commons.net.MalformedServerReplyException: Received > unexpected IMAP protocol response from server: 'Return-Path: > <[removed]>'. > at org.apache.commons.net.imap.IMAPReply.getReplyCode(IMAPReply.java:128) > at org.apache.commons.net.imap.IMAPReply.getReplyCode(IMAPReply.java:93) > at org.apache.commons.net.imap.IMAP.__getReply(IMAP.java:120) > at org.apache.commons.net.imap.IMAP.__getReply(IMAP.java:90) > at org.apache.commons.net.imap.IMAP.sendCommandWithID(IMAP.java:225) > at org.apache.commons.net.imap.IMAP.sendCommand(IMAP.java:238) > at org.apache.commons.net.imap.IMAP.sendCommand(IMAP.java:263) > at org.apache.commons.net.imap.IMAP.doCommand(IMAP.java:276) > at org.apache.commons.net.imap.IMAPClient.fetch(IMAPClient.java:339) > > A sample that reproduces the problem is: > > public static void main(String[] args) throws Exception { > =A0 =A0IMAPClient client =3D new IMAPClient(); > =A0 =A0client.connect(SERVER); > =A0 =A0client.login(USERNAME, PASSWORD); > =A0 =A0client.select("INBOX"); > =A0 =A0client.fetch("1", "body[header]"); > } > > When I telnet to the IMAP server I get a response like: > > 08 fetch 1 body[header] > * 1 FETCH (BODY[HEADER] {608} > Return-Path: <____@____.com> > X-Original-To: ____@____.com > [...] > ) > * 79690 EXISTS > * 13 RECENT > 08 OK Fetch completed. > > I have checked out the samples but they only seem to list emails and > never fetch body[header] or body[text]. > > Am I using the fetch command correctly? Yes. > Can anyone point me in the right direction? Looks like there is a bug in the way server replies are handled. The code is not processing the string response correctly. It should see the {608} at the end of the line and read the next 608 octets as a string, but it does not. > Thanks > -- > Dimitri > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@commons.apache.org > For additional commands, e-mail: user-help@commons.apache.org > --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@commons.apache.org For additional commands, e-mail: user-help@commons.apache.org