base64コマンド

/ Linux/Unix / Comment[0]
メールは基本テキストしか送れない。メールにバイナリファイルを添付する場合は、base64などでテキストに直してから付与するようになっている。
ほとんどのLinuxディストリにはbase64コマンドが入っている。このコマンドは文字通りbase64をデコード・エンコードするコマンドである。
こいつを使ってメールソースから添付ファイルを抽出してみる

MIME-Version: 1.0
Received: by 10.231.144.16 with HTTP; Wed, 6 Apr 2011 19:52:38 -0700 (PDT)
Date: Thu, 7 Apr 2011 11:52:38 +0900
Delivered-To: hogehoge@gmail.com
Message-ID:
Subject: =?ISO-2022-JP?B?GyRCOiMkIiRKJD8kTjhlJG0kSyQkJGskThsoQg==?=
From: Nagakura
To: hogehoge@gmail.com
Content-Type: multipart/mixed; boundary=00163630f349c4885c04a04b33f2

--00163630f349c4885c04a04b33f2
Content-Type: text/plain; charset=ISO-8859-1



--00163630f349c4885c04a04b33f2
Content-Type: image/jpeg; name="saw.jpg"
Content-Disposition: attachment; filename="saw.jpg"
Content-Transfer-Encoding: base64
X-Attachment-Id: file0

/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAIBAQEBAQIBAQECAgICAgQDAgICAgUEBAMEBgUGBgYF
BgYGBwkIBgcJBwYGCAsICQoKCgoKBggLDAsKDAkKCgr/2wBDAQICAgICAgUDAwUKBwYHCgoKCgoK
CgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgoKCgr/wAARCAB3AGQDASIA
AhEBAxEB/8QAHQAAAgIDAQEBAAAAAAAAAAAABAUABgIDBwgBCf/EADUQAAIBAwMCBQIFAwQDAQAA
AAECAwAEEQUSIQYxEyJBUWFxgQcUMpGhI0JSFbHB0TRy8PH/xAAaAQADAQEBAQAAAAAAAAAAAAAD
BAUCAAYB/8QAJxEAAgICAQMEAgMBAAAAAAAAAQIAAxEhBBIxUQUTIkEUYTJxofD/2gAMAwEAAhED
EQA/APxCvOnXDkiPI98Voh6cmkcRrESWbAAFXv8AJWru0cboSTxlsVuFhBYxNd7QW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rJ
JtH0RvFjZXCltrDB57H6EEGjulZ2g0xBcNtJyQGGM8k0kuOrNZubiG6aSPdBDHEn9FSNqKFGQcgn
A9fWi5+qdY19YYbyRI0ht0hKQJt8UJnaX/yIBx9APam6uZWjjoB0MCCfjWOCD9nMZKyzX016ke3x
mHlPPYYo20nimmEeDjtnFKrVjsxn35zVk6b0xZAN6YLHy/NZFfW2YyCtSBYTFptu0YJP8VKs1ro0
McIXcR6kYqU0ONFzeMysqFU4xz8UZbTrZ6dLcSfrfyx0FFJDNMI0OC3Y1p1fUQtwlkjZSIcgD1ps
OqAmKHqOhGVlKIk8xPmOeaFlZZLV0PBaTuPitVvqsO1Vacc9gfSvsm0WxkSXkEsBWwysBBuCMRRe
6ZFNcszJwBubJ7Clt5pJkDzDALHinE80qW+8gAyHGd3pWst+ZdYVAOKTetSCfM2pbIxKpfaZJEm5
wR9RQTR5O1AMmrpqujRTpluRiks9sthp0s4hAeQ7EPt7mpb8Rg29CP12kxPb24dstjA+aLttyNlu
QBwa+Q2ymMGM/ejdNsGuHCMmfqa+V1HWIY2DEN0eCSZwzZI9QKuejJHG0bBgAvfNKdL0xLe23KGz
8mmEMjQjK8HPAqpXWVEUsfqOJa0ukZcrMuPrUpLazbYsFuScnipTPWYHpEqulauEiM0mfIvlGPWt
aul9NuZslm3E1KlIK7MQDDOAp1DIrFCcMSeM1slgkNuIEkwueDjmpUppdDUA2zAb5pZMeX9Kgd+K
xtLu3tfLISGbHIqVKG5PVCVgRgZVkh25znjNI+oLVZ7uO2A8kS9h6k1Klc3zq35mlJVtTGDS1IXE
Yx3xmm+maasLiQqPpUqVupFG5zMcRqkRVMgDB718jiDyk5/TUqUwQOmBXZmcl7DERGHxgD0NSpUp
RmIM3P/Z
--00163630f349c4885c04a04b33f2--

メールソースからファイルの部分をコピペ
saw.base64
/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAIBAQEBAQIBAQECAgICAgQDAgICAgUEBAMEBgUGBgYF
BgYGBwkIBgcJBwYG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XWVEUsfqOJa0ukZcrMuPrUpLazbYsFuScnipTPWYHpEqulauEiM0mfIvlGPWt
aul9NuZslm3E1KlIK7MQDDOAp1DIrFCcMSeM1slgkNuIEkwueDjmpUppdDUA2zAb5pZMeX9Kgd+K
xtLu3tfLISGbHIqVKG5PVCVgRgZVkh25znjNI+oLVZ7uO2A8kS9h6k1Klc3zq35mlJVtTGDS1IXE
Yx3xmm+maasLiQqPpUqVupFG5zMcRqkRVMgDB718jiDyk5/TUqUwQOmBXZmcl7DERGHxgD0NSpUp
RmIM3P/Z

デコードする
$ base64 -d saw.base64 > saw.jpg
$ file saw.jpg
saw.jpg: JPEG image data, JFIF standard 1.01
おk


その他にこんな使い方も

$ echo ようじょようじょつるぺたようじょ|base64
44KI44GG44GY44KH44KI44GG44GY44KH44Gk44KL44G644Gf44KI44GG44GY44KHCg==

$ echo "44KI44GG44GY44KH44KI44GG44GY44KH44Gk44KL44G644Gf44KI44GG44GY44KHCg=="|base64 -d
ようじょようじょつるぺたようじょ

$ gzip -c text.txt|base64 |mail hoge@hoge.com
関連記事

コメント

:
:
:
:
:
管理人のみ表示を許可