Solved

[Lotusscript] Extracting same-name attachments

Posted on 2004-09-16
14
2,134 Views
Last Modified: 2013-12-18
I have an e-mail with 2 attachments, and both of the attachments are named File.TIF.  

When I do the following...
Forall eo In rtitem.EmbeddedObjects
  If (eo.Type = EMBED_ATTACHMENT) Then
     i = i + 1
     Call eo.ExtractFile(i & eo.Source)
  End If
End Forall
... I get 1File.TIF and 2File.TIF, but they are exactly the same, in other words, 1File.TIF is the first attachment and 2File.TIF is also the first attachment!

When I do the following...
v2FileNames = Evaluate("@AttachmentNames", doc)
For i = Lbound(v2FileNames) To Ubound(v2FileNames)
  Set attachedFile = doc.getAttachment(v2FileNames(i))
  Call attachedFile.extractFile(i &  v2FileNames(i))
Next  
... I get a 1File.TIF and an ATTCCDWY file, and they are the two attachments which is good.  But there is no file extension on the second file and I need to know what it is.

I'm not much of a Lotusscripter, never been trained in it, and don't have the resources or time to figure this out.  So 500 points to someone who can provide a routine which will extract and create 1File.TIF and 2File.TIF, or 1File.TIF and ATTCCDWY.TIF, or similar.  Bear in mind that e-mails I will be extracting from can have any number of attachments (that is, not limited to 2), any attachment names (that is, not necessarily File.TIF), any attachment extensions (that is, not always TIF), and any mixture of extensions (that is, TIF, XLS, DOC, PDF in the same email).
0
Comment
Question by:Xinger
  • 4
  • 3
  • 2
  • +3
14 Comments
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 12078396
Try renaming every attachment, using
    Name oldname As newname
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 12078416
So
    Forall eo In rtitem.EmbeddedObjects
      If (eo.Type = EMBED_ATTACHMENT) Then
         i = i + 1
         Call eo.ExtractFile(eo.Source)
         Name eo.source As ("1" & eo.source)
      End If
    End Forall
0
 
LVL 19

Expert Comment

by:RanjeetRain
ID: 12078759
This should do the trick for you.

Dim doc as NotesDocument

' Set the value of doc

Forall eo In doc.EmbeddedObjects
 If (eo.Type = EMBED_ATTACHMENT) Then
    i = i + 1
    Call eo.ExtractFile(i & eo.Source)
  End If
End Forall



I have just changed the rtitem to doc. It should work. If it doesn't (still gives last file name w/o extension) please verify that the sender/creator actually attached/created with those names. DO a sample test and please let us know.
0
 
LVL 14

Expert Comment

by:p_partha
ID: 12079040
When you attach the same filename twice, the second attachment will get a randomly generated internal filename (this is notes behaviour) but i have seen cases where you loose the file extension , and as far as i know i didn't find any way to programatically get at the original filename

Partha
0
 

Author Comment

by:Xinger
ID: 12079323
Sorry to be slow in responding; got other priorities hitting me right now.

sjef_bosman:  I have not tried this yet; have you tried this or is this just a suggestion?

RanjeetRain:  this looks exactly the same as the original code I posted except that I did not show you that I am setting the value of doc.  Is this the change you are suggesting?  I have not tried this yet; have you tried this or is this just a suggestion?

Partha:  I was hoping this isn't true.  I don't doubt you, but I'll wait for other comments to validate this.
0
 

Author Comment

by:Xinger
ID: 12079349
RanjeetRain, I apologize.  I just now saw your explanation at the end of your comment.  Thanks.
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 15

Expert Comment

by:Bozzie4
ID: 12081663
Partha is correct, when adding 2 files with the same name to 1 document, INTERNALLY, the filename changes.   But you can see this easily using @Attachmentnames, I think this gives you the name that Notes uses internally to refer to the document.

cheers,

Tom
0
 
LVL 46

Expert Comment

by:Sjef Bosman
ID: 12082883
Eh, it was only a suggestion. Just checked it, and it doesn't work. :(
0
 
LVL 15

Expert Comment

by:Bozzie4
ID: 12082968
If doc.HasEmbedded Then
            Forall i In doc.Items
                  If i.type = Attachment Then
                        Set nitem = doc.GetFirstItem(i.name)
                        Set o = doc.GetAttachment(i.values(0))
                        filename = "/tmp/"+o.source
                        Call o.extractfile(filename)
                        End If
            End Forall
            
      Else
            Error 12346, "no attachments"
      End If

Now to solve the naming issue, that's trickier.  You need to know which of the 2, the original name was.    If it's enough to see it it has an extension, you could do something like
if instr(i.values(0), ".") > 0 then
' yes
' store this name as name to use
else
' no
' rename this 1 when writing to disk
end if
0
 

Author Comment

by:Xinger
ID: 12129432
I found the solution on my own:

Forall eo In rtitem.EmbeddedObjects
      If (eo.Type = EMBED_ATTACHMENT) Then
            ' If Name and Source are different, Name is a random name assigned by Domino...
            If eo.Name <> eo.Source Then
                  ' take advantage of the random Name & add extension of the Source...
                  attname = eo.Name & "." & GetExtension(eo.Source)
            Else
                  ' No random name was assigned, so it is safe to use Source...
                  attname = eo.Source
            End If
            Call eo.ExtractFile(attname)
      End If
End Forall

0
 
LVL 19

Expert Comment

by:RanjeetRain
ID: 12147180
Good if this code has sorted out your problem. But Name property of NotesEmbeddedObject class is valid only for Embedded objects and not for file attachments. For file attachments this property always returns a blank string. So, my conclusion is this code might have worked for you in a test environment but it will not work if you have 3-4 attachments of same file name.
0
 

Author Comment

by:Xinger
ID: 12147551
Thanks for the heads up on this.  I see that it is documented this way, but I have not expereinced this.  I ran dozens of tests, and I made sure to include an e-mail with 4 pairs of same-named attachments.  The Name property has never been blank, and I have always seen a non-empty Name in the debugger in all situations.  But since you brought it to my attention, I will be wary, and also pursue a verification.  For now, I'm sticking with the code assuming it will work.  Thanks.
0
 

Accepted Solution

by:
ee_ai_construct earned 0 total points
ID: 12160283
Closed, 500 points refunded.
ee_ai_construct (replacement part #xm34)
Community Support Admin
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

For users on the Lotus Notes 8 Standard client, this article provides information on checking the Java Heap size and adjusting it to half of your system RAM in attempt to get the Lotus Notes 8.x Standard client to run faster.  I've had to exercise t…
Article by: Rob
Notes 8.5 Archiving Steps and Tips This article covers setting up a Notes archive, and helps understand some of the menu choices making setting up and maintaining a Notes archive file easier.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now