家庭服务器IPV6搭建无限邮箱系统指南

qq邮箱操作
// 邮箱配置信息
// 注意:使用QQ邮箱需要先开启IMAP服务并获取授权码
// 设置方法:登录QQ邮箱 -> 设置 -> 账户 -> 开启IMAP/SMTP服务 -> 生成授权码

服务器操作
fetchmail 同步QQ邮箱
nginx搭建web显示本地同步过来的邮箱

ssh端浏览邮箱
通过python脚本实现其他用户登录可浏览邮件

腾讯云
dns转给cloudflare

cloudflare
信件全局转发到QQ
AAAA解析到物理机IPV6

演示站点 fengche.site
博客 xoxome.online

下面是ssh端服务器脚本

#!/usr/bin/env python3
# -*- coding: utf-8 -*-import os
import sys
import email
import email.header
import email.utils
import datetime
import subprocess
import tempfile# 邮件目录
MAIL_DIR = "/home/y/Maildir/INBOX/new/new"def clear_screen():"""清屏"""os.system("clear")def decode_header(header):"""解码邮件头部信息"""if not header:return "未知"decoded_header = email.header.decode_header(header)result = ""for text, charset in decoded_header:if isinstance(text, bytes):try:if charset:result += text.decode(charset)else:result += text.decode("utf-8", "replace")except:result += text.decode("utf-8", "replace")else:result += textreturn resultdef get_email_info(mail_file):"""获取邮件信息"""with open(mail_file, "rb") as f:msg = email.message_from_binary_file(f)from_addr = decode_header(msg.get("From", "未知"))to_addr = decode_header(msg.get("To", "未知"))subject = decode_header(msg.get("Subject", "未知"))date_str = msg.get("Date", "")try:date = email.utils.parsedate_to_datetime(date_str)date_formatted = date.strftime("%Y-%m-%d %H:%M:%S")except:date_formatted = date_strreturn {"from": from_addr,"to": to_addr,"subject": subject,"date": date_formatted}def html_to_text(html_content):"""将HTML转换为可读文本"""# 使用临时文件保存HTML内容with tempfile.NamedTemporaryFile(suffix='.html', delete=False) as f:f.write(html_content.encode('utf-8'))temp_filename = f.nametry:# 尝试使用w3m将HTML转换为文本 try:result = subprocess.run(['w3m', '-dump', temp_filename], capture_output=True, text=True, check=True)text = result.stdoutexcept (subprocess.SubprocessError, FileNotFoundError):# 如果w3m不可用,尝试使用lynxtry:result = subprocess.run(['lynx', '-dump', '-force_html', temp_filename],capture_output=True, text=True, check=True)text = result.stdoutexcept (subprocess.SubprocessError, FileNotFoundError):# 如果lynx也不可用,使用简单的HTML标签移除text = html_content# 移除常见HTML标签tags_to_remove = ['<html>', '</html>', '<body>', '</body>', '<head>', '</head>','<script>', '</script>', '<style>', '</style>']for tag in tags_to_remove:text = text.replace(tag, '')# 将<br>和<p>替换为换行符text = text.replace('<br>', '\n').replace('<p>', '\n').replace('</p>', '\n')# 移除其他HTML标签in_tag = Falseresult = ""for char in text:if char == '<':in_tag = Trueelif char == '>':in_tag = Falseelif not in_tag:result += chartext = resultreturn textfinally:# 清理临时文件try:os.unlink(temp_filename)except:passdef extract_email_content(mail_file):"""提取邮件内容"""with open(mail_file, "rb") as f:msg = email.message_from_binary_file(f)content = ""html_content = ""if msg.is_multipart():for part in msg.walk():content_type = part.get_content_type()content_disposition = part.get("Content-Disposition", "")# 忽略附件if "attachment" in content_disposition:continue# 获取文本内容if content_type == "text/plain" and not content:payload = part.get_payload(decode=True)if payload:charset = part.get_content_charset()try:if charset:content += payload.decode(charset)else:content += payload.decode("utf-8", "replace")except:content += payload.decode("utf-8", "replace")# 获取HTML内容elif content_type == "text/html" and not html_content:payload = part.get_payload(decode=True)if payload:charset = part.get_content_charset()try:if charset:html_content += payload.decode(charset)else:html_content += payload.decode("utf-8", "replace")except:html_content += payload.decode("utf-8", "replace")else:# 非多部分邮件content_type = msg.get_content_type()payload = msg.get_payload(decode=True)if payload:charset = msg.get_content_charset()try:decoded = payload.decode(charset if charset else "utf-8", "replace")if content_type == "text/plain":content = decodedelif content_type == "text/html":html_content = decodedexcept:content = payload.decode("utf-8", "replace")# 如果有HTML内容但没有纯文本内容,转换HTML为文本if html_content and not content:content = html_to_text(html_content)# 如果没有任何内容if not content and not html_content:content = "【无法解析的邮件内容】"return content, html_contentdef list_emails():"""列出邮件"""clear_screen()print("欢迎使用邮件查看系统")print("=======================")print()if not os.path.isdir(MAIL_DIR):print("邮件目录不存在: " + MAIL_DIR)input("按Enter键退出...")sys.exit(1)mail_files = []try:# 获取所有邮件文件,按修改时间排序mail_files = sorted([f for f in os.listdir(MAIL_DIR) if os.path.isfile(os.path.join(MAIL_DIR, f))],key=lambda x: os.path.getmtime(os.path.join(MAIL_DIR, x)),reverse=True)except Exception as e:print("读取邮件目录出错: " + str(e))input("按Enter键退出...")sys.exit(1)if not mail_files:print("没有新邮件")print("按Enter键同步邮件,按q退出:")choice = input().strip()if choice.lower() != "q":sync_mail()return list_emails()  # 重新加载邮件列表else:sys.exit(0)print("找到 " + str(len(mail_files)) + " 封新邮件:")print()# 显示最多5封邮件displayed_files = []for i, mail_file in enumerate(mail_files[:5]):full_path = os.path.join(MAIL_DIR, mail_file)try:info = get_email_info(full_path)displayed_files.append(mail_file)print(str(i+1) + ") " + mail_file)print("   从: " + info["from"])print("   主题: " + info["subject"])print("   日期: " + info["date"])print()except Exception as e:print("读取邮件 " + mail_file + " 出错: " + str(e))print()return displayed_filesdef sync_mail():"""同步邮件"""clear_screen()print("正在使用y用户权限同步邮件...")try:# 使用sudo以y用户身份运行fetchmailresult = subprocess.run(['sudo', '-u', 'y', 'fetchmail', '-v'], capture_output=True, text=True)output = result.stdouterror = result.stderrif output:print(output)if error:print()print()# 检查是否成功同步了新邮件if "reading message" in (output or "") or "messages" in (output or ""):print("成功同步了新邮件!")else:print("没有新邮件或同步失败。")except Exception as e:print("同步邮件出错: " + str(e))print()input("按Enter键继续...")def view_email(mail_file):"""查看邮件内容"""clear_screen()full_path = os.path.join(MAIL_DIR, mail_file)try:# 获取邮件信息info = get_email_info(full_path)print("邮件: " + mail_file)print("=======================")print("从: " + info["from"])print("收件人: " + info["to"])print("主题: " + info["subject"])print("日期: " + info["date"])print("=======================")print()# 提取邮件内容text_content, html_content = extract_email_content(full_path)if html_content:print("邮件内容 (转换自HTML):")print("=======================")print(text_content)print("=======================")print()print("选项: 1) 返回邮件列表 2) 查看原始HTML 3) 同步邮件 [1-3]:")view_choice = input().strip()if view_choice == "2":# 使用临时文件显示HTMLwith tempfile.NamedTemporaryFile(suffix='.html', delete=False) as f:f.write(html_content.encode('utf-8'))temp_filename = f.nametry:# 尝试使用不同的HTML查看器browsers = [['w3m', temp_filename],['lynx', temp_filename],['less', temp_filename]]for browser in browsers:try:subprocess.run(browser)breakexcept (subprocess.SubprocessError, FileNotFoundError):continuefinally:os.unlink(temp_filename)elif view_choice == "3":sync_mail()else:print("邮件内容:")print("=======================")print(text_content)print("=======================")print()print("选项: 1) 返回邮件列表 2) 同步邮件 [1-2]:")view_choice = input().strip()if view_choice == "2":sync_mail()return Trueexcept Exception as e:print("查看邮件出错: " + str(e))print()input("按Enter键返回...")return Falsedef main():"""主函数"""while True:displayed_files = list_emails()print("输入邮件编号查看内容,按Enter查看最新邮件,按s同步邮件,按q退出:")choice = input().strip()if choice.lower() == "q":print("谢谢使用,再见!")breakelif choice.lower() == "s":sync_mail()continuemail_to_view = Noneif not choice or choice == "1":# 查看最新邮件if displayed_files:mail_to_view = displayed_files[0]elif choice.isdigit():# 查看选定邮件idx = int(choice) - 1if 0 <= idx < len(displayed_files):mail_to_view = displayed_files[idx]else:print("无效选择!")input("按Enter键继续...")continueelse:print("无效选择!")input("按Enter键继续...")continueif mail_to_view:view_email(mail_to_view)if __name__ == "__main__":# 检查并安装必要的HTML渲染工具try:for pkg in ['w3m', 'lynx']:try:subprocess.run(['which', pkg], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)breakexcept:passexcept:passtry:main()except KeyboardInterrupt:print("\n程序已退出")sys.exit(0)except Exception as e:print("程序发生错误: " + str(e))input("按Enter键退出...")sys.exit(1)

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/81074.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Tauri v1 与 v2 配置对比

