PxPlus User Forum

Twitter Twitter Twitter

Author Topic: iMAP4  (Read 1821 times)

Danilo David

  • Member
  • **
  • Posts: 18
    • View Profile
iMAP4
« on: October 22, 2019, 07:50:57 PM »
HELLO,

I have an Imap command to fetch message.
3110 WRITE RECORD (CHAN_FETCH,ERR=ERROR_11)"A07 UID FETCH "+STR(MESSAGE_NUMBER)+" BODY.PEEK[TEXT]"+$0D0A$ ! *NOMSG*
3120 READ RECORD (CHAN_FETCH,TIM=2,ERR=3150)X$
3130 LET MESSAGE$=MESSAGE$+X$
3140 GOTO 3120
3150 !


the problem is when  a message consist of attachment it is very slow because in the message$ variable attachment is included also
but i dont need the attachment in this stage.
do you know how can I ignore attachment in message variable so it can be faster?

Thank you.

Best regards,
Danilo

Allen Miglore

  • Silver Member
  • ***
  • Posts: 38
    • View Profile
    • UnForm
Re: iMAP4
« Reply #1 on: October 22, 2019, 08:05:42 PM »
You can scan the main headers of the message for a content-type header with a boundary=string value.  That string, with a "--" prefix, delimits the parts of the message.  And the very end of the message both a prefix and suffix value (--string--).  If you just want the first part, typically the text message, you can just watch for the second part and exit.  I would write some whole messages out to files to see how they are structured.

Here is a sample of what it might look like:

Content-Type: multipart/alternative; boundary=f64af71f2a384073bb33579fd1ecabfd

The various parts of this message have a line "--f64af71f2a384073bb33579fd1ecabfd" at the start.

Note you can also speed up string appends with the += operator.  Line 3130 could be: message$+=x$.

chrisk

  • Member
  • **
  • Posts: 14
    • View Profile
Re: iMAP4
« Reply #2 on: October 23, 2019, 01:21:46 AM »
Danilo,

It is unclear whether you want to speed things up by retrieving a smaller amount of data or if you want to improve the processing speed when you retrieve a large amount of data.

Your fetch command is basically requesting the entire message. Looking at the imap spec (RFC 3501), under the fetch command, it says the TEXT part specifier refers to the text body of the message (everything but the header). You can either use a different part specifier or add the syntax to request a partial reply.  Reading and understanding what is in the specification can help you tune the conversation so you get only what you want.

To make your retrieval more efficient when working with the large messages involves fixing the slow processing. Alan’s suggestion to use += helps. However, you should also make sure you are working with good size communication blocks. That means for each read, X$ should be at least 1k in length to minimize how much work your loop is doing.

Chris Kukuchka
Sequoia Group, Inc.

Danilo David

  • Member
  • **
  • Posts: 18
    • View Profile
Re: iMAP4
« Reply #3 on: October 24, 2019, 07:32:57 PM »
The += is a big help to make it faster. but the other suggestion how can i adopt that in my code so that it can be more faster?
Thank you

Mike King

  • Diamond Member
  • *****
  • Posts: 3811
  • Mike King
    • View Profile
    • BBSysco Consulting
Re: iMAP4
« Reply #4 on: October 25, 2019, 07:25:12 PM »
You might try specifying a SIZ= on the READ RECORD to provide you more data, something like:

3120 READ RECORD (CHAN_FETCH,SIZ=10240,TIM=2,ERR=3150)X$
3130 LET MESSAGE$=MESSAGE$+X$
3140 GOTO 3120


The system should return you all it can in X$ up to 10240 bytes in a single read.  If there is not 10240 bytes, it will return you what it has.
Mike King
President - BBSysco Consulting
eMail: mike.king@bbsysco.com

Danilo David

  • Member
  • **
  • Posts: 18
    • View Profile
Re: iMAP4
« Reply #5 on: October 27, 2019, 09:46:32 PM »
Mike,

I did try put SIZ=10240 but the speed is the same
I did check also the length of x$ in having SIZ=10240 and without SIZ.
I did get both 4096 for the len(x$)

best regards,
Danilo
« Last Edit: October 27, 2019, 10:56:04 PM by Danilo David »