用 PHP 实现 POP3 邮件的解码(1)
初步认识邮件的源文件
本文简要说明了通过POP3协议收取邮件、MIME邮件的解码的原理;针对收取和MIME解码,提供了两个实用的PHP类,并提供了使用的样例。分为邮件收取、MIME解码两个部分。我们已经向您介绍过了邮件的收取,现在让我们来为您介绍本文的解码部。
在上一篇里,我们已经完成了一个用PHP通过POP3收取邮件的实例,可是在使用这个类的时候,相信你已经看到了,很多的邮件收下来是一堆乱码,自己根本看不懂!是的。现在的邮件大部分都已经经过了编码,需要一个解码的过程才能变成我们习惯的文字、图片、或是其它的附件。
邮件的源文件
首先,我们来看一段简单的邮件的源文件:(在Foxmail中,选中邮件,点选“查看源文件”就会看到这样的些内容了)
From:
To:
Subject: =?gb2312?B?xOO6w6Oh?=
Date: Sun, 8 Oct 2000 20:28:45 +0800
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_NextPart_000_0007_01C03166.5B1E9510"
X-Priority: 3
X-MSMail-Priority: Normal
X-Mailer: Microsoft Outlook Express 5.00.2919.6700
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700
This is a multi-part message in MIME format.
------=_NextPart_000_0007_01C03166.5B1E9510
Content-Type: text/plain;
charset="gb2312"
Content-Transfer-Encoding: base64
w7vT0MLSwuuwyaO/DQo=
------=_NextPart_000_0007_01C03166.5B1E9510
Content-Type: text/html;
charset="gb2312"
Content-Transfer-Encoding: base64
PCFET0NUWVBFIEhUTUwgUFVCTElDICItLy9XM0MvL0RURCBIVE1MIDQuMCBUcmFuc2l0aW9uYWwv
L0VOIj4NCjxIVE1MPjxIRUFEPg0KPE1FVEEgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PWdi
MjMxMiIgaHR0cC1lcXVpdj1Db250ZW50LVR5cGU+DQo8TUVUQSBjb250ZW50PSJNU0hUTUwgNS4w
MC4yOTIwLjAiIG5hbWU9R0VORVJBVE9SPg0KPFNUWUxFPjwvU1RZTEU+DQo8L0hFQUQ+DQo8Qk9E
WSBiZ0NvbG9yPSNmZmZmZmY+DQo8RElWPjxGT05UIHNpemU9Mj7Du9PQwtLC67DJo788L0ZPTlQ+
PC9ESVY+PC9CT0RZPjwvSFRNTD4NCg==

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Atom editor mac version download
The most popular open source editor

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Mac version
God-level code editing software (SublimeText3)