util

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2026 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MessageColumns = []string{"Date", "Size", "From", "To", "Subject"}

MessageColumns are the message-table column headers, in order. The leading status column is intentionally omitted: unread state is carried on each MessageRow (rendered as bold), and the interactive picker prepends its own checkbox column. This is the single source of truth shared by the static table renderer and the picker.

Functions

func BoolPtr

func BoolPtr(b bool) *bool

Helper function to create a bool pointer

func DateFromString

func DateFromString(dateStr string) (time.Time, error)

DateFromString takes a date string of format "yyyy-mm-dd" and returns a Time

func FormatSize added in v1.1.0

func FormatSize(size uint32) string

FormatSize renders a byte count as a short human-readable string using binary units, e.g. 1572864 -> "1.5M".

func GetConfirmation

func GetConfirmation(prompt string) bool

GetConfirmation prompts the user for confirmation before proceeding

func IsUnread added in v1.3.0

func IsUnread(flags []string) bool

IsUnread reports whether a message lacks the \Seen flag.

func ParseSize added in v1.1.0

func ParseSize(text string) (uint32, error)

ParseSize parses a human-friendly size string into a number of bytes. It accepts a bare byte count ("1024") or a value with a binary unit suffix (K/KB, M/MB, G/GB, case-insensitive), e.g. "10M" = 10 MiB. The result must fit in a uint32, which is what IMAP SEARCH LARGER/SMALLER use.

func RenderFolders added in v1.3.0

func RenderFolders(folders []imaputils.FolderStatus, withDates bool) string

RenderFolders renders a folder listing with message and unread counts as a table string in the shared style. When withDates is true it also includes the date range of each folder's messages. Non-selectable container folders (and empty folders, for dates) show "-". The numeric count columns are right-aligned.

func RenderMessages added in v1.3.0

func RenderMessages(messages []*imap.Message) (string, error)

RenderMessages renders messages as a table string for static (non-interactive) display: the shared columns, with unread rows in bold (replacing the old dot column) and a trailing count caption. Borders are reduced to a single header rule so the static view matches the interactive picker, which draws the same shape plus a leading checkbox column.

func RenderSenders added in v1.3.0

func RenderSenders(data [][]string) string

RenderSenders renders sender/count data (data[0] is the header row) as a table string in the shared style, with the trailing count column right-aligned.

func SelectMessages added in v1.3.0

func SelectMessages(messages []*imap.Message, action string, confirmRequired bool) (kept []*imap.Message, committed bool, err error)

SelectMessages runs the interactive picker over messages (all pre-selected) and returns the subset the user keeps. committed is false when the user cancels, in which case the caller must not act. action labels the pending operation in the picker header (e.g. "delete", "move to Archive"). confirmRequired adds a final confirmation screen for state-changing actions (copy/move/delete); pass false for trivially reversible ones (mark read).

func StringPtr

func StringPtr(s string) *string

Helper function to create a string pointer

func TimePtr

func TimePtr(t time.Time) *time.Time

Helper function to create a time pointer

func TruncateString

func TruncateString(str string, maxLength int) string

TruncateString truncates a string to the specified length and appends an ellipsis if needed.

func Uint32Ptr added in v1.1.0

func Uint32Ptr(value uint32) *uint32

Helper function to create a uint32 pointer

func UnreadMarker added in v1.1.0

func UnreadMarker(flags []string) string

UnreadMarker returns a dot for messages lacking the \Seen flag (unread) and an empty string for read messages, for use as a compact status indicator.

Types

type MessageDate

type MessageDate struct {
	Original   time.Time
	Normalized time.Time
}

MessageDate represents a normalized message date with timezone handling

func NewMessageDate

func NewMessageDate(internalDate time.Time) MessageDate

NewMessageDate creates a new MessageDate from an IMAP internal date

func (MessageDate) FormatConsistent

func (md MessageDate) FormatConsistent(timezone *time.Location) string

FormatConsistent returns a consistently formatted date string in the specified timezone

func (MessageDate) LocalizeToZone

func (md MessageDate) LocalizeToZone(timezone *time.Location) time.Time

LocalizeToZone returns the date in the specified timezone

type MessageRow added in v1.3.0

type MessageRow struct {
	Cells  []string
	Unread bool
}

MessageRow is one formatted message: its cells (aligned 1:1 with MessageColumns) and whether the message is unread, so renderers can style unread rows rather than carrying a separate marker column.

func FormatMessageRows added in v1.3.0

func FormatMessageRows(messages []*imap.Message) ([]MessageRow, error)

FormatMessageRows formats messages into display rows, the single source of truth for how a message renders. Cells are pre-truncated to their column widths. A message without an envelope (malformed or partial fetch) falls back to placeholders rather than panicking.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL