Parse email and link from multiple emails/email ids

Hi I am trying to parse a link and the TO email from multiple emails in my inbox how would I do that without repeating the same parse blocks and Imap Read Mail blocks 100 times

For loop would do it, search the forums for more info but that should be able to do it no problem.

I can’t figure it out please help. I can get it to loop the the same Imap Read Mail and 2 parse block for the link and email but I can only do it for 1 of the ids in the list which would be the first one since its <List[0]>
also when its done it doesn’t show the parses in the variable tab not sure why

What does your loop script look like. Here is a test I just tried that did a search and then looped thru all of the found emails and read them

BLOCK:ImapSearchMails

  text1 = "test"

  => VAR @imapSearchMailsOutput

ENDBLOCK

for (int i = 0; i < imapSearchMailsOutput.Count; i++){

BLOCK:ImapReadMail

  id = $"<imapSearchMailsOutput[i]>"

  => VAR @imapReadMailOutput

ENDBLOCK

}

okay so that works now how would I save the results of the parses? because it still doesn’t appear in the variables tab or get marked as capture if I have it on

when I try to use a add to list function or something it turns the variables into “System.Collections.Generic.List`1[System.String]”

Did you create a list and add to that list?

BLOCK:ImapSearchMails
  text1 = "openbullet"
  text2 = "[email protected]"
  => VAR @imapSearchMailsOutput
ENDBLOCK

BLOCK:ConstantList
  value = []
  => VAR @maillist
ENDBLOCK

for (int i = 0; i < imapSearchMailsOutput.Count; i++){
BLOCK:ImapReadMail
  id = $"<imapSearchMailsOutput[i]>"
  => VAR @test
ENDBLOCK

BLOCK:AddToList
  list = @maillist
  item = @test
ENDBLOCK
}

BLOCK:GetListLength
  list = @maillist
  => VAR @getListLengthOutput
ENDBLOCK

ImapSearchMails - Search for emails
ConstantList - Create a list

Begin Loop through the found emails
ImapReadMail - Read email and save to test
AddToList - add test to maillist
End Loop

GetListLength - Verify mails have been added to list

1 Like

thats basically what I have but instead of adding @test to the list its $"<link1>:<email2>" but it just turns both link1 and email2 into System.Collections.Generic.List`1[System.String]

Please tell me you set the parse Input to the Imap Read’s output, because its working for me

for (int i = 0; i < imapSearchMailsOutput.Count; i++){
BLOCK:ImapReadMail
  id = $"<imapSearchMailsOutput[i]>"
  => VAR @test
ENDBLOCK

BLOCK:Parse
  input = @test
  pattern = "To\\:\\s\\w+\\@\\w+\\.com"
  outputFormat = "[0]"
  MODE:Regex
  => VAR @parseOutput2
ENDBLOCK

BLOCK:Parse
  input = @test
  leftDelim = "[Visit Topic]("
  rightDelim = ")"
  MODE:LR
  => VAR @parseOutput
ENDBLOCK

BLOCK:AddToList
  list = @maillist
  item = $"<parseOutput>:<parseOutput2>"
ENDBLOCK
}

1 Like

Heres my config

BLOCK:ImapAutoConnect
  email = "[email]"
ENDBLOCK

BLOCK:ImapLogin
  email = "[email]"
  password = "[pass]"
ENDBLOCK

BLOCK:ImapSearchMails
  text1 = " [text]"
  text2 = "[text]"
  => VAR @imapSearchMailsOutput
ENDBLOCK

BLOCK:ConstantList
  value = []
  => VAR @constantListOutput
ENDBLOCK
for (int i = 0; i < imapSearchMailsOutput.Count; i++){
BLOCK:ImapReadMail
  id = $"<imapSearchMailsOutput[i]>"
  preferHtml = True
  => VAR @imapReadMailOutput
ENDBLOCK

BLOCK:Parse
  input = @imapReadMailOutput
  leftDelim = "Click on the link <strong><a href=\"https:"
  rightDelim = "\">here</a></"
  RECURSIVE
  MODE:LR
  => CAP @link1
ENDBLOCK

BLOCK:Parse
  input = @imapReadMailOutput
  suffix = ".com"
  leftDelim = "To: \""
  rightDelim = ".com>"
  RECURSIVE
  MODE:LR
  => VAR @email1
ENDBLOCK

BLOCK:Parse
  input = @email1
  suffix = ".com"
  leftDelim = "\" <"
  rightDelim = ".com"
  RECURSIVE
  MODE:LR
  => CAP @email2
ENDBLOCK

BLOCK:AddToList
  list = @constantListOutput
  item = $"<link1>:<email2>"
ENDBLOCK
}

I’m not that good with parsing from email so its a mess but as far as I can tell its basically the same

I dont know how your emails look but my To: address does not have a "; i.e. To: “”

But try changing the parse to Regex and using this to start with, how many links are in the email that you need such a long LR?

pattern = "To\\:\\s(?<email>\\w+\\@\\w+\\.com)"
outputFormat = "[1]"

Also I can check your parse on the weblink if you want to DM me a sample of one of the emails.

that doesn’t work for me I guess because the to comes as “[first] [last] [email]” anyways I can parse the email just fine but I don’t know why when I do the add to list it changes them to the “System.Collections.Generic.List`1[System.String]”

If its the same format as From line then this should work with the same capture group [1]

To\:.+\"\s\<(?<email>.+\@\w+\.\w+)\>

But I have no idea what you mean by “System.Collections.Generic.List`1[System.String]” as I cant reproduce it


thats what I mean by “System.Collections.Generic.List”

Is you Add to list set to -1 for index?

Also what happens if you create a string first then add to list

i.e.

Constant String - :
then just add the constant string var

yes
[character limit]

Well then I cant help you as I cant reproduce it, sorry man hopefully someone else can help

so sorry just figured out why and it was because I had recursive on not sure why that breaks it but I fixed it

Glad you got it sorted