Jump to content

array fixes


KingNED
 Share

Recommended Posts

I'm trying to get a mail read out using the Outlook include, and read certain variables into an array.

the basics work, but the array seems to be misbehaving to me :(

$oOutlook = _OutlookOpen()
$getMail = _OutlookGetMail($oOutlook, "\altbox", False, "", "", "", "", "ReadMailAU3 test")
If @error > 0 Then MsgBox(4096,"Get Mail Error",@error,600)
$toread = $getMail[1][9]
$bodyArray = StringSplit($toread), @CR)
_ArrayDisplay($bodyArray)

but then what it returns is:

[0]|6
[1]|Var1: value1
[2]|
[3]|Var2: value2
[4]|
[5]|Var3: value3
[6]|

What I'm trying to achieve is get only:

[0] # of entries

[1]Value1

[2]Value2

[3]Value3

Any help would be appreciated :graduated:

Link to comment
Share on other sites

I think it's because $toread is a 2 dimensional array !

What display $toread ?

$toread is email number 1, part 9 (the body of the mail)

i've found a partial fix, but it involves modifying the mail itself before sending it.

By sending it as plain text, it'll only get the things needed, but with one white spot in the array again at the end.

Since customers also have to use this, it isn't really something that we want to do that way.

it seems that somehow the mail being sent as HTML is creating a problem for it.

Link to comment
Share on other sites

A bit of a gamble, but what happens if you add

$toread = StringStripWS($toread,BitOR(1,2,4)) ;strip all double spaces and whitespace

above the stringsplit?

That returns:

[0]|Var1: Value1Var2: Value2Var3: Value3Variable: Value

that's *partially* what i need, now i need, that it reads fields like:

Name: Value1

Address: Value2

Telephone: Value3

E-mail:

in whatever sequence they come in, put the Value things which can be just about anything, into an array so i can process it further.

like:

[0]Value1

[1]Value2

[2]Value3

etc

*While keeping the values in the correct order, so if name comes at the bottom, it should still be in it's original place in the array.

*the array should always have to values in the same place.

Edited by KingNED
Link to comment
Share on other sites

What about this:

#include <Array.au3>
$oOutlook = _OutlookOpen()
$getMail = _OutlookGetMail($oOutlook, "\altbox", False, "", "", "", "", "ReadMailAU3 test")
If @error > 0 Then MsgBox(4096,"Get Mail Error",@error,600)
$bodyArray = StringRegExp($getMail[1][9],".*?:(.*)(?:\v|\z)",3)
_ArrayDisplay($bodyArray)

or

#include <Array.au3>
$oOutlook = _OutlookOpen()
$getMail = _OutlookGetMail($oOutlook, "\altbox", False, "", "", "", "", "ReadMailAU3 test")
If @error > 0 Then MsgBox(4096,"Get Mail Error",@error,600)
$bodyArray = StringRegExp($getMail[1][9],"(.*?:.*)(?:\v|\z)",3)
_ArrayDisplay($bodyArray)

edit: copy/paste fail

Edited by Tvern
Link to comment
Share on other sites

Thanks :graduated:

I've been working on the code now, and it is working quite well, it now reads the mail, and puts everything in an associative array.

quick, easy access without the problem of having the values in the wrong positions.

Also made a function out of it so it can just keep checking it the entire time.

#include <Outlook.au3>
#include <AssocArrays.au3>
HotKeySet("^!x", "FuncExit")

Func ProcessMail()
    $avArray=""
    AssocArrayCreate($avArray, 10)
    $oOutlook = _OutlookOpen()
    $getMail = _OutlookGetMail($oOutlook, "\traag", False, "", "", "", "", "ReadMailAU3 test")
    If @error > 0 Then MsgBox(4096,"Get Mail Error",@error,600)
    $bodyArray = StringRegExp($getMail[1][9],"(.*?:.*)(?:\v|\z)",3)
    ;_ArrayDisplay($bodyArray)

    FOR $result IN $bodyArray
        $result2 = StringSplit(StringStripWS($result,BitOR(1,2,4)), ": ", 1)
        AssocArrayAssign($avArray, $result2[1], $result2[2])
        ;_ArrayDisplay($result2)
    Next

    $asKeys = AssocArrayKeys($avArray)
    $sName = ""
    For $iCount = 0 To UBound($asKeys) - 1
        $sName &= "[" & $asKeys[$iCount] & "] = " & AssocArrayGet($avArray, $asKeys[$iCount]) & @CR
    Next

    MsgBox(64, "AssocArray Test", $sName)
    _OutlookClose()
EndFunc

While 1=1
    ProcessMail()
    Sleep(20000)
WEnd

Func FuncExit()
    Exit
EndFunc
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...