昨天的邮件发送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

相关文章

Redis出现中文乱码的问题及解决

《Redis出现中文乱码的问题及解决》:本文主要介绍Redis出现中文乱码的问题及解决,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1. 问题的产生2China编程. 问题的解决redihttp://www.chinasem.cns数据进制问题的解决中文乱码问题解决总结

java向微信服务号发送消息的完整步骤实例

《java向微信服务号发送消息的完整步骤实例》:本文主要介绍java向微信服务号发送消息的相关资料,包括申请测试号获取appID/appsecret、关注公众号获取openID、配置消息模板及代码... 目录步骤1. 申请测试系统2. 公众号账号信息3. 关注测试号二维码4. 消息模板接口5. Java测试

全面解析MySQL索引长度限制问题与解决方案

《全面解析MySQL索引长度限制问题与解决方案》MySQL对索引长度设限是为了保持高效的数据检索性能,这个限制不是MySQL的缺陷,而是数据库设计中的权衡结果,下面我们就来看看如何解决这一问题吧... 目录引言:为什么会有索引键长度问题?一、问题根源深度解析mysql索引长度限制原理实际场景示例二、五大解决

Springboot如何正确使用AOP问题

《Springboot如何正确使用AOP问题》:本文主要介绍Springboot如何正确使用AOP问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录​一、AOP概念二、切点表达式​execution表达式案例三、AOP通知四、springboot中使用AOP导出

Python中Tensorflow无法调用GPU问题的解决方法

《Python中Tensorflow无法调用GPU问题的解决方法》文章详解如何解决TensorFlow在Windows无法识别GPU的问题,需降级至2.10版本,安装匹配CUDA11.2和cuDNN... 当用以下代码查看GPU数量时,gpuspython返回的是一个空列表,说明tensorflow没有找到

解决未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4‘问题

《解决未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4‘问题》:本文主要介绍解决未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4... 目录未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4‘打开pom.XM

IDEA Maven提示:未解析的依赖项的问题及解决

《IDEAMaven提示:未解析的依赖项的问题及解决》:本文主要介绍IDEAMaven提示:未解析的依赖项的问题及解决,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝... 目录IDEA Maven提示:未解析的依编程赖项例如总结IDEA Maven提示:未解析的依赖项例如

Redis分片集群、数据读写规则问题小结

《Redis分片集群、数据读写规则问题小结》本文介绍了Redis分片集群的原理,通过数据分片和哈希槽机制解决单机内存限制与写瓶颈问题,实现分布式存储和高并发处理,但存在通信开销大、维护复杂及对事务支持... 目录一、分片集群解android决的问题二、分片集群图解 分片集群特征如何解决的上述问题?(与哨兵模

SpringBoot+Redis防止接口重复提交问题

《SpringBoot+Redis防止接口重复提交问题》:本文主要介绍SpringBoot+Redis防止接口重复提交问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不... 目录前言实现思路代码示例测试总结前言在项目的使用使用过程中,经常会出现某些操作在短时间内频繁提交。例

解决Entity Framework中自增主键的问题

《解决EntityFramework中自增主键的问题》:本文主要介绍解决EntityFramework中自增主键的问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝... 目录Entity Framework中自增主键问题解决办法1解决办法2解决办法3总结Entity Fram