本文主要是介绍昨天的邮件发送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修改成功之后,又出现新的大问题的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!