Problem to get file with special characters in the message
Hi, I'm developing an application that read the email and save the attached file. However, some files have special characters in the name, like: Documento de EspecificaÇÂO.doc
I noticed the de name of the file in de message head is:
"=?iso-8859-1?Q?Documento_de_Especifica=E7=E3o.doc?="
I'm already using the JavaMil 1.4.5
Tha is my code:
package br.com.cesan.helpdesk;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import javax.mail.Flags;
import javax.mail.Folder;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.Part;
import javax.mail.Session;
import javax.mail.Store;
import javax.mail.search.FlagTerm;
public class LerEmail2 {
* @param args
* @throws MessagingException
* @throws IOException
public static void main(String[] args) throws MessagingException, IOException {
// TODO Auto-generated method stub
// Get session
Session session = Session.getInstance(new Properties(), null);
// Get the store
Store store = session.getStore("pop3");
store.connect("pop.xxxxx.com.br", "user", "password");
Folder folder = store.getFolder("INBOX");
//folder.open(Folder.READ_ONLY);
folder.open(Folder.READ_WRITE);
// Show only unreaded Messages
FlagTerm ft = new FlagTerm(new Flags(Flags.Flag.SEEN), false);
// Get directory
Message message[] = folder.getMessages();
//Message messages[] = folder.search(ft);
for (int i=0, n=message.length; i<n; i++) {
System.out.println(i + " - "+ message.getSubject() +" - " + message[i].getSentDate() );
Object content = message[i].getContent();
if (content instanceof Multipart) {
handleMultipart((Multipart)content);
} else {
handlePart(message[i]);
// Close connection
folder.close(false);
store.close();
public static void handleMultipart(Multipart multipart) throws MessagingException, IOException {
for (int i=0, n=multipart.getCount(); i<n; i++) {
handlePart(multipart.getBodyPart(i));
public static void handlePart(Part part) throws MessagingException, IOException {
String disposition = part.getDisposition();
String contentType = part.getContentType();
if (disposition == null) { // When just body
System.out.println("Null: " + contentType);
// Check if plain
if ((contentType.length() >= 10) && (contentType.toLowerCase().substring(0, 10).equals("text/plain"))) {
part.writeTo(System.out);
} else { // Don't think this will happen
System.out.println("Other body: " + contentType);
part.writeTo(System.out);
} else if (disposition.equalsIgnoreCase(Part.ATTACHMENT)) {
System.out.println("Attachment: " + part.getFileName() + " : " + contentType);
saveFile(part.getFileName(), part.getInputStream());
} else if (disposition.equalsIgnoreCase(Part.INLINE)) {
System.out.println("Inline: " +
part.getFileName() +
" : " + contentType);
saveFile(part.getFileName(), part.getInputStream());
} else { // Should never happen
System.out.println("Other: " + disposition);
public static void saveFile(String filename, InputStream input) throws IOException {
if (filename == null) {
filename = File.createTempFile("xx", ".out").getName();
// Do no overwrite existing file
File file = new File(filename);
for (int i=0; file.exists(); i++) {
file = new File(filename+i);
System.setProperty("file.encoding", "iso-8859-1");
FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fos);
BufferedInputStream bis = new BufferedInputStream(input);
int aByte;
while ((aByte = bis.read()) != -1) {
bos.write(aByte);
bos.flush();
bos.close();
bis.close();
The problem occurs in:
FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fos);
BufferedInputStream bis = new BufferedInputStream(input);
int aByte;
while ((aByte = bis.read()) != -1) {
bos.write(aByte);
Thanks
Edited by: user10283976 on 30/03/2012 07:36
Edited by: user10283976 on 30/03/2012 07:37
Edited by: user10283976 on 30/03/2012 07:37
Edited by: user10283976 on 30/03/2012 07:38
Edited by: user10283976 on 30/03/2012 07:40
Edited by: user10283976 on 30/03/2012 07:41
Edited by: user10283976 on 30/03/2012 07:42
http://www.oracle.com/technetwork/java/javamail/faq/index.html#encodefilename
Similar Messages
-
Robohelp 7 HTML cannot get files with accented characters in the name
The files are added without a problem but "Get" operation
returns error "invalid file name"
Example of the file name Le_système.htm or
Aperçu_du_système.htmI got a similar response when RSC didn't like some of the
special characters (punctuation) that sneaked into some of our
files. Your other files operate normally, right? I'd report this to
Adobe as a bug.
G -
Creating Text files with special characters
I have a problem writing and then reading special characters in a text file. I am using FileWriter and FileReader and once I write (using FileWriter) in a file.txt many characters with ASCII code less than 31, I can not read them back using FileRead. I simply get a content which is different from the one originally written.
Does anyone have an idea about this problem ?The code is OK, problems may have occured during copy/paste. But in the original code it is written c.
Here is a copy of the output of those lines that i'm talking about:
Here is the ASCII Code >> 125
Here is the ASCII Code >> 126
Here is the ASCII Code >> 127
Here is the ASCII Code >> 63
Here is the ASCII Code >> 63
Here is the ASCII Code >> 63
Here is the ASCII Code >> 63
Here is the ASCII Code >> 63
Here is the ASCII Code >> 63
Here is the ASCII Code >> 63
Here is the ASCII Code >> 63
Here is the ASCII Code >> 63
Here is the ASCII Code >> 63
Here is the ASCII Code >> 63
Here is the ASCII Code >> 63
Here is the ASCII Code >> 63
Here is the ASCII Code >> 63
Here is the ASCII Code >> 63
Here is the ASCII Code >> 63
Here is the ASCII Code >> 63
Here is the ASCII Code >> 63
Here is the ASCII Code >> 63
Here is the ASCII Code >> 63
Here is the ASCII Code >> 63
Here is the ASCII Code >> 63
Here is the ASCII Code >> 63
Here is the ASCII Code >> 63
Here is the ASCII Code >> 63
Here is the ASCII Code >> 63
Here is the ASCII Code >> 63
Here is the ASCII Code >> 63
Here is the ASCII Code >> 63
Here is the ASCII Code >> 63
Here is the ASCII Code >> 63
Here is the ASCII Code >> 63
Here is the ASCII Code >> 160
Here is the ASCII Code >> 161
Here is the ASCII Code >> 162 -
Clementine can't play files with special characters
I saw Clementine can't play some mp3 files - it would just say "error loading file".
So I opened an mp3 from the terminal and found out that the problem was the characters in the file name.
For example, it wouldn't play "Schiller - Tired (mit Jaël).mp3" but works fine with "Schiller - Tired (mit Jael)"
Any ideas why?Well...
[bogdan@myhost ~]$ locale
LANG=C
LC_CTYPE="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_COLLATE="C"
LC_MONETARY="C"
LC_MESSAGES="C"
LC_PAPER="C"
LC_NAME="C"
LC_ADDRESS="C"
LC_TELEPHONE="C"
LC_MEASUREMENT="C"
LC_IDENTIFICATION="C"
LC_ALL=
[bogdan@myhost ~]$ -
File Adapter write XML file with special characters
Hi,
I have a BPEL processes which use DB adapter to retrieve record and output in a XML document using File Adapter.
In the table, some records contain these special characters - ">" , "<" , "." . I was expecting the file adapter will convert it to escape characters, but it didn't happen. it just put the same value back to the XML file, which cause other system to reject the file. Do anyone know how to resolve this ?
The version of SOA is 10.1.3.4
Thanks for the help.
Calvin
Edited by: user12018221 on May 25, 2011 1:48 PMone option is to specify validateXML on the partnerlink (that describes the file adapter endpoint) such as shown here
<partnerLinkBinding name="StarLoanService">
<property name="wsdlLocation"> http://<hostname>:9700/orabpel/default/StarLoan/StarLoan?wsdl</property>
<property name="validateXML">true</property>
</partnerLinkBinding>
hth clemens -
Problems with special characters in the data.
Hi All,
Whenever, I'm trying to data such as "Lämmerzunge" which are having some special characters in it, it is storing them as L�mmerzunge. Is there anyway to handle these?
Thanks in advance.
Regards,
VenkyCheck if database characterset supports these special characters
check client's nls settings.
check client machine's language settings (converts characters in driver level) -
Parsing BLOB (CSV file with special characters) into table
Hello everyone,
In my application, user uploads a CSV file (it is stored as BLOB), which is later read and parsed into table. The parsing engine is shown bellow...
The problem is, that it won't read national characters as Ö, Ü etc., they simply dissapear.
Is there any CSV parser that supports national characters? Or, said in other words - is it possible to read BLOB by characters (where characters can be Ö, Ü etc.)?
Regards,
Adam
|
| helper function for csv parsing
|
+-----------------------------------------------*/
FUNCTION hex_to_decimal(p_hex_str in varchar2) return number
--this function is based on one by Connor McDonald
--http://www.jlcomp.demon.co.uk/faq/base_convert.html
is
v_dec number;
v_hex varchar2(16) := '0123456789ABCDEF';
begin
v_dec := 0;
for indx in 1 .. length(p_hex_str) loop
v_dec := v_dec * 16 + instr(v_hex, upper(substr(p_hex_str, indx, 1))) - 1;
end loop;
return v_dec;
end hex_to_decimal;
|
| csv parsing
|
+-----------------------------------------------*/
FUNCTION parse_csv_to_imp_table(in_import_id in number) RETURN boolean IS
PRAGMA autonomous_transaction;
v_blob_data BLOB;
n_blob_len NUMBER;
v_entity_name VARCHAR2(100);
n_skip_rows INTEGER;
n_columns INTEGER;
n_col INTEGER := 0;
n_position NUMBER;
v_raw_chunk RAW(10000);
v_char CHAR(1);
c_chunk_len number := 1;
v_line VARCHAR2(32767) := NULL;
n_rows number := 0;
n_temp number;
BEGIN
-- shortened
n_blob_len := dbms_lob.getlength(v_blob_data);
n_position := 1;
-- Read and convert binary to char
WHILE (n_position <= n_blob_len) LOOP
v_raw_chunk := dbms_lob.substr(v_blob_data, c_chunk_len, n_position);
v_char := chr(hex_to_decimal(rawtohex(v_raw_chunk)));
n_temp := ascii(v_char);
n_position := n_position + c_chunk_len;
-- When a whole line is retrieved
IF v_char = CHR(10) THEN
n_rows := n_rows + 1;
if n_rows > n_skip_rows then
-- Shortened
-- Perform some action with the line (store into table etc.)
end if;
-- Clear out
v_line := NULL;
n_col := 0;
ELSIF v_char != chr(10) and v_char != chr(13) THEN
v_line := v_line || v_char;
if v_char = ';' then
n_col := n_col+1;
end if;
END IF;
END LOOP;
COMMIT;
return true;
EXCEPTION
-- some exception handling
END;Uploading CSV files into LOB columns and then reading them in PL/SQL: [It’s|http://forums.oracle.com/forums/thread.jspa?messageID=3454184�] Re: Reading a Blob (CSV file) and displaying the contents Re: Associative Array and Blob Number of rows in a clob doncha know.
Anyway, it woudl help if you gave us some basic information: database version and NLS settings would seem particularly relevant here.
Cheers, APC
blog: http://radiofreetooting.blogspot.com -
Problem reading csv file with special character
Hai all,
i have the following problem reading a csv file.
442050-Operations Tilburg algemeen Huis in t Veld, EAM (Lisette) Gebruikersaccount 461041 Peildatum: 4-5-2010 AA461041 1 85,92
when reading this line with FM GUI_UPLOAD this line is split up in two lines in data_tab of the FM,
it is split up at this character
Line 1
442050-Operations Tilburg algemeen Huis in
Line 2
t Veld, EAM (Lisette) Gebruikersaccount 461041 Peildatum: 4-5-2010 AA461041 1 85,92
Anyone have a idea how to get this in one line in my interbal table??
Greetz RichardHi Greetz Richard
Problably character contains same binary code as line feed + carriage return.
You can use statement below as workaround.
OPEN DATASET file FOR INPUT IN TEXT MODE ENCODING UNICODE
In this case your system must support Unicode encoding
Kind regards -
Replacing text in a text file with special characters
Hi all,
in my test text file i found an interesting issue, where i can't replace text that looks something like this "New Text Document - Copy (2).txt"
(gc $logeps)|foreach{$_ -replace "$($file.name)",""}|Out-File $logeps
the context of my $($file.name) is "New Text Document - Copy (2).txt"
how can i escape the parentheses characters inside of a variable that i am passing?
thanksThat should work if you're running PowerShell 3.0 or later, but in older versions, you'd run into errors if you try to run .Replace on an array of strings.
While I prefer the string .Replace method in this instance, for future reference, if you want to escape a literal string so it can be used in a regular expression, call the [regex]::Escape method:
$pattern = [regex]::Escape($file.Name)
(gc $logeps) -replace $pattern | Out-File $logeps -
Upload files with swedish characters NS 4.7
Hi,
I can upload files with swedish characters in the file name with IE 5, but not with Netscape 4.7. iFS presents an error message that the file doesn't exist or is empty.
Is there a solution for this problem?
/Elin
nullcheck out if you are using javascripts and whether IE supports it
Roberto Nanamura <[email protected]> wrote:
>
Hi,
I am having a problem uploading files with Internet Explorer, it works with
Netscape Communicator. Has someone had the same problem?
I am using WebLogic 5.1 service pack 5 with Netscape iPlanet 4.1 service pack 2
in a Solaris 7.
Best regards,
Roberto N Nanamura
Technical Consultant
Summa Technologies -
Tag Query with Special Characters in Tag Name not working
Hello-
We are on SAP xMII 12.0 sp8.6, connecting to Honeywell's PHD. We are doing Tag Queries, and all is working well, except when there are special characters in the Tag Name (+, /, \) We have attempted to do the Encoding of the tag name, such as as is returned from the function xmlencodename and also tried URL Encoding.
Here is our tag which returns nothing.
82TK1INV.OCTANE_R+M/2
We have also tried these encoded versions, still to no avail:
82TK1INV.OCTANE_R%2BM%2F2
82TK1INV.OCTANER_M_2
Any help on how to return the values with special characters in the tag name would be very helpful!
thanks,
Paul MazeikaTo Chianti's question of why can't/shouldn't MII work with those bizarre tag names...
Actually, there are a number of reasons:
1) It's a poor design practice to use characters like that in tag names, regardless of the underlying system. That type of information is best assigned to the tag description, not the tag name. I've even seen idiots put leading spaces on tag names...figure that one out!
2) MII uses XML extensively, and XML's syntax rules dictate what is and is not acceptable for XML element and attribute names, and many of these special characters are not permitted.
3) Usage of characters in tags that also represent mathematical operators greatly complicate the parsing and processing of expressions that involve tag names
In general, it reminds of the story of the guy who walks into the doctor, bangs his fist against a specific spot on his head, and says "Doc, it hurts when I do this", to which the doctor responds, "so don't do that".
So, Don't Do That. -
Serving up files with Russian chars in the file name
Anyone know how to get CF 8 to serve up CFM files with
Russian characters in the file name? I can get IIS to server up
.html files but .cfm files turn in to ?????????.cfm files.
For example, this:
новостииобновления.cfm
becomes this ??????????????.cfm and throws a CF error (File Not
Found) when clicking on the link. The strange thing is I can see
the Russian characters in the status bar when I mouse over the link
but CF can't handle it. And IIS will serve up the file and replace
all the chars with their URL entity equivalent.
Any suggestions on how to fix?Open the Script Editor or AppleScript Editor in one of the subfolders of Applications and run the following:
tell application "Finder" to quit
if (do shell script "defaults read com.apple.finder AppleShowAllFiles") is "1" then
do shell script "defaults write com.apple.finder AppleShowAllFiles 0"
else
do shell script "defaults write com.apple.finder AppleShowAllFiles 1"
end if
delay 2
tell application "Finder" to run
If you change your mind later, run the script again.
(93787) -
Problem with flat file loading/Special characters
Hi, All,
We just migrated from Version 3.0B to BI7.0, and I've a problem which I can't handle for the moment. We are in Unicode, current codepage of the server is 4103 and codepage of frontend is 4110 (from SNL1 Transaction).
I'm loading czech texts in my material, via CSV files. The CSV file is correct on my PC, I see the special characters.
The problem is on my loading, whatever Character set I choose in the Infopackage (I choose Standard or Character Set Setting User-dependant), I cannot see the good characters.
Does any one of you already encounter this kind of problem, and, if yes, how did you solve it ?
Thankshi,
check out with your flat file letter's type, if it's in lower case letter's change them in
upper case letter's. or otherwise change the infobject's type as-- select check box
corresponding to lower case letter's in infoobject.
if helpful provide points
regards
harikrishna.N -
Problem figuring out the encoding for filenames with special characters
I'm not sure if this is the right forum, but this does seem like an OS issue.
I brought in a lot of mp3 and m3u files from a Windows machine to my new Mac. Some of the mp3 files have accented characters in their names, and these names appear in the m3u files. But if I add the m3u file to iTunes, it fails to recognize these names and so I lose all the mp3's with special characters in their names.
I tried to fix this by grabbing the files name in Python, but that didn't work either!
Here's an example: the file's name is "Voilà l'été.mp3"
The m3u files says "Voil\xe0 l'\xe9t\xe9.mp3" -- this doesn't work.
From os.listdir(), I get Voila\xcc\x80 l'e\xcc\x81te\xcc\x81.mp3", but sticking it in an m3u files doesn't work either. (Note that here the characters are encoded as unaccented letter + two byte code for the accent).
When I try these strings from python, e.g. doing os.stat(), they both work; but iTunes doesn't understand any of them!
I'd appreciate any hints on how to enter these names in the m3u file so that iTunes can read it. Thanks!I know nothing about "m3u" files and how iTunes interprets the file names in them, but if it is not a relative/absolute path problem, then how about just putting the raw file names (not the ones with backslash escape) in m3u file? For example, just put
Voilà l'été.mp3
in m3u?
As for Unicode encoding, HFS+ file system uses the "decomposed form" for accented characters. This means, as you write, à is hex "61 cc 80" in UTF-8, i.e., "a + COMBINING GRAVE ACCENT". The pre-composed form is hex "c3 a0". But my experience is that in most cases both pre-composed and decomosed forms work at the user level (not at the lowest file system level). -
Unmarshalling problem with special characters (Trademark, French
I'm using a DefaultHandler class to create a StringBuffer which contains a single (though very complex) element from an XML file. I am unmarshalling this StringBuffer object to a JAXBContext like this:
u.unmarshal( new StreamSource( new StringReader( sb.toString() ) )
My special characters are going way out of whack (please read (TM) as the Trademark symbol)
T-Force(TM) Ring(TM) Bonded iron construction for durability and longer life
becomes
T-Force���Ring ��� Bonded iron construction for durability and longer life
Before I put anything else into the StringBuffer I put this in:
sb.append("<?xml version=\"1.0\" encoding=\"iso-8859-15\"?>");
But I've tried:
sb.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
and
sb.append("<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>");
with different, but wrong, results.
It's true that I'm viewing these results on a web page, so it's possible that the problem is occurring on the back end once I persist the data, but it looks like my database is set for UTF-8 (that's what I put for this new installation of Oracle 9i R2).
Is there something basic I am missing. Like, perhaps, I need to do some sort of XML entity coding?
Thank you very much for any help you can offer.Actually I had forgotten one additional thing. I have
tried testing one thing at a time, and I have sent the
special characters to the log file with logger.debug
statements (log4j). The characters are screwed up in
the log files, which is what makes me think I need to
do some sort of entity encoding. (?)I don't think that log4j provides any way to declare the encoding it uses for your files. My guess is that it's using the default encoding for your system, which could be a problem for things like the trademark character. So log4j really gives you just another thing to test, rather than acting as a testing tool.
I was thinking of a more low-level test, where you take your trademark character, which is 2022 or some such number (check the Unicode charts) and you write it to the database and read it back. Do you get the same character back? That sort of testing.
Maybe you are looking for
-
Function Module for outline agreement
Dear Sir, I want to know the function module for contract/outline agreement from where I can fetch the details of release orders against the given contract. Regards Amit Agarwal
-
Iphone is not being recognised on itunes to sync?
Hi, I have connected my iphone to my computer but it is not being recognised on itunes?can u help?
-
Error message from database stored procedures
I would like to have some error message show at client side from stored procedures. I use MS SQL Server and use RAISEERROR, but ColdFusion does not bring the error message just ignore the error continue to run the other part of code. I just want to k
-
Cloud automation testing feasibility using Coded UI 2013.
Hi, I am unable to find any document which could explain whether automation testing for cloud application could be achieved using Coded UI 2013. In my project the plan is to move all applications to cloud network and as an automation tester I have au
-
FM Radio Presets Not saved if player is powered
I bought a new Zen Stone Plus GB and have found that the Preset FM Radio stations are deleted when the power is turned off. Please advise on the procedure to save the Preset Radio Stations permanently if possible.