mailinfo Git Command Guide
The git mailinfo command reads a single email message from standard input and extracts the commit log message and patches, writing the commit message to a file and patches to another file. It extracts author name, email, and subject for use by git am to create commits.
git mailinfo Syntax:
Section titled “git mailinfo Syntax:”git mailinfo [-k|-b] [-u | --encoding=<encoding> | -n] [--[no-]scissors] [--quoted-cr=<action>] <msg> <patch>Email Processing Options:
Section titled “Email Processing Options:”| Option | Description |
|---|---|
-k | Keep email cruft in Subject header |
-b | Remove email cruft from Subject header |
-u | Convert email encoding to UTF-8 |
--encoding=<encoding> | Specify email encoding |
-n | Don’t convert email encoding |
--scissors | Enable scissors detection |
--no-scissors | Disable scissors detection |
--quoted-cr=<action> | Handle quoted CR (warn/crlf/convert) |
Parameters:
Section titled “Parameters:”| Parameter | Description |
|---|---|
<msg> | File to write commit log message to |
<patch> | File to write patches to |
Email Format Processing:
Section titled “Email Format Processing:”Standard Email Structure:
Section titled “Standard Email Structure:”From: Author Name <author@example.com>Date: Thu, 01 Jan 2023 12:00:00 +0000Subject: [PATCH] Add new feature
Commit message here
---Patch content hereScissors Detection:
Section titled “Scissors Detection:”# Scissors line separates message from patch-- >8 --<commit message>
<patch content>Quoted CR Handling:
Section titled “Quoted CR Handling:”# Handle different line ending styles--quoted-cr=warn # Warn about quoted CR--quoted-cr=crlf # Convert to CRLF--quoted-cr=convert # Convert quoted CR to LFBasic Usage Examples:
Section titled “Basic Usage Examples:”Extract Patch from Email:
Section titled “Extract Patch from Email:”# Read email from stdin, extract message and patchcat email.eml | git mailinfo msg.txt patch.txt
# Process email with specific encodingcat email.eml | git mailinfo --encoding=iso-8859-1 msg.txt patch.txt
# Preserve email formatting in subjectcat email.eml | git mailinfo -k msg.txt patch.txtEmail Processing Pipeline:
Section titled “Email Processing Pipeline:”# Complete email to patch workflowcat email.eml | git mailinfo msg.txt patch.txtecho "$(cat msg.txt)" | git am --patch-format=mbox patch.txt
# Process multiple emailsfor email in *.eml; do base=$(basename "$email" .eml) cat "$email" | git mailinfo "${base}-msg.txt" "${base}-patch.txt"doneAdvanced Email Processing:
Section titled “Advanced Email Processing:”# Handle emails with scissorscat email-with-scissors.eml | git mailinfo --scissors msg.txt patch.txt
# Process with UTF-8 conversioncat international-email.eml | git mailinfo -u msg.txt patch.txt
# Custom quoted CR handlingcat windows-email.eml | git mailinfo --quoted-cr=convert msg.txt patch.txtIntegration with Git Workflows:
Section titled “Integration with Git Workflows:”Automated Patch Processing:
Section titled “Automated Patch Processing:”#!/bin/bash# Process incoming email patches
# Extract message and patchcat email.eml | git mailinfo commit-msg.txt patch-file.txt
# Apply patch if extraction successfulif [ -s "patch-file.txt" ]; then git am --patch-format=mbox patch-file.txt
# Clean up temporary files rm commit-msg.txt patch-file.txtelse echo "No patch found in email" exit 1fiEmail Client Integration:
Section titled “Email Client Integration:”# Process emails from mail client# Save email as .eml file, then processcat saved-email.eml | git mailinfo -u commit-msg.txt patch.txt
# Apply with proper authorshipAUTHOR_INFO=$(cat commit-msg.txt | head -1)echo "Patch from: $AUTHOR_INFO"git am patch.txtBatch Email Processing:
Section titled “Batch Email Processing:”# Process multiple email patchesfor eml_file in patch-emails/*.eml; do base=$(basename "$eml_file" .eml)
# Extract patch information cat "$eml_file" | git mailinfo "${base}-msg.txt" "${base}-patch.txt"
# Apply if patch exists if [ -s "${base}-patch.txt" ]; then git am "${base}-patch.txt" echo "Applied patch: $base" fidoneEmail Format Handling:
Section titled “Email Format Handling:”Subject Line Processing:
Section titled “Subject Line Processing:”# Default behavior (remove cruft)# Input: [PATCH v2] Add feature# Output: Add feature
# Keep cruft with -k# Input: [PATCH v2] Add feature# Output: [PATCH v2] Add feature
# Custom processingcat email.eml | git mailinfo -b msg.txt patch.txt # Remove cruftMessage Body Extraction:
Section titled “Message Body Extraction:”# Extract commit messagecat email.eml | git mailinfo msg.txt patch.txtcat msg.txt # Shows extracted commit message
# Handle multi-part messagescat multipart-email.eml | git mailinfo --scissors msg.txt patch.txtPatch Content Handling:
Section titled “Patch Content Handling:”# Extract patch to filecat patch-email.eml | git mailinfo msg.txt patch.txtls -la patch.txt # Shows extracted patch
# Process inline patchescat inline-patch.eml | git mailinfo msg.txt patch.txtConfiguration and Customization:
Section titled “Configuration and Customization:”Encoding Configuration:
Section titled “Encoding Configuration:”# Configure default encodinggit config mailinfo.encoding UTF-8
# Handle specific email clientsgit config mailinfo.scissors true
# Configure CR handlinggit config mailinfo.quotedcr convertCustom Processing Rules:
Section titled “Custom Processing Rules:”# Custom email processing script#!/bin/bash# Enhanced mailinfo processing
# Extract with custom optionscat "$1" | git mailinfo \ --encoding=UTF-8 \ --scissors \ --quoted-cr=convert \ "${1%.eml}-msg.txt" \ "${1%.eml}-patch.txt"
# Validate extractionif [ -s "${1%.eml}-patch.txt" ]; then echo "Patch extracted successfully"else echo "No patch found in email"fiTroubleshooting Common Issues:
Section titled “Troubleshooting Common Issues:”Email Format Problems:
Section titled “Email Format Problems:”# Check email formatcat email.eml | head -20
# Test with known good emailcat good-email.eml | git mailinfo test-msg.txt test-patch.txt
# Debug encoding issuescat email.eml | git mailinfo --encoding=UTF-8 msg.txt patch.txtPatch Extraction Issues:
Section titled “Patch Extraction Issues:”# Check if patch was extractedls -la patch.txtcat patch.txt | head -5
# Verify message extractioncat msg.txt
# Manual patch extraction if neededgrep -A 1000 "^---$" email.eml > manual-patch.txtScissors Detection:
Section titled “Scissors Detection:”# Check for scissors linecat email.eml | grep -n ">8\|--8<\|-- >8"
# Force scissors processingcat email.eml | git mailinfo --scissors msg.txt patch.txt
# Disable scissors if causing issuescat email.eml | git mailinfo --no-scissors msg.txt patch.txtEncoding Problems:
Section titled “Encoding Problems:”# Detect email encodingcat email.eml | grep -i "content-type" | head -1
# Try different encodingscat email.eml | git mailinfo --encoding=iso-8859-1 msg.txt patch.txt
# Convert encoding manuallyiconv -f iso-8859-1 -t utf-8 email.eml | git mailinfo -u msg.txt patch.txtReal-World Usage Examples:
Section titled “Real-World Usage Examples:”Open Source Patch Processing:
Section titled “Open Source Patch Processing:”#!/bin/bash# Process patches from mailing list
# Download email from listcurl -s "https://lists.example.com/msg.eml" > patch.eml
# Extract patch informationcat patch.eml | git mailinfo commit-msg.txt patch.txt
# Apply patch with proper authorshipif [ -s "patch.txt" ]; then # Get author information from email author=$(cat commit-msg.txt | head -1) echo "Applying patch from: $author"
# Apply patch git am --patch-format=mbox patch.txt
# Clean up rm commit-msg.txt patch.txt patch.emlelse echo "No patch found in email"fiCorporate Email Integration:
Section titled “Corporate Email Integration:”# Process internal code review emails
# Extract review informationcat review-email.eml | git mailinfo \ --encoding=UTF-8 \ --scissors \ review-msg.txt review-patch.txt
# Apply with review trackingif [ -s "review-patch.txt" ]; then git am review-patch.txt
# Add review notes git notes add -m "Reviewed: $(date)" HEAD git notes append -m "Reviewer: $(git config user.name)"fiAutomated Patch Validation:
Section titled “Automated Patch Validation:”#!/bin/bash# Validate incoming patches
validate_patch() { local email_file="$1"
# Extract patch cat "$email_file" | git mailinfo msg.txt patch.txt
# Check if patch extracted if [ ! -s "patch.txt" ]; then echo "ERROR: No patch found in $email_file" return 1 fi
# Validate patch format if ! git apply --check patch.txt 2>/dev/null; then echo "ERROR: Invalid patch format in $email_file" return 1 fi
# Check commit message quality if [ "$(cat msg.txt | wc -l)" -lt 3 ]; then echo "WARNING: Short commit message in $email_file" fi
echo "✓ Valid patch: $email_file" return 0}
# Process all emails in directoryfor eml in incoming-patches/*.eml; do validate_patch "$eml"doneHow does mailinfo work with different email formats?
Section titled “How does mailinfo work with different email formats?”Processes standard email headers (From, Date, Subject) and extracts commit message and patch content. Handles various email formats including multipart and different encodings.
What’s the difference between -k and -b options?
Section titled “What’s the difference between -k and -b options?”-k preserves email cruft in subject line (like [PATCH v2]), -b removes it for cleaner commit messages. Use -k when processing git format-patch -k output.
Can mailinfo handle HTML emails?
Section titled “Can mailinfo handle HTML emails?”Processes text content only. HTML emails should be converted to plain text first or use email clients that can extract plain text patches.
How do I handle emails with attachments?
Section titled “How do I handle emails with attachments?”mailinfo processes inline patches. For attachments, extract patch files manually first, then process with mailinfo for message extraction.
What’s the scissors feature for?
Section titled “What’s the scissors feature for?”Detects ”— >8 —” line that separates commit message from patch content in emails. Helps with proper message/patch separation.
Can mailinfo process multiple patches in one email?
Section titled “Can mailinfo process multiple patches in one email?”Processes first patch found. For multiple patches, split email or use git am which handles series automatically.
How do I handle international characters in emails?
Section titled “How do I handle international characters in emails?”Use -u or —encoding options to handle non-ASCII characters. Configure proper encoding for international development teams.
What’s the relationship between mailinfo and git am?
Section titled “What’s the relationship between mailinfo and git am?”mailinfo is low-level tool used by git am. git am calls mailinfo internally to extract patches and messages from emails.
Can mailinfo work with Outlook/Exchange emails?
Section titled “Can mailinfo work with Outlook/Exchange emails?”Yes, processes standard email formats. May need encoding adjustments for different email clients. Test with sample emails first.
How do I handle quoted-printable encoding?
Section titled “How do I handle quoted-printable encoding?”mailinfo handles quoted-printable automatically. Use —encoding option if manual encoding specification needed.
What’s the output format of mailinfo?
Section titled “What’s the output format of mailinfo?”Writes commit message to
Can mailinfo process nested email threads?
Section titled “Can mailinfo process nested email threads?”Processes the primary email content. Thread information may be preserved in commit message depending on email structure.
How do I handle large patch files?
Section titled “How do I handle large patch files?”mailinfo doesn’t limit patch size. Large patches processed normally. Use git apply —check to validate large patches before applying.
Can mailinfo work with signed emails?
Section titled “Can mailinfo work with signed emails?”Processes email content regardless of signatures. Email signatures may appear in commit message unless using scissors separation.
What’s the —quoted-cr option for?
Section titled “What’s the —quoted-cr option for?”Handles different line ending styles in emails. Convert quoted CR characters to appropriate line endings for the platform.
How do I integrate mailinfo with custom email processing?
Section titled “How do I integrate mailinfo with custom email processing?”Use in shell scripts for automated patch processing. Combine with email filtering and validation for robust patch workflows.
Can mailinfo handle binary patches?
Section titled “Can mailinfo handle binary patches?”Processes text-based patches. Binary patches should be handled separately or use appropriate encoding options.
How do I troubleshoot mailinfo failures?
Section titled “How do I troubleshoot mailinfo failures?”Check email format, try different encoding options, verify scissors settings, test with known good emails, check file permissions.
What’s the performance impact of mailinfo?
Section titled “What’s the performance impact of mailinfo?”Very fast - processes email text parsing. Performance mainly depends on email size and encoding complexity.
Can mailinfo work with mbox format?
Section titled “Can mailinfo work with mbox format?”Yes, processes individual emails from mbox files. Extract individual emails first or use git am for mbox processing.
How do I handle emails with multiple patches?
Section titled “How do I handle emails with multiple patches?”mailinfo processes first patch found. For multiple patches, use git am which handles patch series automatically.
Applications of the git mailinfo command
Section titled “Applications of the git mailinfo command”- Patch Management: Extract patches from email for application to Git repositories
- Code Review Integration: Process emailed patches for automated review workflows
- Mailing List Integration: Handle patches submitted through project mailing lists
- Collaborative Development: Enable email-based patch submission and review processes
- Automated Processing: Build systems for processing incoming email patches
- Archive Management: Extract and organize patches from email archives for historical analysis