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

相关文章

解决IDEA报错:编码GBK的不可映射字符问题

《解决IDEA报错:编码GBK的不可映射字符问题》:本文主要介绍解决IDEA报错:编码GBK的不可映射字符问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录IDEA报错:编码GBK的不可映射字符终端软件问题描述原因分析解决方案方法1:将命令改为方法2:右下jav

MyBatis模糊查询报错:ParserException: not supported.pos 问题解决

《MyBatis模糊查询报错:ParserException:notsupported.pos问题解决》本文主要介绍了MyBatis模糊查询报错:ParserException:notsuppo... 目录问题描述问题根源错误SQL解析逻辑深层原因分析三种解决方案方案一:使用CONCAT函数(推荐)方案二:

Redis 热 key 和大 key 问题小结

《Redis热key和大key问题小结》:本文主要介绍Redis热key和大key问题小结,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录一、什么是 Redis 热 key?热 key(Hot Key)定义: 热 key 常见表现:热 key 的风险:二、

IntelliJ IDEA 中配置 Spring MVC 环境的详细步骤及问题解决

《IntelliJIDEA中配置SpringMVC环境的详细步骤及问题解决》:本文主要介绍IntelliJIDEA中配置SpringMVC环境的详细步骤及问题解决,本文分步骤结合实例给大... 目录步骤 1:创建 Maven Web 项目步骤 2:添加 Spring MVC 依赖1、保存后执行2、将新的依赖

Spring 中的循环引用问题解决方法

《Spring中的循环引用问题解决方法》:本文主要介绍Spring中的循环引用问题解决方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录什么是循环引用?循环依赖三级缓存解决循环依赖二级缓存三级缓存本章来聊聊Spring 中的循环引用问题该如何解决。这里聊

Spring Boot中JSON数值溢出问题从报错到优雅解决办法

《SpringBoot中JSON数值溢出问题从报错到优雅解决办法》:本文主要介绍SpringBoot中JSON数值溢出问题从报错到优雅的解决办法,通过修改字段类型为Long、添加全局异常处理和... 目录一、问题背景:为什么我的接口突然报错了?二、为什么会发生这个错误?1. Java 数据类型的“容量”限制

关于MongoDB图片URL存储异常问题以及解决

《关于MongoDB图片URL存储异常问题以及解决》:本文主要介绍关于MongoDB图片URL存储异常问题以及解决方案,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录MongoDB图片URL存储异常问题项目场景问题描述原因分析解决方案预防措施js总结MongoDB图

SpringBoot项目中报错The field screenShot exceeds its maximum permitted size of 1048576 bytes.的问题及解决

《SpringBoot项目中报错ThefieldscreenShotexceedsitsmaximumpermittedsizeof1048576bytes.的问题及解决》这篇文章... 目录项目场景问题描述原因分析解决方案总结项目场景javascript提示:项目相关背景:项目场景:基于Spring

解决Maven项目idea找不到本地仓库jar包问题以及使用mvn install:install-file

《解决Maven项目idea找不到本地仓库jar包问题以及使用mvninstall:install-file》:本文主要介绍解决Maven项目idea找不到本地仓库jar包问题以及使用mvnin... 目录Maven项目idea找不到本地仓库jar包以及使用mvn install:install-file基

usb接口驱动异常问题常用解决方案

《usb接口驱动异常问题常用解决方案》当遇到USB接口驱动异常时,可以通过多种方法来解决,其中主要就包括重装USB控制器、禁用USB选择性暂停设置、更新或安装新的主板驱动等... usb接口驱动异常怎么办,USB接口驱动异常是常见问题,通常由驱动损坏、系统更新冲突、硬件故障或电源管理设置导致。以下是常用解决