Sign in to follow this  
Followers 0
shiv

want to get value displayed b/w < > against a string

19 posts in this topic

Hi Friends,

I am using your pop3 functions to read the contents of mail using telnet.

I am successfully able to read the subject from backend.

to compare the mail subject i am using the following code:
 

Func _Pop3Retr($msg)
    If $pop3_IsAuth = 1 Then
        Local $ret

        ; Send Retr
        $ret = TCPSend ($pop3_socket, "RETR " & $msg & @CRLF)
        If @error Then
            SetError($pop3_error_retr_refused)
            Return -1
        EndIf
        $ret = _Pop3WaitForOK()
        If @error Then
            SetError($pop3_error_no_OK_response)
            Return -1
        EndIf

        ; Downloading until final dot and cariage return.
        While Not StringRegExp($ret, "\r\n\.\r\n")
            $ret = $ret & _WaitTcpResponse()
            If @error Then
                SetError($pop3_error_no_TCP_response)
                Return -1
            EndIf
        WEnd
        Return $ret
    Else
        SetError($pop3_error_no_auth)
        Return -1
    EndIf
EndFunc   ;==>_Pop3Retr

Local $sRet =_Pop3Retr(1)

$aArray = StringRegExp($sRet, $sMailSubject , 2) ; here mail subject is alreay known to me


But the mail contents also shows Message-ID: <000001cf75a9c71d40$5557c634780$@test.gmail.com> for the particular mail

the string Message-ID will always be there, as this message ID(000001cf75a9c71d40$5557c634780$) is randomly generated

I want to store the value "000001cf75a9c71d40$5557c634780$@test.gmail.com" in a variable by compairing it with string  Message-ID:<  want to read this value and stored in a variable  >

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

HINT:

SRE:
 

(?i)(?:Message-ID: <)(.*?)(?:>)
Edited by mLipok

Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

Thanks tried this one but getting the complete string

Message-ID: <000001cf75a9c71d40$5557c634780$@test.gmail.com>

i just want to get 000001cf75a9c71d40$5557c634780$@test.gmail.com     or      <000001cf75a9c71d40$5557c634780$@test.gmail.com>

Please reply i am stuck with this

Share this post


Link to post
Share on other sites

show here how you use my tip 


Signature beginning:   Wondering who uses AutoIT and what it can be used for ?
* GHAPI UDF - modest begining - comunication with GitHub REST API *
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST API *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 - BETA * ADO.au3 UDF SMTP Mailer UDF *

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Best coding practices * 

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * 

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2017-06-04

Share this post


Link to post
Share on other sites

Hi Done it using the following code:

    
    Local $sGetMessageId ="Message-ID: "& "<" &"(.+)"&">"
    $aArray = StringRegExp($sRet,$sGetMessageId,2)
    Local $Mid = StringRegExpReplace($aArray[0],"Message-ID: ","")

now i woulld get <000001cf75a9c71d40$5557c634780$@test.gmail.com> which is fine

But These is one more value "In-Reply-To" which contains some ID ,  i am using the same code[Local $sGetMessageId ="In-Reply-To: "& "<" &"(.+)"&">"] as above to match the value but
it shows no match is found however the In-Reply-To is present.  
can  we have some other way to match this string
 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

?

#Include <Array.au3>

$str = "some text" & @crlf & _ 
    "Message-ID: <000001cf75a9c71d40$5557c634780$@test.gmail.com>" & @crlf & _ 
    "some other text" & @crlf & _ 
    "In-Reply-To: <000001something_else@test.gmail.com>"

$res = StringRegExp($str, '(?s)<(.+?)>', 3)
_ArrayDisplay($res)

To get the first one only (being more restrictive) :

$res = StringRegExp($str, '(?s)Message-ID:\h*<(.+?)>', 3)
Edited by mikell

Share this post


Link to post
Share on other sites

Hi Mikell,

the value of $srt is not known to me. i am reading the string using pop functions as i have mentioned above.

the thing is

Local $sGetReplyID ="In-Reply-To: "& "<" &"(.+)"&">" 

  $aArray = StringRegExp($sRet,$sGetReplyID,2)

is not able to match the string "In-Reply-To" as it is working for Message-ID .

Please provide some how i can do this

Share this post


Link to post
Share on other sites

Local $s, $str = "some text" & @CRLF & _
        "Message-ID: <000001cf75a9c71d40$5557c634780$@test.gmail.com>" & @CRLF & _
        "some other text" & @CRLF & _
        "In-Reply-To: <000001something_else@test.gmail.com>"


$s = StringRegExpReplace($str, '(?is).*Message-ID:\s<(.*?)>.*', '\1')
If @extended Then MsgBox(0, '', $s)

