[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

[Lotusscript] Extracting same-name attachments

Posted on 2004-09-16
14
Medium Priority
?
2,286 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
13 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
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

[Webinar] Kill tickets & tabs using PowerShell

Are you tired of cycling through the same browser tabs everyday to close the same repetitive tickets? In this webinar JumpCloud will show how you can leverage RESTful APIs to build your own PowerShell modules to kill tickets & tabs using the PowerShell command Invoke-RestMethod.

Question has a verified solution.

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

  In today’s Arena we can’t imagine our lives without Internet as we are highly used to of it. If we consider our life style just for only 2 min we found that face to face communication is swapped by e-communication.  Every Where from Works place to…
IBM Notes offer Encryption feature using which the user can secure its NSF emails or entire database easily. In this section we will discuss about the process to Encrypt Incoming and Outgoing Mails in depth.
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Suggested Courses

590 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