Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/gmail-attachment-support.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@googleworkspace/cli": minor
---

feat(gmail): add --attachment flag to +send, +reply, +reply-all, +forward

Adds file attachment support to Gmail helper commands. The `--attachment` flag accepts comma-separated file paths and builds a proper MIME multipart/mixed message with base64-encoded attachments and auto-detected Content-Type.
21 changes: 15 additions & 6 deletions src/helpers/gmail/forward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ pub(super) async fn handle_forward(
(orig, Some(t))
};

let attachments = match matches.get_many::<String>("attachment") {
Some(paths) => read_attachments(&paths.cloned().collect::<Vec<_>>())?,
None => Vec::new(),
};

let subject = build_forward_subject(&original.subject);
let envelope = ForwardEnvelope {
to: &config.to,
Expand All @@ -45,7 +50,7 @@ pub(super) async fn handle_forward(
subject: &subject,
body: config.body_text.as_deref(),
};
let raw = create_forward_raw_message(&envelope, &original);
let raw = create_forward_raw_message(&envelope, &original, &attachments);

super::send_raw_email(
doc,
Expand Down Expand Up @@ -87,7 +92,11 @@ fn build_forward_subject(original_subject: &str) -> String {
}
}

fn create_forward_raw_message(envelope: &ForwardEnvelope, original: &OriginalMessage) -> String {
fn create_forward_raw_message(
envelope: &ForwardEnvelope,
original: &OriginalMessage,
attachments: &[Attachment],
) -> String {
let references = build_references(&original.references, &original.message_id_header);
let builder = MessageBuilder {
to: envelope.to,
Expand All @@ -107,7 +116,7 @@ fn create_forward_raw_message(envelope: &ForwardEnvelope, original: &OriginalMes
None => forwarded_block,
};

builder.build(&body)
builder.build_with_attachments(&body, attachments)
}

fn format_forwarded_message(original: &OriginalMessage) -> String {
Expand Down Expand Up @@ -187,7 +196,7 @@ mod tests {
subject: "Fwd: Hello",
body: None,
};
let raw = create_forward_raw_message(&envelope, &original);
let raw = create_forward_raw_message(&envelope, &original, &[]);

assert!(raw.contains("To: dave@example.com"));
assert!(raw.contains("Subject: Fwd: Hello"));
Expand Down Expand Up @@ -224,7 +233,7 @@ mod tests {
subject: "Fwd: Hello",
body: Some("FYI see below"),
};
let raw = create_forward_raw_message(&envelope, &original);
let raw = create_forward_raw_message(&envelope, &original, &[]);

assert!(raw.contains("Cc: eve@example.com"));
assert!(raw.contains("Bcc: secret@example.com"));
Expand Down Expand Up @@ -256,7 +265,7 @@ mod tests {
subject: "Fwd: Hello",
body: None,
};
let raw = create_forward_raw_message(&envelope, &original);
let raw = create_forward_raw_message(&envelope, &original, &[]);

assert!(raw.contains("In-Reply-To: <msg-2@example.com>"));
assert!(
Expand Down
Loading
Loading