$s = StringRegExpReplace($str, '(?is).*In-Reply-To:\s<(.*?)>.*', '\1')
If @extended Then MsgBox(0, '', $s)


Make yourself sheep and the wolves will eat you - Benjamin Franklin

Share this post


Link to post
Share on other sites

Hi Thanks a lot ,

But getting the string in following formats:

1. sometime get:

In-Reply-To: <000001cf78ac
$eee7cb30$ccb76190$@exchange2007.test.gmail.com>

2. Sometimes get

In-Reply-To:
<000001cf78ac$eee7cb30$ccb76190$@exchange2007.test.gmail.com>

As we can see above sometime the <id> is in next line as in (2), and sometimes some of the contents are in the same line(1) in which "In-Reply-To" is,and the remaining comes in next line as shown above.
I do not understand how to use regular expression for this.
 

Share this post


Link to post
Share on other sites

OK please try this

$str1 = "some text" & @CRLF & _
    "In-Reply-To: <000001cf78ac" & @CRLF & _
        "$eee7cb30$ccb76190$@exchange2007.test.gmail.com>" & @CRLF & _
        "some other text"

$str2 = "some text" & @CRLF & _
    "In-Reply-To: " & @CRLF & _
        "<000001cf78ac$eee7cb30$ccb76190$@exchange2007.test.gmail.com>" & @CRLF & _
        "some other text"

MsgBox(0, '', StringRegExpReplace($str1, '(?is).*In-Reply-To:\s*<(\N*)\R?(\N*)>.*', '$1$2') )

MsgBox(0, '', StringRegExpReplace($str2, '(?is).*In-Reply-To:\s*<(\N*)\R?(\N*)>.*', '$1$2') )

Share this post


Link to post
Share on other sites

Not getting what you are saying,  we can not use two variables $str1 and $str2. i have only one variables which is storing the complete data , and i am searching the particular string f.ex

"In-Reply-To:<id> which would be a unique string that is present in a siongle variable. and i am not declaring this string of my own. instead i am using pop3 function mention at the top to get the complete 

data which contains this in-reply-to, but problem is this "In-Reply-To:" comes with different patterns as i mentioned in the last comment.

But i think there can be 1 more resolution to it . suppose if we remove the "n" for every line. i.e. suppose if there are 100 lines in a file, can we use some regular expression which removes all the n and convert it into single line .

then we would not be getting this issue any more . but i am very slow in regx, i am trying but not able to succeed.

Please

Share this post


Link to post
Share on other sites

This time has got the data like attached in file

output.txt

Share this post


Link to post
Share on other sites

$str1 and $str2 were only examples

Using your text file :

$str = FileRead("output.txt")

MsgBox(0, '', StringRegExpReplace($str, '(?is).*In-Reply-To:\s*<(\N*)\R?(\N*)>.*', '$1$2') )

Share this post


Link to post
Share on other sites

HI ,Tried this one not working

Share this post


Link to post
Share on other sites

This time got as shown in attachment

output2.txt

Share this post


Link to post
Share on other sites


StringRegExpReplace($str, '(?is).*In-Reply-To:\s*<(\N*)\R?(\N*)>.*', '$1$2') )

Can you please explain the above regx

like-

s for white space

-N- for  next line

(?is) not understood is

R? not understood

$1$2  not understood

Please........... explain the above





			
		

Share this post


Link to post
Share on other sites

#17 ·  Posted (edited)

Hum, my code above works with your output2.txt file too  :huh:

Maybe this ?

$str = FileRead("output2.txt")
$str = StringStripWS($str, 8)    ; this strips all white spaces and newlines
MsgBox(0, '', StringRegExpReplace($str, '.*In-Reply-To:<(.*?)>.*', '$1') )

Edit

All the defs are in the helpfile, i.e.

StringRegExpReplace($str, '(?is).*In-Reply-To:\s*<(\N*)\R?(\N*)>.*', '$1$2') 

\N  Matches any character except a newline sequence regardless of option (?s).
\s   Matches any whitespace character 
*   0 or more, greedy
\R  Matches any Unicode newline sequence by default (...). By default \R matches "(?>\r\n|\n|\r)" where "(?>...)" is an atomic group, making the sequence "\r\n" (@CRLF) unbreakable
(?s) Single-line or DotAll: . matches anything including a newline sequence. By default, DotAll is off hence . does not match a newline sequence. 
(?i) Caseless: matching becomes case-insensitive from that point on. By default, matching is case-sensitive.  
Options can be grouped together: "(?is)".
$1$2  back-references to the2  matched groups
Edited by mikell

Share this post


Link to post
Share on other sites

Thank you very much

its working :thumbsup:

Share this post


Link to post
Share on other sites

Hallelujah  :D

Glad I could help

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0