message_text

package
v1.99.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package message_text reads a Gmail message as text: its text/plain part, or, failing one, its text/html part with the markup taken out.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(data string) ([]byte, error)

Decode decodes data as Gmail serves it, base64url-encoded, with or without padding.

func FindTextPart

func FindTextPart(part *message_part.MessagePart, mimeType string) *message_part.MessagePart

FindTextPart returns the first part of the mime type that is text rather than an attachment, searching the parts in the order they appear. A message that is not multipart is its own single part.

func HtmlToText

func HtmlToText(source string) string

HtmlToText is the text a page would show, near enough to read: what is not shown is dropped, a link keeps its target, what breaks the line breaks it, the tags go, and the entities come back as the characters they stand for.

func NormalizeWhitespace

func NormalizeWhitespace(text string) string

NormalizeWhitespace is a text with one space between words, no trailing space on a line, and no more than one blank line in a row.

func Text

func Text(msg *message.Message) string

Text is the text of the message: its text/plain part, or, failing one, its text/html part read as text. A message with neither -- an image, a calendar invitation with no description -- has none.

Gmail serves a part's data in the message's own character set, which for mail is overwhelmingly UTF-8; what is not valid UTF-8 is read as Latin-1, which is right for the rest of what arrives and readable for anything else.

func TextWith added in v1.99.0

func TextWith(msg *message.Message, htmlToText func(source string) string) string

TextWith is Text with HTML read as text by htmlToText: the text/html part, and a text/plain part that is an HTML document in fact, as some senders' are. A text/plain part keeps its indentation and its runs of spaces, which line its columns up.

Types

This section is empty.

Jump to

Keyboard shortcuts

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