昨天的邮件发送bug修改成功之后,又出现新的大问题

2024-06-16 13:18

本文主要是介绍昨天的邮件发送bug修改成功之后,又出现新的大问题,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

2014年02月21日  昨天的发送邮件 还可以发送成功 ,今天 就失败了。9:39分了,目前还不知原因。分析中…….

 

根据昨天的分析,文件找不到,文件名 的问题 ,昨天的文件名好像由数字命名的。把文件名改为数字之后,发送成功。

改为中文就会程序崩溃。总是提出Poco::FileNotFoundException  异常 。是POCO.net 不支持中文还是编码问题?

 中间各种调试以及猜测.......... 

2014年02月21日 15:26 

 

在同事的帮助下 ,终于解决了邮件发送,附件文件名是中文的问题。

回顾解决过程:

网上搜索 PartSource*pAttach = new FilePartSource(string(sAttachFile))这个函数的源文件,因为poco库是开源的,所以找到源文件,如下:

//
// FilePartSource.cpp
//
// $Id: //poco/svn/Net/src/FilePartSource.cpp#2 $
//
// Library: Net
// Package: Messages
// Module: FilePartSource
//
// Copyright (c) 2005-2006, Applied Informatics Software EngineeringGmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person ororganization
// obtaining a copy of the software and accompanying documentation covered by
// this license (the "Software") to use, reproduce, display,distribute,
// execute, and transmit the Software, and to prepare derivative works ofthe
// Software, and to permit third-parties to whom the Software is furnished to
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement,including
// the above license grant, this restriction and the followingdisclaimer,
// must be included in all copies of the Software, in whole or in part,and
// all derivative works of the Software, unless such copies orderivative
// works are solely in the form of machine-executable object code generatedby
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OFMERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BELIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OROTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//

#include "Poco/Net/FilePartSource.h"
#include "Poco/Path.h"
#include "Poco/Exception.h"

using Poco::Path;
using Poco::OpenFileException;

namespace Poco {
namespace Net {

FilePartSource::FilePartSource(const std::string&path):
        _istr(path)
{
        Pathp(path);
        _filename =p.getFileName();
        if (!_istr.good())
                throw OpenFileException(path);
}

FilePartSource::FilePartSource(const std::string& path, conststd::string&mediaType):
        PartSource(mediaType),
        _istr(path)
{
        Pathp(path);
        _filename =p.getFileName();
        if(!_istr.good())
                throwOpenFileException(path);
}

FilePartSource::~FilePartSource()
{
}

std::istream&FilePartSource::stream()
{
        return _istr;
}

const std::string&FilePartSource::filename()
{
        return _filename;
}

} } // namespace Poco::Net

 

源文档 <http://tsmells.googlecode.com/svn/trunk/sample/poco/poco/Net/src/FilePartSource.cpp>

 

注意到黄色的表示在这里出错了。也就是说std::istream可能不支持中文文件名。

上网搜索,果然有一篇文章《C++fstream文件流处理对中文字符不支持的解决办法

 

源文档 <http://www.cnblogs.com/upendi/archive/2013/05/10/3072195.html>

 

然后按照文章上说的改过之后,发现c++的 fstream是可以支持中文了。这个还是不行。

std::istream&,这说明直接用的是istream.

猜测是poco自己封装了fstream,继续找文件。

 

找poco的fstream文件也就是FileStream .h文件。

//
// FileStream.h
//
// $Id: //poco/svn/Foundation/include/Poco/FileStream.h#2 $
//
// Library: Foundation
// Package: Streams
// Module:  FileStream
//
// Definition of the FileStreamBuf, FileInputStream and FileOutputStreamclasses.
//
// Copyright (c) 2007, Applied Informatics Software Engineering GmbH.
// and Contributors.
//
// Permission is hereby granted, free of charge, to any person or organization
// obtaining a copy of the software and accompanying documentation coveredby
// this license (the "Software") to use, reproduce, display,distribute,
// execute, and transmit the Software, and to prepare derivative works ofthe
// Software, and to permit third-parties to whom the Software is furnishedto
// do so, all subject to the following:
//
// The copyright notices in the Software and this entire statement,including
// the above license grant, this restriction and the followingdisclaimer,
// must be included in all copies of the Software, in whole or in part,and
// all derivative works of the Software, unless such copies orderivative
// works are solely in the form of machine-executable object code generatedby
// a source language processor.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NOEVENT
// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BELIABLE
// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OROTHER
// DEALINGS IN THE SOFTWARE.
//