本文档对比 Tauri v1 和 v2 版本的配置结构和内容差异&#xff0c;帮助开发者了解版本变更并进行迁移。 配置结构变化 v1 配置结构 {"package": { ... },"tauri": { "allowlist": { ... },"bundle": { ... },"security":…

对js的Date二次封装,继承了原Date的所有方法,增加了自己扩展的方法,可以实现任意时间往前往后推算多少小时、多少天、多少周、多少月;

封装js时间工具 概述 该方法继承了 js 中 Date的所有方法&#xff1b;同时扩展了一部分自用方法&#xff1a; 1、任意时间 往前推多少小时&#xff0c;天&#xff0c;月&#xff0c;周&#xff1b;参数1、2必填&#xff0c;参数3可选beforeDate(num,formatter,dateVal); befo…

TimeDistill:通过跨架构蒸馏的MLP高效长期时间序列预测

原文地址&#xff1a;https://arxiv.org/abs/2502.15016 发表会议&#xff1a;暂定&#xff08;但是Star很高&#xff09; 代码地址&#xff1a;无 作者&#xff1a;Juntong Ni &#xff08;倪浚桐&#xff09;, Zewen Liu &#xff08;刘泽文&#xff09;, Shiyu Wang&…

DeepSeek最新大模型发布-DeepSeek-Prover-V2-671B

