Hi, I need to do a mail loop downloading mail with a specific word in the subject.
I made a task that works perfectly but it's too slow because it analyzes ALL the mails.
I tried to use a "while loop" and "imap folder info" but it's slow too because I must download every single mail to get the subject differently to the "imap mail loop" action.
Is there a way to analyze only the last 100 mails with imap mail loop?
Mail loop with last X mails
Re: Mail loop with last X mails
You have to use some counter in the mail loop.
Process messages from 1 to 100. Next you can break the loop. Use Break action
Algorithm will be similar to this:
Process messages from 1 to 100. Next you can break the loop. Use Break action
Algorithm will be similar to this:
Code: Select all
IMAP open
IMAP Mail Loop // set ordering number to NUM
.....
do something
.....
if {num} >100 then
break
end if
End loop
Oleg Yershov
Re: Mail loop with last X mails
So, if mail box contains less than 100 massages you process all messages. If more than 100 you process only 100 newest messages.
Oleg Yershov
-
- Posts: 70
- Joined: Thu Jul 02, 2015 3:54 pm
Re: Mail loop with last X mails
Thanks for you very fast answer,
I have 2178 mails and I need to process messages from 2078 to 2178.
I set the ordering number with the value (num = 2078) breaking when num>100 but it start always from the oldest mail.
imap open
imap folder info
increment variable (2 variables: total mail {nums} and total -100 {num})
imap mail loop (ordering number {num})
if {num}>100
break
if subject contain word
download message
end if
end loop.
What's wrong?
I have 2178 mails and I need to process messages from 2078 to 2178.
I set the ordering number with the value (num = 2078) breaking when num>100 but it start always from the oldest mail.
imap open
imap folder info
increment variable (2 variables: total mail {nums} and total -100 {num})
imap mail loop (ordering number {num})
if {num}>100
break
if subject contain word
download message
end if
end loop.
What's wrong?