#ifndef Foundation_FileStream_INCLUDED
#define Foundation_FileStream_INCLUDED

#include "Poco/Foundation.h"
#if defined(POCO_OS_FAMILY_WINDOWS)
#include "FileStream_WIN32.h"
#else
#include "FileStream_POSIX.h"
#endif
#include <istream>
#include <ostream>

namespace Poco {

class Foundation_API FileIOS: public virtualstd::ios
        /// The base class forFileInputStream andFileOutputStream.
        ///
        /// This class is needed toensure the correctinitialization
        /// order of the stream bufferand baseclasses.
        ///
        /// Files are always opened inbinary mode, a textmode
        /// with CR-LF translation isnot supported. Thus, the
        /// file is always opened as ifthe std::ios::binaryflag
        /// wasspecified.
        /// Use anInputLineEndingConverter or OutputLineEndingConverter
        /// if you require CR-LFtranslation.
        ///
        /// On Windows platforms, ifPOCO_WIN32_UTF8 is#define'd,
        /// UTF-8 encoded Unicode pathsare correctlyhandled.

{
public:
        FileIOS(std::ios::openmodedefaultMode);
                ///Creates the basicstream.
                
        ~FileIOS();
                ///Destroys the stream.

void open(const std::string& path, std::ios::openmodemode);
                ///Opens the file specified by path, using the given mode.
                ///
                ///Throws a FileException (or a similar exception) if the file
                ///does not exist or is not accessible for other reasonsand
                ///a new file cannot be created.

voidclose();
                ///Closes the file stream.

FileStreamBuf*rdbuf();
                ///Returns a pointer to the underlying streambuf.

protected:
        FileStreamBuf_buf;
        std::ios::openmode_defaultMode;
};

class Foundation_API FileInputStream: public FileIOS, publicstd::istream
        /// An input stream for readingfrom afile.
        ///
        /// Files are always opened inbinary mode, a textmode
        /// with CR-LF translation isnot supported. Thus,the
        /// file is always opened as ifthe std::ios::binaryflag
        /// wasspecified.
        /// Use anInputLineEndingConverter if you require CR-LF translation.
        ///
        /// On Windows platforms, ifPOCO_WIN32_UTF8 is#define'd,
        /// UTF-8 encoded Unicode pathsare correctlyhandled.
{
public:
        FileInputStream();
                ///Creates an unopened FileInputStream.
        
        FileInputStream(conststd::string& path, std::ios::openmode mode =std::ios::in);
                ///Creates the FileInputStream for the file given by path,using
                ///the given mode.
                ///
                ///The std::ios::in flag is always set, regardless of the actual
                ///value specified formode.
                ///
                ///Throws a FileNotFoundException (or a similar exception) if the file
                ///does not exist or is not accessible for other reasons.

~FileInputStream();
                ///Destroys the stream.
};

class Foundation_API FileOutputStream: public FileIOS, publicstd::ostream
        /// An output stream forwriting to afile.
        ///
        /// Files are always opened inbinary mode, a textmode
        /// with CR-LF translation isnot supported. Thus,the
        /// file is always opened as ifthe std::ios::binaryflag
        /// wasspecified.
        /// Use anOutputLineEndingConverter if you require CR-LF translation.
        ///
        /// On Windows platforms, ifPOCO_WIN32_UTF8 is#define'd,
        /// UTF-8 encoded Unicode pathsare correctlyhandled.
{
public:
        FileOutputStream();
                ///Creats an unopened FileOutputStream.
                
        FileOutputStream(conststd::string& path, std::ios::openmode mode = std::ios::out | std::ios::trunc);
                ///Creates the FileOutputStream for the file given by path,using
                ///the givenmode.
                ///
                ///The std::ios::out is always set, regardless of the actual
                ///value specified formode.
                ///
                ///Throws a FileException (or a similar exception) if the file
                ///does not exist or is not accessible for other reasonsand
                ///a new file cannot be created.

~FileOutputStream();
                ///Destroys the FileOutputStream.
};

classFoundation_API FileStream: public FileIOS, public std::iostream
        ///A stream for reading from and writing to afile.
        ///
        /// Files are always opened inbinary mode, a textmode
        /// with CR-LF translation isnot supported. Thus,the
        /// file is always opened as ifthe std::ios::binary flag
        /// wasspecified.
        /// Use anInputLineEndingConverter orOutputLineEndingConverter
        /// if you require CR-LF translation.
        ///
        /// A seek (seekg() or seekp())operation will always set the
        /// read position and the writeposition simultaneously tothe
        /// samevalue.
        ///
        /// On Windows platforms, if POCO_WIN32_UTF8is #define'd,
        /// UTF-8 encodedUnicode paths are correctly handled.
{
public:
        FileStream();
                ///Creats an unopened FileStream.
        
        FileStream(conststd::string& path, std::ios::openmode mode = std::ios::out |std::ios::in);
                ///Creates the FileStream for the file given by path,using
                ///the given mode.

~FileStream();
                ///Destroys the FileOutputStream.
};

} // namespace Poco

