You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Dimitri Koussa <di...@gmail.com> on 2012/05/24 02:28:50 UTC

[net] Problem using IMAPClient to fetch email contents

Hi,

I'm trying to use commons-net-3.1 to fetch body[header] and body[text] via 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 {
    IMAPClient client = new IMAPClient();
    client.connect(SERVER);
    client.login(USERNAME, PASSWORD);
    client.select("INBOX");
    client.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?
Can anyone point me in the right direction?

Thanks
-- 
Dimitri

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [net] Problem using IMAPClient to fetch email contents

Posted by sebb <se...@gmail.com>.
On 25 May 2012 16:17, sebb <se...@gmail.com> wrote:
> On 25 May 2012 03:24, sebb <se...@gmail.com> wrote:
>> On 24 May 2012 01:28, Dimitri Koussa <di...@gmail.com> wrote:
>>> Hi,
>>>
>>> I'm trying to use commons-net-3.1 to fetch body[header] and body[text] via 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 {
>>>    IMAPClient client = new IMAPClient();
>>>    client.connect(SERVER);
>>>    client.login(USERNAME, PASSWORD);
>>>    client.select("INBOX");
>>>    client.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.
>
> https://issues.apache.org/jira/browse/NET-467
>
> has been created to track this issue.

Now hopefully solved.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [net] Problem using IMAPClient to fetch email contents

Posted by sebb <se...@gmail.com>.
On 25 May 2012 03:24, sebb <se...@gmail.com> wrote:
> On 24 May 2012 01:28, Dimitri Koussa <di...@gmail.com> wrote:
>> Hi,
>>
>> I'm trying to use commons-net-3.1 to fetch body[header] and body[text] via 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 {
>>    IMAPClient client = new IMAPClient();
>>    client.connect(SERVER);
>>    client.login(USERNAME, PASSWORD);
>>    client.select("INBOX");
>>    client.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.

https://issues.apache.org/jira/browse/NET-467

has been created to track this issue.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Re: [net] Problem using IMAPClient to fetch email contents

Posted by sebb <se...@gmail.com>.
On 24 May 2012 01:28, Dimitri Koussa <di...@gmail.com> wrote:
> Hi,
>
> I'm trying to use commons-net-3.1 to fetch body[header] and body[text] via 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 {
>    IMAPClient client = new IMAPClient();
>    client.connect(SERVER);
>    client.login(USERNAME, PASSWORD);
>    client.select("INBOX");
>    client.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