2025 年 4 月 30 日&#xff0c;DeepSeek 开源了新模型 DeepSeek-Prover-V2-671B&#xff0c;该模型聚焦数学定理证明任务&#xff0c;基于混合专家架构&#xff0c;使用 Lean 4 框架进行形式化推理训练&#xff0c;参数规模达 6710 亿&#xff0c;结合强化学习与大规模合成数据…

如何用AI生成假期旅行照?

以下是2025年最新AI生成假期旅行照片的实用工具推荐及使用指南&#xff0c;结合工具特点、研发背景和适用场景进行综合解析&#xff1a; 一、主流AI旅行照片生成工具推荐与对比 1. 搜狐简单AI&#xff08;国内工具&#xff09; • 特点&#xff1a; • 一键优化与背景替换&…

ElaticSearch

ElaticSearch: 全文搜索 超级强&#xff0c;比如模糊查询、关键词高亮等 海量数据 高效查询&#xff0c;比传统关系数据库快得多&#xff08;尤其是搜索&#xff09; 灵活的数据结构&#xff08;Schema灵活&#xff0c;可以动态字段&#xff09; 分布式高可用&#xff0c;天…

Android开发,实现一个简约又好看的登录页

文章目录 1. 编写布局文件2.设计要点说明3. 效果图4. 关于作者其它项目视频教程介绍 1. 编写布局文件 编写activity.login.xml 布局文件 <?xml version"1.0" encoding"utf-8"?> <androidx.appcompat.widget.LinearLayoutCompat xmlns:android…

机器学习:【抛掷硬币的贝叶斯后验概率】

首先,抛硬币的问题通常涉及先验概率、似然函数和后验概率。假设用户可能想通过观察一系列的正面(H)和反面(T)来更新硬币的偏差概率。例如,先验可能假设硬币是均匀的,但随着观察到更多数据,用贝叶斯定理计算后验分布。 通常,硬币的偏差可以用Beta分布作为先验,因为它…

Echarts 问题:自定义的 legend 点击后消失,格式化 legend 的隐藏文本样式

