none
can't move a copy of an item due to permissions problem RRS feed

  • Question

  • I've got the following script running in an Outlook 2007/2010 custom form against Exchange Server 2007. But MOVE doesn't behave the way I want it to due to permissions (I think).

    I'm trying to email a copy of a Task item. Here's the code:

    Set myCopiedItem = Me.Copy
    Set myDrafts = myNameSpace.GetDefaultFolder(16) ' olFolderDrafts
    myCopiedItem.Move myDrafts
    Set myItem = myDrafts.Items.GetLast

    I wind up with a new MailItem (myItem) that I can work with, .Display for the user, then they can send it.

    But I wind up with a copy of myCopiedItem in the Public Folder that I started from. So it looks like .Move is leaving a copy of the item. If I run "myCopiedItem.Delete" then the copy of the original item deletes properly. But users don't have general permission to delete items from this Public Folder, so granting them that permission would be opening a can of worms that I would like to avoid if possible.

    Can anyone think of a programmatic way to email a Task Item from a Public Folder without leaving this copy of the item behind?

    Sunday, January 6, 2013 6:42 PM

Answers

  • Move is a function that returns the newly created item:

    Set myItem = myCopiedItem.Move(myDrafts)


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Monday, January 7, 2013 12:01 AM
  • I can only suggest using Redemption and its RDOMail.CopyTo method which allows to pass RDOFolder or RDOMail object as the target parameter and does not create an intermediary copy in the source foler.

    What happens if you call myCopiedItem.Save before callign myCopiedItem.Move?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Wednesday, January 9, 2013 3:12 PM

All replies

  • Move is a function that returns the newly created item:

    Set myItem = myCopiedItem.Move(myDrafts)


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Monday, January 7, 2013 12:01 AM
  • Your code is better, but it still doesn't solve the dilema.

    A couple of users have permission to delete items from the Public Folder, most of the users don't.

    For the users WITHOUT delete permission, making a copy of the item then trying to Move the copied item leaves the copy in the Public Folder (I assume because move is doing a copy followed by a delete and the delete fails). Doing a move on the original item works, but only because the original item cannot be deleted (due to permissions).

    For users WITH delete permission, making a copy then moving it works. But doing a move on the original item will not leave the original item in the Public Folder, which I need to do.

    I could code this with UserName and an IF statement, then perform different logic based on who the user is, but that's a maintenance nightmare to me. Better would be to see if the user has delete permission on the folder, then decide which part of the IF statement to execute. Maybe you know how to determine whether or not the current user has delete permissions on the item they have open.

    Or maybe there's a better way to go at this.

    Monday, January 7, 2013 2:14 PM
  • You can try to access the PR_ACCESS property (DASL name http://schemas.microsoft.com/mapi/proptag/0x0FF40003) using MailItem.PropertyAccessor, then check if the MAPI_ACCESS_DELETE bit (= 4) is set.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!


    Monday, January 7, 2013 2:20 PM
  • So am I correct reading that the values for MAPI_ACCESS_DELETE are additive? So if

    Debug.Print propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0FF40003")

    returns 3, the user has Write (1) + Read (2) permissions (which I what I get testing this on the users that don't have delete permission). If it returns 7 (which it does for me, and I have delete permissions), then it's Write (1) + Read (2) + Delete (4).

    Am I thinking about this properly? So my logic would be:

    IF value < 4 then try the move (which will fail) but there won't be a copy left in the original folder

    ELSEIF value >= 4 then make a copy, then move the copy (which will succeed).


    Tuesday, January 8, 2013 2:15 PM
  • No, you must check for that particular bit only using the bitwise & operator:

    if ((propValue & 4) != 0) 
    {
        //the user has delete permission
    }


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Tuesday, January 8, 2013 2:19 PM
  • I think this is what you meant, translated into VB Script. But I thought I'd give to a chance to check it or offer any suggestions:

    intX = propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0FF40003") And 4
    If intX = 0 Then
        Debug.Print "User does not have delete permission"
    Else
        Debug.Print "User has delete permission"
    End If

    Thanks.

    Wednesday, January 9, 2013 2:52 PM
  • That looks right.

    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Wednesday, January 9, 2013 2:57 PM
  • The move behavior doesn't work as I was hoping. Maybe you can offer a suggestion about what's going on.

    The Public Folder has Task items. myTask is the item that's currently open. The code below does MOVE the item to the Drafts folder and the original item is no longer in the Public Folder (assuming the user as Delete permission on the folder).

    • Set myMailItem = myTask.Move(myDrafts)

    But I want to leave the original Task item in the Public Folder. So I tried the following:

    • Set myCopiedItem = myTask.Copy
    • Set myMailItem = myCopiedItem.Move(myDrafts)

    thinking the new copy of the item would be moved to the Drafts folder. But this code leaves the copy in the Public Folder. I've even tried adding

    • myCopiedItem.Delete

    after the move, but that doesn't delete the new copy of the item. So I wind up with two copies in the Public Folder and one copy in the Drafts folder.

    What I want is the original in the Public Folder and one copy in the Drafts folder. Any ideas how to do this?

    Wednesday, January 9, 2013 3:02 PM
  • I can only suggest using Redemption and its RDOMail.CopyTo method which allows to pass RDOFolder or RDOMail object as the target parameter and does not create an intermediary copy in the source foler.

    What happens if you call myCopiedItem.Save before callign myCopiedItem.Move?


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.4 is now available!

    Wednesday, January 9, 2013 3:12 PM
  • Adding myCopiedItem.Save didn't change anything.

    I'll give Redemption a try.

    Thanks.

    Wednesday, January 9, 2013 4:05 PM
  • Hi Gordon,

    Thanks for posting in the MSDN Forum.

    Would you please tell we whether Redemption solved your issue?

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, January 14, 2013 4:49 AM
    Moderator
  • It looks like Redemption will work, since it allows the destination folder to be part of the Copy command. But I have to get approval before deploying an add-on like this. It may be two weeks before I am able to try it.
    Monday, January 14, 2013 3:25 PM
  • Hi Gordon,

    I will close this thread, please feel free to unmark it if you find any un-except issue after your test.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Tuesday, January 15, 2013 4:33 AM
    Moderator