我正在开发一个脚本,允许我从文件头文件中读取“已接收”字段。
这只是代码的一小部分:
mbox = mailbox.mbox(filename)
print message.keys()
print message["Received"]
Keys的印刷品给我这个结果:
['Return-Path', 'Delivered-To', 'Received', 'Delivered-To', 'Received', 'X-Received', 'Received', 'Received-SPF', 'Authentication-Results', 'DKIM-Signature', 'Received', 'To', 'From', 'Subject', 'Message-ID', 'Disposition-Notification-To', 'Date', 'User-Agent', 'MIME-Version', 'Content-Type', 'Content-Transfer-Encoding', 'X-AntiAbuse', 'X-AntiAbuse', 'X-AntiAbuse', 'X-AntiAbuse', 'X-AntiAbuse', 'X-Get-Message-Sender-Via', 'X-Authenticated-Sender', 'X-Source', 'X-Source-Args', 'X-Source-Dir', 'X-getmail-retrieved-from-mailbox', 'X-GMAIL-THRID', 'X-GMAIL-MSGID']
从这里我看到有3个字段“已收到”,但如果我执行:
print message["Received"]
它只显示第一个字段,如何打印/查看它们?
由于 安德烈
答案 0 :(得分:1)
当你致电public static class SerializationExtensions
{
static bool EnumTypeIsSigned(this Type tEnum)
{
var underlyingType = Enum.GetUnderlyingType(tEnum);
if (underlyingType == typeof(long) || underlyingType == typeof(int) || underlyingType == typeof(short) || underlyingType == typeof(sbyte))
return true;
if (underlyingType == typeof(ulong) || underlyingType == typeof(uint) || underlyingType == typeof(ushort) || underlyingType == typeof(byte))
return false;
throw new ArgumentException(tEnum.Name + " is not an enum type");
}
static bool IsSigned<TEnum>(this TEnum value) where TEnum : struct, IConvertible, IComparable, IFormattable
{
return typeof(TEnum).EnumTypeIsSigned();
}
public static void WriteEnum<TEnum>(this BinaryWriter writer, TEnum value) where TEnum : struct, IConvertible, IComparable, IFormattable
{
if (value.IsSigned())
{
var underlyingValue = checked(value.ToInt64(NumberFormatInfo.InvariantInfo));
writer.Write(underlyingValue);
}
else
{
var underlyingValue = checked(value.ToUInt64(NumberFormatInfo.InvariantInfo));
writer.Write(underlyingValue);
}
}
public static TEnum ReadEnum<TEnum>(this BinaryReader reader) where TEnum : struct, IConvertible, IComparable, IFormattable
{
if (typeof(TEnum).EnumTypeIsSigned())
{
var underlyingValue = reader.ReadInt64();
return checked((TEnum)Enum.ToObject(typeof(TEnum), underlyingValue));
}
else
{
var underlyingValue = reader.ReadUInt64();
return checked((TEnum)Enum.ToObject(typeof(TEnum), underlyingValue));
}
}
}
时,它会线性扫描msg标题列表并返回第一个匹配名称的标题。
要获得多次使用__get__
方法,即:
items()