Jump to content

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


Recommended Posts

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  >

Link to comment
Share on other sites

HINT:

SRE:
 

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

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor 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 APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

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 * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

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) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

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 *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"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: 2023-04-24

Link to comment
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

Link to comment
Share on other sites

show here how you use my tip 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor 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 APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

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 * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

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) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

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 *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"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: 2023-04-24

Link to comment
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
 

Link to comment
Share on other sites

?

#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
Link to comment
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

Link to comment
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)

"The mediocre teacher tells. The Good teacher explains. The superior teacher demonstrates. The great teacher inspires." -William Arthur Ward

Link to comment
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.
 

Link to comment
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') )
Link to comment
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

Link to comment
Share on other sites

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
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...