Re: Mail loop with last X mails
I'm sorry, you are correct: newest messages are at the end of the list
look at my example below how to read only 100 last messages
Save the text of the task to a file and use menu Task->Import to import the task into RoboTask.
You can change the amount of the messages, look at the step #4
look at my example below how to read only 100 last messages
Code: Select all
;*****************************
;* RoboTask Task file
;* Do not edit in text editor!
;*****************************
[Root]
ActionAfterRun=INTEGER|0
Actions=FOLDER
Automat=INTEGER|-1
CatID=INTEGER|1539658767
Comment=STRINGLIST
ContinueOnError=INTEGER|0
ExternalName=STRING|"Task272"
Hide=INTEGER|0
ID=INTEGER|1723780338
LogOnAsUser=INTEGER|1
Name=STRING|"check only last 100 emails"
OnErrorTaskID=INTEGER|-1
Priority=INTEGER|3
RunOnClose=INTEGER|0
RunOnStartup=INTEGER|0
ToLog=INTEGER|2
UnicodeFormat=INTEGER|1
WriteGeneralLog=INTEGER|0
[Actions]
Action1=FOLDER
Action10=FOLDER
Action11=FOLDER
Action12=FOLDER
Action13=FOLDER
Action14=FOLDER
Action15=FOLDER
Action2=FOLDER
Action3=FOLDER
Action4=FOLDER
Action5=FOLDER
Action6=FOLDER
Action7=FOLDER
Action8=FOLDER
Action9=FOLDER
[Actions\Action1]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER
[Actions\Action1\Params]
message=STRING|"*****************"
type=STRING|"3"
[Actions\Action10]
ActionID=STRING|"A_IMAP_DOWNLOAD"
Enabled=INTEGER|-1
Name=STRING|"IMAP Download Message"
Params=FOLDER
[Actions\Action10\Params]
extract=STRING|"0"
num=STRING|"{num}"
overwrite=STRING|"1"
savefilenames=STRING|"0"
savetofile=STRING|"{TempDir}\tmp.eml"
[Actions\Action11]
ActionID=STRING|"A_EMAILE_PARSE"
Enabled=INTEGER|-1
Name=STRING|"Parse Email Message"
Params=FOLDER
[Actions\Action11\Params]
cc=STRING|"0"
date=STRING|"1"
datevar=STRING|"dt"
extract=STRING|"0"
file=STRING|"{TempDir}\tmp.emp"
from=STRING|"0"
overwrite=STRING|"0"
priority=STRING|"0"
savefilenames=STRING|"0"
subj=STRING|"1"
subjvar=STRING|"subj"
text=STRING|"0"
texttype=STRING|"0"
to=STRING|"0"
[Actions\Action12]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER
[Actions\Action12\Params]
message=STRING|"{num}: {subj}"
type=STRING|"3"
[Actions\Action13]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER
[Actions\Action13\Params]
message=STRING|"{num}: {dt}"
type=STRING|"3"
[Actions\Action14]
ActionID=STRING|"A_LOOP_BREAK"
Enabled=INTEGER|-1
Name=STRING|"Break"
[Actions\Action15]
ActionID=STRING|"A_LOOP_END"
Enabled=INTEGER|-1
Name=STRING|"End Loop"
[Actions\Action2]
ActionID=STRING|"A_IMAP_OPEN"
Enabled=INTEGER|-1
Name=STRING|"IMAP Open"
Params=FOLDER
[Actions\Action2\Params]
folder=STRING|"INBOX"
host=STRING|"imap.gmail.com"
password=STRING|"46697457712734240652452634424341422"
passwordmode=STRING|"1"
port=STRING|"993"
SSL=STRING|"1"
user=STRING|"your-user-name"
[Actions\Action3]
ActionID=STRING|"A_IMAP_MSGCOUNT"
Enabled=INTEGER|-1
Name=STRING|"IMAP Folder Info"
Params=FOLDER
[Actions\Action3\Params]
folder=STRING|"0"
recent=STRING|"0"
total=STRING|"1"
unseen=STRING|"0"
vartotal=STRING|"sz"
[Actions\Action4]
ActionID=STRING|"A_SCRIPT_VBEVALUATE"
Enabled=INTEGER|-1
Name=STRING|"VB Evaluate"
Params=FOLDER
[Actions\Action4\Params]
expression=STRING|"{sz}-100+1"
linecount=STRING|"0"
loadfromfile=STRING|"1"
variable=STRING|"delta"
[Actions\Action5]
ActionID=STRING|"A_FLOW_IF"
Enabled=INTEGER|-1
Name=STRING|"If Then"
Params=FOLDER
[Actions\Action5\Params]
case=STRING|"0"
connection=STRING|"0"
count=STRING|"1"
operator=STRING|"4"
type=STRING|"1"
value1=STRING|"{delta}"
value2=STRING|"0"
[Actions\Action6]
ActionID=STRING|"A_VARIABLES_SET"
Enabled=INTEGER|-1
Name=STRING|"Set variable ""DELTA"" with value ""1"""
Params=FOLDER
[Actions\Action6\Params]
expand=STRING|"0"
varname=STRING|"DELTA"
varvalue=STRING|"1"
[Actions\Action7]
ActionID=STRING|"A_FLOW_ENDIF"
Enabled=INTEGER|-1
Name=STRING|"End If"
[Actions\Action8]
ActionID=STRING|"A_ROBOTASK_LOG"
Enabled=INTEGER|-1
Name=STRING|"Log Message"
Params=FOLDER
[Actions\Action8\Params]
message=STRING|"delta = {delta}"
type=STRING|"3"
[Actions\Action9]
ActionID=STRING|"A_LOOP_SIMPLE"
Enabled=INTEGER|-1
Name=STRING|"Simple Loop"
Params=FOLDER
[Actions\Action9\Params]
begin=STRING|"{delta}"
end=STRING|"{sz}"
variable=STRING|"NUM"
You can change the amount of the messages, look at the step #4
Oleg Yershov
-
- Posts: 70
- Joined: Thu Jul 02, 2015 3:54 pm
Re: Mail loop with last X mails
ok, It works. Thank you very much.
P.s.
I noticed that simple loop is slower than mail loop, this is my impression (can you confirm that?).
However I think that would be useful to add a Mail loop action where I can choose to start from the newest or last mail.
P.s.
I noticed that simple loop is slower than mail loop, this is my impression (can you confirm that?).
However I think that would be useful to add a Mail loop action where I can choose to start from the newest or last mail.
Re: Mail loop with last X mails
This task downloads the whole message, but Email loop reads only message headers if it's necessary.
Therefore you see that simple loop works a bit slower.
Maybe we will improve email loop actions (IMAP and POP3) in order to avoid such complex construction
I wrote the request into our ToDo.
Therefore you see that simple loop works a bit slower.
Maybe we will improve email loop actions (IMAP and POP3) in order to avoid such complex construction
I wrote the request into our ToDo.
Oleg Yershov