Solved

[Lotusscript] Extracting same-name attachments

Posted on 2004-09-16
14
2,147 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For Desktop Techs: How to retain a user's Notes configuration data when swapping out the end user's computer. (Assuming that you are not upgrading to a completely different version of Notes client) All you need to do is: 1) install Notes o…
You’ve got a lotus Domino web server, and you have been told that “leverage browser caching” is a must do. This means that we have to tell the browser everywhere in the web to use cache. In other words, we set (and send) an expiration date in the HT…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

920 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

17 Experts available now in Live!

Get 1:1 Help Now