|
the Codeplex link shows no releases to download.
|
|
|
|
|
You should download the source.
THe source contains a project called InterIMAP, add that to your project and make a reference.
|
|
|
|
|
Want to get Attachments of a message which is in Byte[]. I am using IMAP, can anyone help me in this regard ? I am pasting my code here :
'******************************************************************************************************
public IMAP_FetchItem[] FetchMessages(int startMsgNo, int endMsgNo, bool uidFetch, bool headersOnly, bool setSeenFlag)
{
//Authentication
if (!m_Connected)
{
throw new Exception("You must connect first !");
}
if (!m_Authenticated)
{
throw new Exception("You must authenticate first !");
}
if (m_SelectedFolder.Length == 0)
{
throw new Exception("You must select folder first !");
}
//Define Arraylist for the messages.
ArrayList fetchItems = new ArrayList();
string endMsg = endMsgNo.ToString();
if (endMsgNo < 1)
{
endMsg = "*";
}
string headers = "";
if (headersOnly)
{
headers = "HEADER";
}
string uidF = "";
if (uidFetch)
{
uidF = "UID ";
}
string seenFl = "";
if (!setSeenFlag)
{
seenFl = ".PEEK";
}
Core.SendLine(m_pSocket, "a1 " + uidF + "FETCH " + startMsgNo + ":" + endMsg + " (UID RFC822.SIZE FLAGS BODY" + seenFl + "[" + headers + "])");
// Must get lines with * and cmdTag + OK or cmdTag BAD/NO
string reply = Core.ReadLine(m_pSocket);
if (reply.StartsWith("*"))
{
// Read multiline response
while (reply.StartsWith("*"))
{
// Get rid of * 1 FETCH and parse params. Reply:* 1 FETCH (UID 12 BODY[] ...)
reply = reply.Substring(reply.IndexOf("FETCH (") + 7);
int uid = 0;
int size = 0;
byte[] data = null;
bool isNewMsg = true;
// Loop fetch result fields
for (int i = 0; i < 4; i++)
{
// UID field
if (reply.ToUpper().StartsWith("UID"))
{
reply = reply.Substring(3).Trim(); // Remove UID word from reply
if (reply.IndexOf(" ") > -1)
{
uid = Convert.ToInt32(reply.Substring(0, reply.IndexOf(" ")));
reply = reply.Substring(reply.IndexOf(" ")).Trim(); // Remove UID value from reply
}
else
{ // Last param, no ending ' '
uid = Convert.ToInt32(reply.Substring(0));
reply = "";
}
}
// RFC822.SIZE field
else if (reply.ToUpper().StartsWith("RFC822.SIZE"))
{
reply = reply.Substring(11).Trim(); // Remove RFC822.SIZE word from reply
if (reply.IndexOf(" ") > -1)
{
size = Convert.ToInt32(reply.Substring(0, reply.IndexOf(" ")));
reply = reply.Substring(reply.IndexOf(" ")).Trim(); // Remove RFC822.SIZE value from reply
}
else
{
// Last param, no ending ' '
size = Convert.ToInt32(reply.Substring(0));
reply = "";
}
}
// BODY.PEEK field
else if (reply.ToUpper().StartsWith("BODY"))
{
// Get data. Find {dataLen}
int dataLen = Convert.ToInt32(reply.Substring(reply.IndexOf("{") + 1, reply.IndexOf("}") - reply.IndexOf("{") - 1));
MemoryStream storeStrm = new MemoryStream(dataLen);
Core.ReadData(m_pSocket, dataLen, storeStrm, true, 30000);
data = storeStrm.ToArray();
// Read last fetch line, can be ')' or some params')'.
reply = Core.ReadLine(m_pSocket).Trim();
if (!reply.EndsWith(")"))
{
throw new Exception("UnExpected fetch end !");
}
else
{
reply = reply.Substring(0, reply.Length - 1).Trim(); // Remove ')' from reply
}
}
// FLAGS field
else if (reply.ToUpper().StartsWith("FLAGS"))
{
if (reply.ToUpper().IndexOf("\\SEEN") > -1)
{
isNewMsg = false;
}
reply = reply.Substring(reply.IndexOf(")") + 1).Trim(); // Remove FLAGS value from reply
}
}
fetchItems.Add(new IMAP_FetchItem(uid , size, data, headersOnly, isNewMsg));
reply = Core.ReadLine(m_pSocket);
}
}
reply = reply.Substring(reply.IndexOf(" ")).Trim(); // Remove Cmd tag
if (!reply.ToUpper().StartsWith("OK"))
{
throw new Exception("Server returned:" + reply);
}
IMAP_FetchItem[] retVal = new IMAP_FetchItem[fetchItems.Count];
fetchItems.CopyTo(retVal);
return retVal;
}
Irfan Shahid
|
|
|
|
|
If you want to use your own code to do this, you would need to figure out which BODY[x(.x.x)] part of the message contains the attachment. There are a few ways to do this.
Once you get the data as a string, and verified that the transfer encoding is base64 (which it usually, but not always, is), you would need to do something like:
string sData = "<the string="" of="" data="" for="" the="" file="">";
byte[] fileData = Convert.FromBase64String(sData);
Otherwise, if you don't want to use your own code, or want to see an example of how this is done, check out http://www.codeplex.com/InterIMAP
modified on Tuesday, May 20, 2008 1:13 PM
|
|
|
|
|
this should get the attachement this sorted out, it is a port of the VB function that is posted somewhere here
public void ParseAttachment(XmlNode docNode, string attachDir, string attachName)
{
if (((docNode.ParentNode.SelectSingleNode("content-size") != null)))
{
//Get attachment file size
int attSize;
int.TryParse(docNode.ParentNode.SelectSingleNode("content-size").InnerXml, out attSize);
//Get attachment file name
string fileName = attachName;
if ((docNode.ParentNode.SelectSingleNode("content-description") != null)) {
fileName = docNode.ParentNode.SelectSingleNode("content-description").InnerXml;
}
}
//Retrieve and convert encoded base64 to a binary array
string base64String = docNode.InnerXml;
byte[] binaryArray = Convert.FromBase64String(base64String.Substring(0, attSize));
//Temporarely save attachment to local C:\ Drive for testing purposes if binary exists...ONLY IN DEBUG MODE
if (binaryArray.Length > 0) {
string attDestinationPath = Path.Combine(attachDir, fileName);
if (File.Exists(attDestinationPath))
File.Delete(attDestinationPath);
FileStream fs = new FileStream(attDestinationPath, FileMode.CreateNew);
fs.Write(binaryArray, 0, binaryArray.Length);
fs.Close();
}
}
}
|
|
|
|
|
Thanks for your Replay but i want to get direct folder size without reading attachments and messages is there any way to do this get direct folder size if read attachments and body size it's taking a lot of time to read if more messages was there in folder please replay
|
|
|
|
|
Hello,
Does anybody knows the command which can get the email-body as plain-ascii text instead of with xml-tags?
I am using Body[1] and it shows the body-content in xml-format.
Thanks.
Sharda
|
|
|
|
|
IMAP command has nothing to do with xml tags. IMAPLibrary retrieves the body as either plain text or base64encoded (based on encoding) than adds into xml file. You can modify code not to write to xml file.
|
|
|
|
|
Please check out http://www.codeplex.com/InterIMAP for a new version of this library that contains many bug fixes and enhancements. Currently still in testing, with a 1.0 release coming soon.
New changeset will be uploaded within a day or two (as of 5/20) with the newest code.
modified on Tuesday, May 20, 2008 1:13 PM
|
|
|
|
|
I've tryed fetching a message body from gmail(with ssl) with the following piece of code:
<br />
....<br />
string body=string.Empty;<br />
imap.FetchPartBody(uid, "TEXT", ref body);<br />
.....<br />
but the application just hangs.
Can anybody suggest me something or post a working example ?
Thanks.
|
|
|
|
|
Please check out http://www.codeplex.com/InterIMAP for a new version of this library that contains many bug fixes and enhancements. Currently still in testing, with a 1.0 release coming soon.
New changeset will be uploaded within a day or two (as of 5/20) with the newest code.
modified on Tuesday, May 20, 2008 1:13 PM
|
|
|
|
|
Hey,
Has anyone been able to log on to gmail successfully with the new SSL code?
When I try to use the command:
IMAPConfig config = new IMAPConfig("imap.gmail.com", "USER", "PASS", true, true, "");
IMAPClient client = new IMAPClient(config);
client.Logoff();
I get the following exception:
IMAP003 LIST "" "*"
* LIST (\HasNoChildren) "/" "INBOX"
* LIST (\Noselect \HasChildren) "/" "[Gmail]"
* LIST (\HasNoChildren) "/" "[Gmail]/All Mail"
* LIST (\HasNoChildren) "/" "[Gmail]/Drafts"
* LIST (\HasNoChildren) "/" "[Gmail]/Sent Mail"
* LIST (\HasNoChildren) "/" "[Gmail]/Spam"
* LIST (\HasNoChildren) "/" "[Gmail]/Starred"
* LIST (\HasNoChildren) "/" "[Gmail]/Trash"
IMAP003 OK Success
IMAP004 EXAMINE INBOX
* FLAGS (\Answered \Flagged \Draft \Deleted \Seen)
* OK [PERMANENTFLAGS ()]
* OK [UIDVALIDITY 2]
* 904 EXISTS
* 0 RECENT
* OK [UNSEEN 178]
* OK [UIDNEXT 1905]
IMAP004 OK [READ-ONLY] INBOX selected. (Success)
IMAP005 UID SEARCH all
* SEARCH 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 542 543 645 646 648 674 963 964 967 968 969 970 971 972 973 974 975 976 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1118 1121 1122 1127 1128 1129 1130 1133 1164 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1181 1182 1184 1185 1186 1187 1189 1190 1191 1192 1193 1195 1196 1197 1198 1199 1200 1201 1442 1482 1487 1488 1489 1490 1491 1492 1493 1497 1498 1510 1511 1512 1513 1514 1515 1517 1518 1519 1520 1521 1522 1525 1526 1529 1530 1531 1532 1546 1552 1554 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1574 1575 1576 1577 1578 1579 1580 1582 1584 1585 1587 1588 1589 1591 1596 1598 1599 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1626 1630 1631 1632 1633 1634 1636 1637 1638 1639 1640 1641 1642 1651 1728 1729 1732 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1777 1780 1781 1790 1791 1792 1793 1794 1808 1809 1810 1834 1835 1836 1837 1838 1839 1840 1842 1847 1848 1849 1850 1851 1852 1853 1854 1868 1869 1871 1875 1877 1878 1886 1890 1892 1893 1895 1896 1897 1898 1899 1900 1901 1902
IMAP005 OK SEARCH completed (Success)
A first chance exception of type 'System.FormatException' occurred in mscorlib.dll
The thread 0xe4c has exited with code 0 (0x0).
IMAP006 EXAMINE [Gmail]
IMAP006 NO Unknown Mailbox: [Gmail] (now in authenticated state) (Failure)
A first chance exception of type 'InterIMAP.IMAPException' occurred in InterIMAP.dll
A first chance exception of type 'InterIMAP.IMAPException' occurred in InterIMAP.dll
Error:Error in the application.:
The thread 0x8ac has exited with code 0 (0x0).
|
|
|
|
|
it seems to be a bug... not parsing correctly the email addresses and names... i'll pretty up/optimize the code when i have the time.
Test environment:
- Microsoft Exchange Server 2003 IMAP4rev1 server version 6.5.7638.1.
THE FIX FOR NOW:
IMAP.cs:
private List<imapmailaddress> ParseAddresses(string s)
{
List<imapmailaddress> addresses = new List<imapmailaddress>();
bool hasDisplayName = false;
Console.WriteLine("FERNANDODEBUG: " + s);
if (s.Contains("\""))
hasDisplayName = true;
string[] adrlist = s.Replace("\"", string.Empty).Trim().Split(new char[] { '>' });
if (adrlist.Length > 1)
{
for (int i = 0; i < adrlist.Length; i++)
{
string name = String.Empty;
if (hasDisplayName)
{
int idx = adrlist[i].IndexOf("<");
name = adrlist[i].Trim();
if (name.Length > 0)
{
name = name.Substring(0, idx - 1);
//name = adrlist[i].Substring(0, idx - 1);
if (name.Length > 0)
adrlist[i] = adrlist[i].Replace(name, " ");
}
}
string temp = adrlist[i].Trim().Replace("<", "");
int idx2 = temp.IndexOf("UID");
if (idx2 > -1)
temp = temp.Remove(idx2);
string addr = temp;
IMAPMailAddress newAddress = new IMAPMailAddress();
newAddress.Address = addr;
newAddress.DisplayName = name;
addresses.Add(newAddress);
}
}
else
{
string name = String.Empty;
if (hasDisplayName)
{
int idx = s.IndexOf("<");
name = s.Substring(0, idx - 1);
s = s.Replace(name, "");
}
string temp = s.Trim().Replace("<", "").Replace(">", "");
int idx2 = temp.IndexOf("UID");
if (idx2 > -1)
temp = temp.Remove(idx2);
string addr = temp;
IMAPMailAddress newAddress = new IMAPMailAddress();
newAddress.Address = addr;
newAddress.DisplayName = name;
addresses.Add(newAddress);
}
return addresses;
}
It Is Not That I'm Different!
... I'm Only Making The Difference!
|
|
|
|
|
Please check out http://www.codeplex.com/InterIMAP for a new version of this library that contains many bug fixes and enhancements. Currently still in testing, with a 1.0 release coming soon.
New changeset will be uploaded within a day or two (as of 5/20) with the newest code.
modified on Tuesday, May 20, 2008 1:14 PM
|
|
|
|
|
gmail require SSL so instead of using Stream object you need to use SslStream.
on connect method line 439 use this:
m_oNetStrm = new SslStream(m_oImapServ.GetStream(), false);
((SslStream)m_oNetStrm).AuthenticateAsClient(sHost);
also dont forget to change the hostname :imap.gmail.com and port:993
|
|
|
|
|
hello,nice peace of work but i am facing a problem in notepad attachments.
i can open all attachement except notepad attachement,when i want to write the mail into xml i receive an invalid body structure error.
even in the Imap console application project when i fetch a message containing a notepad file i receive an error ,did any one find a way to solve it?
|
|
|
|
|
What is notepad attachment? text file or notepad.exe?
|
|
|
|
|
i mean by notepad attachmenet all the files .txt
and the attachments whose name is in arabic are making the same problem.
|
|
|
|
|
i solved the arabic problem ,the message is in windows 1256 encoding,i am trying to decode it but i still have the text file in notepad problem,no xml could be created ,i receive an error "failed body structure"
|
|
|
|
|
Dear Rohit
Hi, I’m facing the same problem as Joekey (.txt attachment).
If you or anyone can help me to fix the error I will be thankful.
Regards
Slymen
|
|
|
|
|
I found the problem. If you send email through outlook and if it has .txt attachment, it converts into winmail.dat file which contains the original text attachment + other headers. But if you send email through google, you should be able to download the .txt attachment.
Now converting txt attachment to winmail.dat is mictosfot's propertary format and not part of standard IMAP protocol.
Even when I tried to open the same email through netscape mail client, it only showed winmail.dat attachment. If you open winmail.dat in notepad, you will see the file name and body of the .txt file in it. Only way to get the .txt attachment is to download winmail.dat, decode it and parse to get the .txt attachment.
Here is link to parse winmail.dat: http://www.emailarchitect.net/eagetmail/sdk/html/object_tnef.htm
Google it for more information.
modified on Monday, April 21, 2008 7:29 PM
|
|
|
|
|
hey joshi thank's for the tip,but i think the problem is in the sbodystruct,it does not always takes the sline if it is multiline so i thinkthe code should b sbodystruct +=sline
|
|
|
|
|
hello joekey,
i am getting same problem ,i able to download txt file but after that it give message "invalid body structure"
using your given solution i tried but not get solution still having problem..
one more thing i have noticed that
--if my email contains more then one attachments and if i get first attachment as txt file and second in any format then it stops parse another attachments
---id it reverse like first file may b any format and then second is txt file then its parse after first file as well and after parsing txt file it give message "invalid body structure" and logout ....
please help me if any body know about this problem ..
and sorry for my english
i hope i will get reply soon ..
|
|
|
|
|
This is really a great library!
Is it possible to move a message in the Inbox into a subfolder? If so, how?
Thanks,
Todd
|
|
|
|
|
Right now the library doesn't have a built in function to do that, but to accomplish this using IMAP commands it looks something like this:
UID COPY messageUID "new folder"
UID STORE messageUID +FLAGS (\Deleted)
EXPUNGE
The first command copies the message in question to the new folder (note: the folder must already exist). The second marks the message as deleted, and the third deletes all the messages that have been marked with the \Deleted flag.
The copy command assigns a new UID to the copy of the message. In the server response from the copy command, the UID of the copy is returned.
In the new version of the library there will be direct support through the API to perform this function. Please see message below for the link to the new version.
|
|
|
|