tags:

views:

58

answers:

3

Hi,

I am extracting attachment from Inbox,Send,Drafts e.t.c. mails. And saving them in a folder.

Using below logic:

http://stackoverflow.com/questions/1361695/how-to-access-attachments-from-notes-mail

But problem i am facing here is. Attachment having same type and name but different content. In current situation it is replacing old file with new one.

How i can uniquely manage this attachment for different mails.

A: 

There is several ways:
1) Always generate a random filename, for every attachment ( Negative here is that you will use "more" storage space
2) Generate a hash like SH-256 of the content of the file, and give it a name after this ( Negative here is hashing can take a while, depending on file size)

Depending on what your doing, i would off course save the original filename somewhere so it can be found based on the filename in the email. Perhaps also if you choose the hashing method, you should store what emails that file is attached to.

EKS
A: 

A few other ideas:

  • You could add the Notes Document Unique ID to the file name. Then you'd also have a way to determine which Notes Document the file came from.

  • In the past, I just handled this the way I see most programs handle it. I appended _x to the file name where x is a number. So if there were three files with the same name, they'd show up in the folder as file.txt, file_1.txt, file_2.txt.

Ken Pespisa
A: 

You can use the File.Exists(path) to verify if the file exists before extracting and if it does then add something to the name to make it unique.

Carlos