Class: Pikuri::Thunderbird::MailRead

Inherits:
Pikuri::Tool
  • Object
show all
Defined in:
lib/pikuri/thunderbird/mail_read.rb

Overview

The thunderbird_mail_read tool — the read half of the mail search→read pair. Given a message_id from thunderbird_mail_search, returns the full decoded body (Gloda has already MIME-decoded and HTML-stripped it, so no markup noise) plus headers and attachment names. Inbound-only.

Sharing: P_shared_locked — no state of its own, and the Gloda backend it queries locks; see that class's == Sharing.

Constant Summary collapse

MAX_BODY =

Returns hard cap on the body bytes returned (a runaway 50k-char body would swamp the context).

Returns:

  • (Integer)

    hard cap on the body bytes returned (a runaway 50k-char body would swamp the context).

40 * 1024
DESCRIPTION =

Returns opencode-shape description.

Returns:

  • (String)

    opencode-shape description.

<<~DESC
  Read one local Thunderbird message in full (headers, decoded plain-text body, attachment names).

  Usage:
  - Pass the id from a thunderbird_mail_search result.
  - Returns the full text; attachment contents are not opened, only their names are listed.
DESC

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(backend:) ⇒ MailRead

Parameters:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/pikuri/thunderbird/mail_read.rb', line 29

def initialize(backend:)
  @backend = backend
  super(
    name: 'thunderbird_mail_read',
    description: DESCRIPTION,
    parameters: Parameters.build { |p|
      p.required_string :message_id,
                        'The id from a search result, e.g. "<CAF..@mail.example.com>".'
    },
    execute: lambda { |message_id:|
      MailRead.run_read(backend: @backend, message_id:)
    },
    trifecta_legs: Pikuri::Thunderbird::INBOUND_LEGS
  )
end

Class Method Details

.run_read(backend:, message_id:) ⇒ String

Returns formatted message or "Error: …".

Returns:

  • (String)

    formatted message or "Error: …".



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/pikuri/thunderbird/mail_read.rb', line 46

def self.run_read(backend:, message_id:)
  rec = backend.read(message_id:)
  return "Error: no message found with id #{message_id.inspect}." unless rec

  attachments = rec[:attachment_names].to_s.strip
  <<~MSG.chomp
    Subject: #{rec[:subject]}
    From: #{rec[:from]}
    To: #{rec[:to]}
    Date: #{DateHelpers.short_datetime(rec[:date])}
    Folder: #{rec[:folder]}
    Attachments: #{attachments.empty? ? '(none)' : attachments}

    #{body(rec[:body])}
  MSG
end