Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2262
  • Last Modified:

[Lotusscript] Extracting same-name attachments

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
Xinger
Asked:
Xinger
  • 4
  • 3
  • 2
  • +3
1 Solution
 
Sjef BosmanGroupware ConsultantCommented:
Try renaming every attachment, using
    Name oldname As newname
0
 
Sjef BosmanGroupware ConsultantCommented:
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
 
RanjeetRainCommented:
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
p_parthaCommented:
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
 
XingerAuthor Commented:
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
 
XingerAuthor Commented:
RanjeetRain, I apologize.  I just now saw your explanation at the end of your comment.  Thanks.
0
 
Bozzie4Commented:
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
 
Sjef BosmanGroupware ConsultantCommented:
Eh, it was only a suggestion. Just checked it, and it doesn't work. :(
0
 
Bozzie4Commented:
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
 
XingerAuthor Commented:
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
 
RanjeetRainCommented:
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
 
XingerAuthor Commented:
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
 
ee_ai_constructCommented:
Closed, 500 points refunded.
ee_ai_construct (replacement part #xm34)
Community Support Admin
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

  • 4
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now