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

相关文章

关于@MapperScan和@ComponentScan的使用问题

《关于@MapperScan和@ComponentScan的使用问题》文章介绍了在使用`@MapperScan`和`@ComponentScan`时可能会遇到的包扫描冲突问题,并提供了解决方法,同时,... 目录@MapperScan和@ComponentScan的使用问题报错如下原因解决办法课外拓展总结@

MybatisGenerator文件生成不出对应文件的问题

《MybatisGenerator文件生成不出对应文件的问题》本文介绍了使用MybatisGenerator生成文件时遇到的问题及解决方法,主要步骤包括检查目标表是否存在、是否能连接到数据库、配置生成... 目录MyBATisGenerator 文件生成不出对应文件先在项目结构里引入“targetProje

C#使用HttpClient进行Post请求出现超时问题的解决及优化

《C#使用HttpClient进行Post请求出现超时问题的解决及优化》最近我的控制台程序发现有时候总是出现请求超时等问题,通常好几分钟最多只有3-4个请求,在使用apipost发现并发10个5分钟也... 目录优化结论单例HttpClient连接池耗尽和并发并发异步最终优化后优化结论我直接上优化结论吧,

Java内存泄漏问题的排查、优化与最佳实践

《Java内存泄漏问题的排查、优化与最佳实践》在Java开发中,内存泄漏是一个常见且令人头疼的问题,内存泄漏指的是程序在运行过程中,已经不再使用的对象没有被及时释放,从而导致内存占用不断增加,最终... 目录引言1. 什么是内存泄漏?常见的内存泄漏情况2. 如何排查 Java 中的内存泄漏?2.1 使用 J

numpy求解线性代数相关问题

《numpy求解线性代数相关问题》本文主要介绍了numpy求解线性代数相关问题,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧... 在numpy中有numpy.array类型和numpy.mat类型,前者是数组类型,后者是矩阵类型。数组

Python手搓邮件发送客户端

《Python手搓邮件发送客户端》这篇文章主要为大家详细介绍了如何使用Python手搓邮件发送客户端,支持发送邮件,附件,定时发送以及个性化邮件正文,感兴趣的可以了解下... 目录1. 简介2.主要功能2.1.邮件发送功能2.2.个性签名功能2.3.定时发送功能2. 4.附件管理2.5.配置加载功能2.6.

解决systemctl reload nginx重启Nginx服务报错:Job for nginx.service invalid问题

《解决systemctlreloadnginx重启Nginx服务报错:Jobfornginx.serviceinvalid问题》文章描述了通过`systemctlstatusnginx.se... 目录systemctl reload nginx重启Nginx服务报错:Job for nginx.javas

Redis缓存问题与缓存更新机制详解

《Redis缓存问题与缓存更新机制详解》本文主要介绍了缓存问题及其解决方案,包括缓存穿透、缓存击穿、缓存雪崩等问题的成因以及相应的预防和解决方法,同时,还详细探讨了缓存更新机制,包括不同情况下的缓存更... 目录一、缓存问题1.1 缓存穿透1.1.1 问题来源1.1.2 解决方案1.2 缓存击穿1.2.1

vue解决子组件样式覆盖问题scoped deep

《vue解决子组件样式覆盖问题scopeddeep》文章主要介绍了在Vue项目中处理全局样式和局部样式的方法,包括使用scoped属性和深度选择器(/deep/)来覆盖子组件的样式,作者建议所有组件... 目录前言scoped分析deep分析使用总结所有组件必须加scoped父组件覆盖子组件使用deep前言

解决Cron定时任务中Pytest脚本无法发送邮件的问题

《解决Cron定时任务中Pytest脚本无法发送邮件的问题》文章探讨解决在Cron定时任务中运行Pytest脚本时邮件发送失败的问题,先优化环境变量,再检查Pytest邮件配置,接着配置文件确保SMT... 目录引言1. 环境变量优化:确保Cron任务可以正确执行解决方案:1.1. 创建一个脚本1.2. 修