#endif // Foundation_FileStream_INCLUDED

 

源文档 <http://tsmells.googlecode.com/svn/trunk/sample/poco/poco/Foundation/include/Poco/FileStream.h>

 

 所以要把路径GB2312转换为utf-8  

这篇关于昨天的邮件发送bug修改成功之后,又出现新的大问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1066561

相关文章

SQL Server修改数据库名及物理数据文件名操作步骤

《SQLServer修改数据库名及物理数据文件名操作步骤》在SQLServer中重命名数据库是一个常见的操作,但需要确保用户具有足够的权限来执行此操作,:本文主要介绍SQLServer修改数据... 目录一、背景介绍二、操作步骤2.1 设置为单用户模式(断开连接)2.2 修改数据库名称2.3 查找逻辑文件名

MySQL 设置AUTO_INCREMENT 无效的问题解决

《MySQL设置AUTO_INCREMENT无效的问题解决》本文主要介绍了MySQL设置AUTO_INCREMENT无效的问题解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参... 目录快速设置mysql的auto_increment参数一、修改 AUTO_INCREMENT 的值。

关于跨域无效的问题及解决(java后端方案)

《关于跨域无效的问题及解决(java后端方案)》:本文主要介绍关于跨域无效的问题及解决(java后端方案),具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录通用后端跨域方法1、@CrossOrigin 注解2、springboot2.0 实现WebMvcConfig

Go语言中泄漏缓冲区的问题解决

《Go语言中泄漏缓冲区的问题解决》缓冲区是一种常见的数据结构,常被用于在不同的并发单元之间传递数据,然而,若缓冲区使用不当,就可能引发泄漏缓冲区问题,本文就来介绍一下问题的解决,感兴趣的可以了解一下... 目录引言泄漏缓冲区的基本概念代码示例:泄漏缓冲区的产生项目场景:Web 服务器中的请求缓冲场景描述代码

Python使用smtplib库开发一个邮件自动发送工具

《Python使用smtplib库开发一个邮件自动发送工具》在现代软件开发中,自动化邮件发送是一个非常实用的功能,无论是系统通知、营销邮件、还是日常工作报告,Python的smtplib库都能帮助我们... 目录代码实现与知识点解析1. 导入必要的库2. 配置邮件服务器参数3. 创建邮件发送类4. 实现邮件

Java死锁问题解决方案及示例详解

《Java死锁问题解决方案及示例详解》死锁是指两个或多个线程因争夺资源而相互等待,导致所有线程都无法继续执行的一种状态,本文给大家详细介绍了Java死锁问题解决方案详解及实践样例,需要的朋友可以参考下... 目录1、简述死锁的四个必要条件:2、死锁示例代码3、如何检测死锁?3.1 使用 jstack3.2

解决JSONField、JsonProperty不生效的问题

《解决JSONField、JsonProperty不生效的问题》:本文主要介绍解决JSONField、JsonProperty不生效的问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑... 目录jsONField、JsonProperty不生效javascript问题排查总结JSONField

github打不开的问题分析及解决

《github打不开的问题分析及解决》:本文主要介绍github打不开的问题分析及解决,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、找到github.com域名解析的ip地址二、找到github.global.ssl.fastly.net网址解析的ip地址三

Oracle修改端口号之后无法启动的解决方案

《Oracle修改端口号之后无法启动的解决方案》Oracle数据库更改端口后出现监听器无法启动的问题确实较为常见,但并非必然发生,这一问题通常源于​​配置错误或环境冲突​​,而非端口修改本身,以下是系... 目录一、问题根源分析​​​二、保姆级解决方案​​​​步骤1:修正监听器配置文件 (listener.

MySQL版本问题导致项目无法启动问题的解决方案

《MySQL版本问题导致项目无法启动问题的解决方案》本文记录了一次因MySQL版本不一致导致项目启动失败的经历,详细解析了连接错误的原因,并提供了两种解决方案:调整连接字符串禁用SSL或统一MySQL... 目录本地项目启动报错报错原因:解决方案第一个:第二种:容器启动mysql的坑两种修改时区的方法:本地