• Possible bug in msg_gettxt/msg_gethdr?

    From xqtr@21:1/111 to All on Sun Mar 8 09:48:23 2020
    I am writing a piece of code for one of my scripts and i get an unusual behavior. The code is the following, in MPY/python:

    msg = msg_open(mbase["path"] + mbase["filename"])
    if msg is None:
    writeln('|CL|CRno msgs.|PA')
    return

    msg_seek(msg, 0)
    while msg_found(msg) and not shutdown():
    msgbodies.append(msg_gettxt(msg))
    items.append(msg_gethdr(msg))
    msg_next(msg)
    msg_close(msg)

    So... in the msgbodies list i store all msg.text and in the items list all headers of msgs. The weird thing is that items[0], items[1], items[2] etc. contains the correct header information for each message, BUT msgbodies[0] shows weird text, msgbodies[1] shows text from msg stored in items[0], msgbodies[2] shows text from msg stored in items[1] etc. As a result i can't get also the text for the last message stored in the list, as i always get the one before.

    It's like get_msgtxt retrieves data as 1 based array but get_msghdr as 0 based array.

    Can someone confirm this?

    You can see it in action in my BBS at the main menu, by pressing !M, navigate through the groups/bases go to the msg list and check first and last message.

    :: XQTR :: Another Droid BBS :: andr01d.zapto.org:9999 :: xqtr@gmx.com

    --- Mystic BBS v1.12 A45 2020/02/18 (Raspberry Pi/32)
    * Origin: Another Droid BBS # andr01d.zapto.org:9999 (21:1/111)
  • From g00r00@21:1/108 to xqtr on Sun Mar 8 17:13:30 2020
    msg = msg_open(mbase["path"] + mbase["filename"])
    if msg is None:
    writeln('|CRno msgs.|PA')
    return

    msg_seek(msg, 0)
    while msg_found(msg) and not shutdown():
    msgbodies.append(msg_gettxt(msg))
    items.append(msg_gethdr(msg))
    msg_next(msg)
    msg_close(msg)

    msg_gethdr returns a dictionary and msg_gettxt returns a list. The contents of msgbodies and items are being created and populated byb data you are
    giving it. Mystic isn't populating them.

    Are you initializing the msgbodies and items lists anywhere? IE:

    msgbodies = []
    items = []

    msg_seek(msg, 0)
    while msg_found(msg) and not shutdown():
    msgbodies.append(msg_gettxt(msg))
    items.append(msg_gethdr(msg))
    msg_next(msg)
    msg_close(msg)

    --- Mystic BBS v1.12 A46 2020/03/08 (Windows/64)
    * Origin: Sector 7 (21:1/108)
  • From xqtr@21:1/111 to g00r00 on Sun Mar 8 13:33:44 2020
    msg_gethdr returns a dictionary and msg_gettxt returns a list. The contents of msgbodies and items are being created and populated byb data you are giving it. Mystic isn't populating them.
    Are you initializing the msgbodies and items lists anywhere? IE: msgbodies = []
    items = []

    Yes i initialize the lists the same way.

    while msg_found(msg) and not shutdown():
    msgbodies.append(msg_gettxt(msg))
    items.append(msg_gethdr(msg))
    msg_next(msg)
    msg_close(msg)

    I found the "bug" :) In my code i read first the msg text and after the header. It should be the other way around... that's why i was missing the text body of the first message. I realized it when i looked into the msgread.mpy example and noticed that first you read the header and after the body text.

    After changing the two lines my code works now. :)

    Thank you for the help.

    :: XQTR :: Another Droid BBS :: andr01d.zapto.org:9999 :: xqtr@gmx.com

    --- Mystic BBS v1.12 A45 2020/02/18 (Raspberry Pi/32)
    * Origin: Another Droid BBS # andr01d.zapto.org:9999 (21:1/111)
  • From g00r00@21:1/108 to xqtr on Sun Mar 8 22:02:59 2020
    I found the "bug" :) In my code i read first the msg text and after the header. It should be the other way around... that's why i was missing
    the text body of the first message. I realized it when i looked into the msgread.mpy example and noticed that first you read the header and after the body text.

    Awesome find!

    I was really struggling to figure out why it was messing up for you but that absolutely explains it. The way it is set up you do have to get the header before the text!

    --- Mystic BBS v1.12 A46 2020/03/08 (Windows/64)
    * Origin: Sector 7 (21:1/108)
  • From xqtr@21:1/111 to g00r00 on Mon Mar 9 12:23:36 2020
    Awesome find!
    I was really struggling to figure out why it was messing up for you but that absolutely explains it. The way it is set up you do have to get
    the header before the text!

    I thought that because you call the function like msg_gettxt(msg) it gets the data using the msg object and didn't require to read the header first.

    I feel like an idiot :) I was frustrated for many hours, many times trying to find what the hell i was doing wrong and it was in front of me all the time :)

    :: XQTR :: Another Droid BBS :: andr01d.zapto.org:9999 :: xqtr@gmx.com

    --- Mystic BBS v1.12 A45 2020/02/18 (Raspberry Pi/32)
    * Origin: Another Droid BBS # andr01d.zapto.org:9999 (21:1/111)
  • From g00r00@21:1/108 to xqtr on Mon Mar 9 19:58:01 2020
    I thought that because you call the function like msg_gettxt(msg) it
    gets the data using the msg object and didn't require to read the header first.

    I didn't really intend for it to work that way, but that is how it does work after looking at the code.

    I feel like an idiot :) I was frustrated for many hours, many times
    trying to find what the hell i was doing wrong and it was in front of me all the time :)

    Its totally my fault, sorry.. I should have realized that limitation and documented it.

    I have updated the msgread.mpy example in the new installation to mention that gethdr has to be called first.

    --- Mystic BBS v1.12 A46 2020/03/09 (Windows/64)
    * Origin: Sector 7 (21:1/108)