• src/sbbs3/getmsg.cpp readmail.cpp readmsgs.cpp sbbs.h

    From Rob Swindell (on Debian Linux)@1:103/705 to Git commit to main/sbbs/master on Tue Jul 28 19:54:10 2026
    https://gitlab.synchro.net/main/sbbs/-/commit/a81d979492c81cc5e982a00d
    Modified Files:
    src/sbbs3/getmsg.cpp readmail.cpp readmsgs.cpp sbbs.h
    Log Message:
    Message listings: convert header fields before formatting them

    A message-listing line reserves its name columns in bytes: the stock MailOnSystemLstFmt and SubMsgLstFmt are "%-22.22s". When a from, to or
    subject field holds non-ASCII text those two counts diverge -- the field
    is 22 bytes but fewer than 22 screen columns -- and every column to its
    right slides left by the difference.

    bprintf() formats first and converts the character set afterwards, in
    bputs(), so the conversion cannot inform the field widths. Hand the
    listing call sites fields that are already in the terminal's character
    set: on a CP437, ASCII or PETSCII terminal one byte is then one column
    and the existing format strings measure exactly what they display. This
    also removes the mid-sequence truncation the byte-counted precision
    could inflict, which rendered an orphaned byte as a garbage glyph and
    logged "Invalid UTF-8 sequence" once per listed message.

    The ten call sites in readmail.cpp and readmsgs.cpp share one helper, list_msg(), which converts the fields, selects the format string in the matching character set, and sets P_UTF8 only for a terminal that can
    take it. Anonymity moves into a parameter so text[Anonymous] keeps
    bypassing conversion.

    msghdr_field() gains an overload taking the destination size. The
    existing one always copied sizeof(msgghdr_field_cp437_str) - 1 bytes
    regardless of the buffer it was handed, so a caller-supplied buffer had
    to happen to be at least that large; it now delegates. The sized form
    copies with utf8_strlcpy() so a truncated copy cannot end part-way
    through a multi-byte sequence.

    Terminals that speak UTF-8 are still misaligned here; the field widths
    reaching printf are still counted in bytes for them.

    Issue #1204

    Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
    --- SBBSecho 3.37-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)