文章目录 问题分析实现步骤代码解释问题 如下图所示,在自定义的 legend 点击后会消失 分析 我把隐藏的图例字体颜色设为灰色,可以借助 legend.formatter 和 legend.textStyle 结合 option.series 的 show 属性来达成。以下是具体的实现步骤和示例代码: <!DOCTYPE ht…

光谱相机如何提升目标检测与识别精度

光谱相机&#xff08;多光谱/高光谱&#xff09;通过捕捉目标在多个波段的光谱特征&#xff0c;能够揭示传统RGB相机无法感知的材质、化学成分及物理特性差异。以下是提升其目标检测与识别精度的核心方法&#xff1a; ‌1. 硬件优化&#xff1a;提升数据质量‌ ‌(1) 光谱分辨…

springboot项目配置nacos,指定使用环境

遇到这样一个问题&#xff0c;在开发、测试、生成环境之间切换的问题。 大多数的操作是通过修改spring.profiles.active来确定指向使用的环境配置文件&#xff0c;对应项目中需要增加对应的配置文件。 但是现在几乎所有公司都会有代码管理不管是SVN、git&#xff0c;这样就会涉…

AI代码审查的落地实施方案 - Java架构师面试实战

AI代码审查的落地实施方案 - Java架构师面试实战 本文通过模拟一位拥有十年Java研发经验的资深架构师马架构与面试官之间的对话&#xff0c;深入探讨了AI代码审查的落地实施方案。 第一轮提问 面试官&#xff1a; 马架构&#xff0c;请介绍一下您对AI代码审查的理解。 马架…

TDengine 订阅不到数据问题排查

简介 TDengine 在实际生产应用中&#xff0c;经常会遇到订阅程序订阅不到数据的问题&#xff0c;总结大部分都为使用不当或状态不正确等问题&#xff0c;需手工解决。 查看服务端状态 通过 sql 命令查看有问题的 topic 和consumer_group 组订阅是否正常。 select * from inf…

二、UI自动化测试02--元素定位方法

目录 一、定位⼀组元素⽅法二、XPath 定位⽅法1. 路径策略1.1 路径值获取⽅法 2. 利⽤元素属性策略利⽤元素属性策略的注意事项 3. 属性和逻辑结合4. 层级和属性结合策略5. XPath 延伸⽅法 三、CSS 定位⽅法1. CSS 策略: id选择器/class选择器/元素选择器/属性选择器2. 属性选择…

HotSpot的算法细节

可达性分析算法 以一系列“GC Roots”根对象作为起始节点集&#xff0c;从这些节点开始&#xff0c;根据引用关系向下搜索&#xff0c;搜索过程所走过的路径称为“引用链”&#xff08;Reference Chain&#xff09;&#xff0c;如果某个对象到GC Roots间没有任何引用链相连&am…

Transformer数学推导——Q27 证明时序注意力(Temporal Attention)在视频模型中的帧间依赖建模

该问题归类到Transformer架构问题集——注意力机制——跨模态与多模态。请参考LLM数学推导——Transformer架构问题集。 在视频理解任务中&#xff0c;捕捉帧与帧之间的时间依赖关系&#xff08;如动作的连贯性、物体的运动轨迹&#xff09;是核心挑战。时序注意力&#xff08…

服务器和数据库哪一个更重要

在当今数字化的时代&#xff0c;服务器和数据库都是构建和运行各种应用系统的关键组成部分&#xff0c;要说哪一个更重要&#xff0c;其实很难简单地给出定论。 服务器就像是一个强大的引擎&#xff0c;为应用程序提供了稳定的运行环境和高效的计算能力。它负责接收和处理来自…

【Android】四大组件之Service

目录 一、什么是Service 二、启停 Service 三、绑定 Service 四、前台服务 五、远程服务扩展 六、服务保活 七、服务启动方法混用 你可以把Service想象成一个“后台默默打工的工人”。它没有UI界面&#xff0c;默默地在后台干活&#xff0c;比如播放音乐、下载文件、处理…

pytest 技术总结

目录 一 pytest的安装&#xff1a; 二 pytest有三种启动方式&#xff1a; 三 用例规则&#xff1a; 四 配置框架&#xff1a; 一 pytest的安装&#xff1a; pip install pytest # 安装 pip install pytest -U # 升级到最新版 二 pytest有三种启动方式&#xff1a; 1…